Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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

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.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

So How to do to output my expected ?

>Solution :

$_.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" }
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading