Help
Help

Reputation: 181

PowerShell 2 - How To Check Windows 2012 OS Volume Only

I am restricted to PowerShell 2.

I have crafted the command below which lists out all of the File Systems that are not NTFS and this works perfectly:

Get-WMIObject -Class Win32_Volume | Where-Object {$_.FileSystem -ne "NTFS"} | Select DriveLetter,Label,FileSystem

I need to run this against all of my Windows systems, however, I would only like to check my Windows 2012 (including R2) machines. For example, the command runs against all Windows machines, for machines that are OS 2012 (including R2), list out the command output above and for other OS types such us Win 7, 2016, etc. echo this "This is a Win 2012 Check Only".

Is the above possible with PowerShell?

EDIT:

I am almost there! I crafted the below:

$x = Get-WMIObject -Class Win32_OperatingSystem | Select Caption; if ($x -eq "Microsoft Windows Server 2012 Standard"){Get-WMIObject -Class Win32_Volume | Where-Object {$_.FileSystem -ne "NTFS"} | Select DriveLetter,Label,FileSystem}if ($x -eq "Microsoft Windows Server 2012 R2 Standard"){Get-WMIObject -Class Win32_Volume | Where-Object {$_.FileSystem -ne "NTFS"} | Select DriveLetter,Label,FileSystem}else {write-host("This applys to Windows 2012 Only")}

But even if I run it on a win 2012 machine, it echos the else statement, any ideas as to what may be wrong with the statement?

Upvotes: 0

Views: 316

Answers (1)

Ernest Correale
Ernest Correale

Reputation: 516

The select command is returning a header value in addition to the expected string. Add the -ExpandProperty parameter and you're all set.

$x = Get-WMIObject -Class Win32_OperatingSystem | Select -ExpandProperty Caption

Upvotes: 1

Related Questions