Hi Guys :smileyhappy:
Im having trouble with the following code, not because it doesnt work, but because regardless of whether different parts of the try statement are successful or not, I cannot get all the columns I want in one go.
So if for example $CurrentPageFile doesnt exist on one server, but when I then try a different WMI query, the table header doesnt display for the relevant select command to pull off the relevant details.
Its a bit annoying because I need all of it for each specific server. I would rather it produces all 5 colums initially, then populates the relevant ones with data if it has it available to display on screen.
if ($VM.Guest.Hostname -ne $VM.Name)
{
$username = Remote-AuthenticationCalculator -VM $VM -AdminAccount $AdminAccount
$cred = New-Object -TypeName System.Management.Automation.PSCredential -argumentlist $username, $password
try
{
$CurrentPageFile = Get-WmiObject -ComputerName $VM -Query "select * from Win32_PageFileSetting" -Credential $cred -ErrorAction Stop
$CurrentPageFile | Select __Server, Name, InitialSize, MaximumSize
if (!$CurrentPageFile)
{
$CurrentPageFile = Get-WmiObject -ComputerName $VM -Query "select * from Win32_PageFileUsage" -Credential $cred -ErrorAction Stop
$CurrentPageFile | select __Server, Name, AllocatedBaseSize
}
}
catch
{
$message1 = [String]::Format("`nVM: {0}{1}{0} could not be contact remotely using ""Get-WmiObject""`n`nSkipping pagefile interrogation...`n", $quote, $VM.Guest.Hostname)
Write-Host $message1 -BackgroundColor Black -ForegroundColor Red
}
}
Thanks everyone :smileyhappy: