Execute commands remote with PSSession


hi,

i trying write script executed on server connects server b , executes commands remote powershell.

i trying simple commands since it's first time have tried remote powershell function. connect server working fine, if simple command like:
$foundfiles = get-childitem - path "c:\temp"

it returns error telling me cannot find path. if same , use "c:\windows" works.

if enter commands manually in console works expected.

?

lasse


/lasse

if this:

enter-pssession -name testconnection
$tmpfiles = get-childitem -path "c:\temp"

you running  remote system , c:\temp have on remote system.  either copy file there or use invoke.

spend time testing commands until sort out how remoting works.   when enter sessin prompt changes tell you running on remote system , references remote system.

this works same references local , execution remote:

$session=new-pssession  -computername servername
invoke-command -file c:\temp\script.ps1 -session $session -argumentlist '-param1 xxxx','-param2 vvvvv'

i can alter session:

ps c:\scripts> invoke-command -command {$newvar='hello remote'} -session $session
ps c:\scripts> invoke-command -command {$newvar} -session $session
hello remote

notice session retained. can load modules in 1 command or file , use them in another:

we can use -asjob long running scripts , invoke against list of computers.

it not telnet session full remote targetable session.


¯\_(ツ)_/¯




Windows Server  >  Windows PowerShell



Comments

Popular posts from this blog

WIMMount (HSM) causing cluster storage to go redirected (2012r2 DC)

Failed to delete the test record dcdiag-test-record in zone test.com

Azure MFA with Azure AD and RDS