Trying to get a script to run to export VM's for backup. Using lots of help from here and the database I have most, but not all, working, What does work:
This is run on the appropriate server. The script is named ExportVM.ps1 and this is the only line in the PS script: Export-VM -Name Gateway -Path Z:\
This completes exporting the VM:
cRun=FileGet(cScript)
ObjectClrOption("use", "System.Management.Automation,version=1.0.0.0,publicKeyToken=31bf3856ad364e35,culture=neutral")
objAutoPs = ObjectClrNew("System.Management.Automation.PowerShell")
oPshell = objAutoPs.Create()
oScope = ObjectType("BOOL",@TRUE)
oPshell.AddScript(cRun,oScope)
objAsync = oPshell.BeginInvoke()
oPShell.EndInvoke(objAsync)
oPshell.Dispose()
oPshell=0
The problem happens when changing the .ps1 script to be: Get-VM | Export-VM –Path N:\
If I save the PS1 file and then call it as above I get this error:
COM/CLR Exception: System.Management.Automation The string is missing the terminator: ".
If I run Get-VM | Export-VM –Path N:\ directly inside powershell it runs to completion.
What am I missing? Why will it complete if I do one machine, but fail on get-vm where there is more than one machine to get?