开发者

Used to "grep", lost in Powershell

Suppose I want to test if there is a drive named 'Z'. First step is this;

Get-PSProvider |  Select-Object -Property Drives

This give me;

开发者_开发问答Drives:

...
{C, A, D, Z}
...

But how do I proceed to retrieve the drives and test for 'Z' ? I have tried a lot of no-working variants....

BR/ Christer


You can use the Test-Path cmdlet:

Test-Path Z:

Or the Get-PSDrive cmdlet:

Get-PSDrive Z -ErrorAction SilentlyContinue


Try using Where-Object to select just the info you need:

Get-PSDrive | Where-Object { ($_.Provider -match "FileSystem") -and ($_.Name -eq "Z") }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜