VMware Cloud Community
Nighthawkz
Enthusiast
Enthusiast
Jump to solution

invoke-vmscript powershell formatting isn't being passed through correctly

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

Reply
0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

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

View solution in original post

Reply
0 Kudos
2 Replies
LucD
Leadership
Leadership
Jump to solution

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

Reply
0 Kudos
Nighthawkz
Enthusiast
Enthusiast
Jump to solution

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!

Reply
0 Kudos