I feel daft for asking this as i'm pretty sure it's not a powercli problem but a me problem - yet i cannot figure it.
I basically i'm trying to get the uptime of every o/s (using the exsi info sys.uptime.latest proved a little inaccurate for our estate unfortunatley) . so i'm trying to pass through the command
(Date)-([Management.ManagementDateTimeConverter]::ToDateTime((gwmi Win32_OperatingSystem).LastBootUpTime)) to the invoke-vmscript.
it keeps telling me the input string is in the incorrect format, yet if i run it locally on any VM, it runs fine. what on god's earth am i doing wrong to make powercli pass it through incorrectly.
This is how the command is stored before it's invoked:
$InvokeScriptParam =@{
ScriptText = "(Date)-([Management.ManagementDateTimeConverter]::ToDateTime((gwmi Win32_OperatingSystem).LastBootUpTime))"
VM = $VM.Name
GuestCredential = $VMCredential
ErrorAction = "stop"
ScriptType = 'Powershell'
}
on the flip side, when invoking the equivilent command on a linux machine via the above, formatting doesn't seem to be a problem and it reports back correctly.
cheers
Are you doing it like this?
Seems to work for me.
$vm = Get-VM MySrv
$InvokeScriptParam =@{
ScriptText = "(Date)-([Management.ManagementDateTimeConverter]::ToDateTime((gwmi Win32_OperatingSystem).LastBootUpTime))"
VM = $vm
GuestCredential = $VMCredential
ErrorAction = "stop"
ScriptType = 'Powershell'
}
Invoke-VMScript @InvokeScriptParam
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Are you doing it like this?
Seems to work for me.
$vm = Get-VM MySrv
$InvokeScriptParam =@{
ScriptText = "(Date)-([Management.ManagementDateTimeConverter]::ToDateTime((gwmi Win32_OperatingSystem).LastBootUpTime))"
VM = $vm
GuestCredential = $VMCredential
ErrorAction = "stop"
ScriptType = 'Powershell'
}
Invoke-VMScript @InvokeScriptParam
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
well.....shoot.
it was because of the way I was passing the vm name in. apparently just passing the name in wasn't good enough. Worked once I rejigged after your suggestion
thank you!