Get-VMSnapshot Doesn't work in Enter-PSsession script


hello,

i have encountered issue writing small script.

for reason works if run line line, if run whole script fails.

this error get:

get-vmsnapshot : term 'get-vmsnapshot' not recognized name of cmdlet, function, script file, or operable program. check spelling of name, or if path included, verify path correct , try again.
@ line:3 char:30
+ invoke-command -scriptblock {get-vmsnapshot –vmname "pc000006_uat" -name "pc0000 ...
+                              ~~~~~~~~~~~~~~
    + categoryinfo          : objectnotfound: (get-vmsnapshot:string) [], commandnotfoundexception
    + fullyqualifiederrorid : commandnotfoundexception

and script:

enter-pssession -computername "$machine_name"

invoke-command -scriptblock

{get-vmsnapshot –vmname "pc000006_uat" -name "pc000006_uat backup"  sort-object creationtime -descending |

select-object -first 1 |

restore-vmsnapshot -confirm:$false -erroraction stop }

exit-pssession

thank help



this:

enter-pssession -computername "$machine_name" get-vmsnapshot –vmname "pc000006_uat" -name "pc000006_uat backup" | 	sort-object creationtime -descending | 	select-object -first 1 | 	restore-vmsnapshot -confirm:$false exit-pssession

or this:

invoke-command -computername $machine_name -scriptblock { 		get-vmsnapshot –vmname pc000006_uat -name "pc000006_uat backup" | 		sort-object creationtime -descending | 		select-object -first 1 | 		restore-vmsnapshot -confirm:$false -erroraction stop 	}
cannot mix two.


\_(ツ)_/




Windows Server  >  Windows PowerShell



Comments

Popular posts from this blog

Motherboard replacement

Cannot create Full Text Search catalog after upgrading to V12 - Database is not fully started up or it is not in an ONLINE state

Remote Desktop App - Error 0x207 or 0x607