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") }
精彩评论