K Ahmed
K Ahmed

Reputation: 21

powershell - remote disk information unique description

Need some assistance with the below script created, i can create a HTML report of the disk space for all remote machines i specified; however how do i add a meaningful description for each host i.e the pic below.

enter image description here

Script below

$Machine = @("Fakehost1", "Fakehost2", "fakehost3")

Get-CimInstance Win32_LogicalDisk -ComputerName $Machine -Filter "DriveType = '3'" -ErrorAction SilentlyContinue | 
Select-Object PsComputerName, DeviceID, 
    @{N="Disk Size (GB) "; e={[math]::Round($($_.Size) / 1073741824,0)}}, 
    @{N="Free Space (GB)"; e={[math]::Round($($_.FreeSpace) / 1073741824,0)}}, 
    @{N="Free Space (%)"; e={[math]::Round($($_.FreeSpace) / $_.Size * 100,1)}} | 
Sort-Object -Property 'Free Space (%)' | 
ConvertTo-Html -Head $Head -Title "$Title" -PreContent "<p><font size=`"6`">$Title</font><p>Generated on $date</font></p>" > $HTML

Upvotes: 0

Views: 356

Answers (1)

Steven
Steven

Reputation: 7067

A quick fix is to Sruce up the PSComputerName object in the same Select-Object command. You're already doing a lot of calculated properties what's 1 more...

Get-CimInstance Win32_LogicalDisk -ComputerName $Machine -Filter "DriveType = '3'" -ErrorAction SilentlyContinue | 
Select-Object @{N = 'PSComputerName'; E = { $_.PSComputerName + " : Description" }}, 
    DeviceID, 
    @{N="Disk Size (GB) ";e={[math]::Round($($_.Size) / 1073741824,0)}}, 
    @{N="Free Space (GB)";e={[math]::Round($($_.FreeSpace) / 1073741824,0)}}, 
    @{N="Free Space (%)";e={[math]::Round($($_.FreeSpace) / $_.Size * 100,1)}} | 
Sort-Object -Property 'Free Space (%)' | 
ConvertTo-Html -Head $Head -Title "$Title" -PreContent "<p><font size=`"6`">$Title</font><p>Generated on $date</font></p>" > $HTML

This tested good in my environment, but you will have to decide how to or what the actual description should be... If you are in an AD environment maybe you can create a hash to hold the descriptions like:

$Descriptions = @{}
$Machine | 
Get-ADComputer -Properties Description |
ForEach-Object{ $Descriptions.Add( $_.Name, $_.Description ) }

Then change the PSComputerName expression like:

@{N = 'PSComputerName'; E = { $_.PSComputerName + $Descriptions[$_.PSComputerName] }}

This would reference the hash and return the value you got from the AD description attribute. Of course, that means the attribute has to be populated. But it's just 1 idea to demonstrate the point that the description must be mined from somewhere.

Update:

To answer your comment, You could manually specify the hash instead. use something like below, before the Get-CimInstance command. Make sure to remove the previous AD stuff...

$Descriptions = 
@{
    Fakehost1 = "SQL Server for some bug app..."
    Fakehost2 = "File Server 1"
    Fakehost3 = "Another file server"
}

Upvotes: 1

Related Questions