djpatrick
Contributor
Contributor

Running PowerCLI scripts remote from the vCenter server using LocalSystem

Hi

I have an issue where I need to run remote PowerCLI command on a server remotely from the vCenter Server itself using an orchestration tool. The orchestrator currently runs under the LocalSystem context which is where I'm seeing the following behaviour. If I run the same script directly on the vCenter box using LocalSystem I'm fine - the only issue I have is when I run remote PowerCLI scripts with LocalSystem

*As a last resort - I could change the user the orchestrator runs with - but this is last resort and wouldn't know what else would break if I did this *

Also, any ideas where I go to debug this or where to look for hints at why the snapin appears not to load properly?

The kind of output I'm seeing is:

Add-PSSnapin : Could not find a part of the path 'C:\Windows\system32\config\sy

stemprofile\AppData\Local\Temp\g3i4hpmm.tmp'.

At C:\Windows\System32\WindowsPowerShell\v1.0\profile.ps1:1 char:13

+ Add-PSSnapin <<<< VMware.VimAutomation.Core -ea "SilentlyContinue"

    + CategoryInfo          : NotSpecified: (:) [Add-PSSnapin], DirectoryNotFo

   undException

    + FullyQualifiedErrorId : System.IO.DirectoryNotFoundException,Microsoft.P

   owerShell.Commands.AddPSSnapinCommand

The term 'Get-PowerCLIVersion' is not recognized as the name of a cmdlet, funct

ion, script file, or operable program. Check the spelling of the name, or if a

path was included, verify that the path is correct and try again.

At D:\CASSP\MoveVM.ps1:77 char:35

+     $version = Get-PowerCLIVersion <<<<

    + CategoryInfo          : ObjectNotFound: (Get-PowerCLIVersion:String) [],

    CommandNotFoundException

    + FullyQualifiedErrorId : CommandNotFoundException

The term 'Connect-VIServer' is not recognized as the name of a cmdlet, function

, script file, or operable program. Check the spelling of the name, or if a pat

h was included, verify that the path is correct and try again.

At D:\CASSP\MoveVM.ps1:231 char:21

+     Connect-VIServer <<<<  -Server $Vserver -User $Vuser -Password $Vpassword

-WarningAction SilentlyContinue >$null

    + CategoryInfo          : ObjectNotFound: (Connect-VIServer:String) [], Co

   mmandNotFoundException

    + FullyQualifiedErrorId : CommandNotFoundException

The term 'Move-VM' is not recognized as the name of a cmdlet, function, script

file, or operable program. Check the spelling of the name, or if a path was inc

luded, verify that the path is correct and try again.

At D:\CASSP\MoveVM.ps1:243 char:12

+     Move-VM <<<<  -VM $VMname -destination $ContentionPool -confirm:$false

    + CategoryInfo : ObjectNotFound: (Move-VM:String) [], CommandNotF

   oundException

    + FullyQualifiedErrorId : CommandNotFoundException

The term 'Disconnect-VIServer' is not recognized as the name of a cmdlet, funct

ion, script file, or operable program. Check the spelling of the name, or if a

path was included, verify that the path is correct and try again.

At D:\CASSP\MoveVM.ps1:246 char:24

+     Disconnect-VIServer <<<<  -Server $Vserver -confirm:$false

    + CategoryInfo          : ObjectNotFound: (Disconnect-VIServer:String) [],

    CommandNotFoundException

  + FullyQualifiedErrorId : CommandNotFoundException

0 Kudos
1 Reply
jdptechnc
Expert
Expert

I don't think you are going to be able to use the LocalSystem identity on one machine to run a script on another machine.  I'm not sure if that is the cause of the errors you are seeing, though.  Have you tried testing with a real user account that has rights to the vCenter server, to be sure that the script itself is OK to be run remotely?

Please consider marking as "helpful", if you find this post useful. Thanks!... IT Guy since 12/2000... Virtual since 10/2006... VCAP-DCA #2222
0 Kudos