提供一行你认为有用的PowerShell脚本,每个回答一个脚本。
这里有一个类似的问题,但这个问题仅提供包含脚本的页面链接,让我们在这里逐个回答并列出最常用或最有用的脚本。
列出文件的最近版本
ls -r -fi *.lis | sort @{expression={$_.Name}}, @{expression={$_.LastWriteTime};Descending=$true} | select Directory, Name, lastwritetime | Group-Object Name | %{$_.Group | Select -first 1}
gps programThatIsAnnoyingMe | kill
使用其注册的程序打开文件(例如
start
,例如start foo.xls
)ii foo.xls
检索并显示系统特殊文件夹的路径
[enum]::getvalues([system.environment+specialfolder]) | foreach {"$_ maps to " + [system.Environment]::GetFolderPath($_)}
将环境值复制到剪贴板中(现在您知道如何使用剪贴板了!)
$env:appdata | % { [windows.forms.clipboard]::SetText($input) }
OR
ls | clip
使用SnapIns
TFS中两个变更集之间的文件
Get-TfsItemHistory <location> -Recurse -Version <label1>~<label2> | % { $(Get-TfsChangeset $_.ChangeSetID).Changes } | % { $_.Item.ServerItem } | Sort-Object -Unique
获取Exchange 200中所有Hub服务器上存在错误的队列消息
Get-ExchangeServer | ?{$_.IsHubTransportServer -eq $true} | Get-Queue | ?{$_.LastError -ne $null} | Sort-Object -Descending -Property MessageCount | ft -Property NextHopDomain,@{l="Count";e={$_.MessageCount}},@{l="Last Try";e={$_.LastRetryTime.tosting("M/dd hh:mm")}},@{l="Retry";e={$_.NextRetryTime.tostring("M/dd hh:mm")}},Status,LastError -AutoSize
这段代码是用于在 Exchange 服务器中获取正在运行的邮件队列信息。首先,使用 "Get-ExchangeServer" 命令获取所有 Exchange 服务器的列表,然后使用 "?{$_.IsHubTransportServer -eq $true}" 过滤出 Hub Transport 服务器。接下来,在获取到的邮件队列中再次使用 "?{$_.LastError -ne $null}" 来过滤掉没有错误的邮件队列。最后,按照邮件数量排序,输出 NextHopDomain、Count、Last Try、Retry、Status 和 LastError 等属性的值,并自动调整表格的宽度。