Hello,
I was testing a script I found in Manning publication “Learn Active Directory Management in a Month of Lunches” (Chapter 20. (20.7) Maintaining and monitoring Active Directory) re: getting C: drive size but the output re: PSComputername is wonky. The Calculated Properties don’t work. I’ve looked at both my book example and the Manning website (some slight differences in formatting the script) but not sure how to get good output for the given DCs in the domain.
$dom = [System.DirectoryServices.ActiveDirectory.Domain]::GetCurrentDomain()
foreach ($dc in $dom.DomainControllers) {
Get-WmiObject -Class Win32_Volume -ComputerName $dc -Filter "Name='C:\\'"
select Name,
@{N='Size(GB)'; E={[Math]::Round(($_.Capacity / 1GB),2)}},
@{N='Free(GB)'; E={[Math]::Round(($_.FreeSpace / 1GB),2)}},
@{N='PercFree'; E={[Math]::Round((($_.FreeSpace / $_.Capacity) * 100),2)}}
PSComputerName
}
Error is:
PSComputerName : The term 'PSComputerName' is not recognized as the name of a cmdlet
I’m supposed to see:
Name : C:\ Size(GB) : 180.46 Free(GB) : 18.03 PercFree : 9.99 PSComputerName : SERVER02