开发者

Used to "grep", lost in Powershell

开发者 https://www.devze.com 2023-04-04 00:28 出处:网络
Suppose I want to test if there is a drive named \'Z\'. First step is this; Get-PSProvider |Select-Object -Property Drives

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

精彩评论

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