【发布时间】:2010-10-11 13:06:12
【问题描述】:
提供你认为有用的一行 PowerShell 脚本,每个答案一个脚本。
有一个类似的question here,但这个只给出了带有脚本的页面的链接,让我们在这里一一回答,并提供最常用或最有用的脚本的贡献列表。
-
列出最新版本的文件
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) }
或ls | clip
使用管理单元
-
TFS 中两个变更集编号之间的文件
Get-TfsItemHistory <location> -Recurse -Version <label1>~<label2> | % { $(Get-TfsChangeset $_.ChangeSetID).Changes } | % { $_.Item.ServerItem } | Sort-Object -Unique -
在交换 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
【问题讨论】:
-
投票应该是社区 WIKI
-
而且通常不属于 SO。
-
@EBGreen:通常不,他们不会。不过,我认为这个相当不错(如果我们澄清一些措辞的话)。它可以作为一个很好的 PS 介绍。
-
呸。不是一个问题。像这样的东西应该继续wiki.poshcode.org或其他东西
-
仅仅因为你在一行上放了很多废话并不能真正使它成为单行。
标签: .net powershell scripting scripting-language