I have a script to run and obtain disk information. It runs on 2012 but fails on 2012R2. This is due to one comma " , " in the command. My goal is to run my disk.ps1 and have it remotely query the server for OS version and get the disk info. whether its 2012 or 2012R2.
Right now I have two different scripts one for 2012 and the other for R2. As I'm a beginner when it comes to PS, I'm not sure where to begin. <insert frowny face here>
Windows 2012
************
#DISK INFO
write-host `n "Disk Info $Server" -BackgroundColor Blue -ForegroundColor White
Get-WmiObject -ComputerName $Server -Class Win32_LogicalDisk |
Where-Object {$_.DriveType -ne 2} |
Sort-Object -Property Name |
Select-Object Name, VolumeName, FileSystem, Description, `
@{"Label"="DiskSize(GB)";"Expression"={"{0:N}" -f ($_.Size/1GB) -as [float]}}, `
@{"Label"="FreeSpace(GB)";"Expression"={"{0:N}" -f ($_.FreeSpace/1GB) -as [float]}}, ` | Format-Table –AutoSize
Windows 2012R2
**************
#DISK INFO
write-host `n " Disk Info $Server" -BackgroundColor Blue -ForegroundColor White
Get-WmiObject -ComputerName $Server -Class Win32_LogicalDisk |
Where-Object {$_.DriveType -ne 2} |
Sort-Object -Property Name |
Select-Object Name, VolumeName, FileSystem, Description, `
@{"Label"="DiskSize(GB)";"Expression"={"{0:N}" -f ($_.Size/1GB) -as [float]}}, `
@{"Label"="FreeSpace(GB)";"Expression"={"{0:N}" -f ($_.FreeSpace/1GB) -as [float]}} ` | Format-Table –AutoSize
Note: there is a " , " difference on the last line after the "float" parameter.
So I'm not sure if I can use a trap or the proper use of "IF" this "THEN" that etc..... again apologies for not knowing the correct PS verbage as this is all new to me. I've read on such things but have no idea where to go from here. Thoughts?
↧
2012 vs 2012R2 disk info
↧