Home > Mobile >  How to select objects based on their property which is not string type?
How to select objects based on their property which is not string type?

Time:01-14

For example,

PS C:\Users\lgd> Get-PSDrive

Name           Used (GB)     Free (GB) Provider      Root                                                                                                                                       CurrentLocation
----           ---------     --------- --------      ----                                                                                                                                       ---------------
Alias                                  Alias
C                  86.42         32.70 FileSystem    C:\                                                                                                                                              Users\lgd
Cert                                   Certificate   \
E                                      FileSystem    E:\
Env                                    Environment
F                  14.49         14.17 FileSystem    F:\
Function                               Function
HKCU                                   Registry      HKEY_CURRENT_USER
HKLM                                   Registry      HKEY_LOCAL_MACHINE
Temp               86.42         32.70 FileSystem    C:\Users\lgd\AppData\Local\Temp\
Variable                               Variable
WSMan                                  WSMan

and I would like to output the rows in which the Provider is FileSystem, but

Get-PSDrive | Where-Object Provider -eq "FileSystem"

doesn't work because the type of Provider property is not string.

So How to do to output my expected ?

CodePudding user response:

$_.Provider returns an instance of ProviderInfo class which has a Name property which you can use to get the name of the provider as a string.

Get-PSDrive | Where-Object { $_.Provider.Name -eq "FileSystem" }
  •  Tags:  
  • Related