代码改变世界

PowerShell 之常用方法

2021-09-29 20:24  jetwill  阅读(191)  评论(0编辑  收藏  举报

随笔分类 - 常用

 

【PowerShell】文件的解压与压缩
摘要:1 New-Item -ItemType File 1.txt -Force #新建文本文件 2 Compress-Archive -Path '1.txt' -DestinationPath '1.zip' -Force #压缩为zip 3 Expand-Archive -Path '1.zip' -DestinationPath '新建文件夹' -Force #解压到新文件夹内 阅读全文

 

时间差函数列出两个时间内的所有日期
摘要:1 function DateDiff 2 { 3 param([Parameter(Mandatory=$true)][datetime]$starttime,[datetime]$endtime,[string]$formatdate='D') 4 [long]$firsttime+=[long]((date $starttime).ToOADate()) 5 [long]$las... 阅读全文

 

【PowerShell】ASCII与Char之间的转换
摘要:1 [char[]][int[]]$char=65..90 2 $char -join ',' 3 [int[]][char[]]$ascii=$char 4 $ascii -join ',' A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z 65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,... 阅读全文

 

【PowerShell】格式化输出字符串
摘要:1 '{0:d4}' -f 10 2 '数字的补零';{} 3 '{0:f4}' -f 10 4 '保留小数位数';{} 5 '{0:p2}' -f 0.4567 6 '转换为百分比';{} 7 '{0:x}' -f 255 8 '转换为十六进制';{} 9 '{0:X}' -f 255 10 '以大写字母方式转换为十六进制';{} 11 '{0:X8}' -f 255 12 ... 阅读全文

 

获取盘符
摘要:1 [System.IO.DriveInfo]::GetDrives()|Where-Object{$_.DriveType -eq 3}|ForEach-Object{$_.Name} C:\ D:\ E:\ F:\ 阅读全文

 

隐藏启动程序
摘要:1 function Run([string]$name,$var,[bool]$wait_exp){ 2 $startclass = Get-CimClass -ClassName Win32_ProcessStartup 3 $startinfo = New-CimInstance -CimClass $startclass -Property @{ShowWindow... 阅读全文

 

Powershell 【控制台常用方法】
摘要:1 function Pause(){ 2 [System.Console]::Write('按任意键继续...') 3 [void][System.Console]::ReadKey(1) 4 } 5 [System.Console]::Title='控制台常用方法' 6 0..15|ForEach-Object{ 7 [System.Console]::... 阅读全文

 

PowerShell 【按任意键继续】
摘要:1 function Pause(){ 2 [System.Console]::Write('按任意键继续...') 3 [void][System.Console]::ReadKey(1) 4 } 5 pause 阅读全文