If I run lines 1,2,3,4 the script fails on line 4 and says profile location not found.
If I run lines 1,2,3 wait until the PSSession is created then run line 4 everything works.
How do I initiate a wait until the PSSession is complete before proceeding to the next line in the script?
$ServerName = "***-*-*-*****"
Enter-PSSession $servername
$ProfileLocation = "d:\Profiles"
cd $ProfileLocation
Enter PSSession - then Errors
Forum rules
Do not post any licensing information in this forum.
Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
Do not post any licensing information in this forum.
Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
- Alexander Riedel
- Posts: 8488
- Last visit: Tue Apr 16, 2024 8:42 am
- Been upvoted: 37 times
Re: Enter PSSession - then Errors
[Topic moved by moderator]
Alexander Riedel
SAPIEN Technologies, Inc.
SAPIEN Technologies, Inc.
Re: Enter PSSession - then Errors
You can't use Enter-PsSession in a script. It is only allowed in an interactive session. Use the following to remote commands.
This will execute the commands in the scriptblocks on the remote server.
Read the documentation provided that discusses remoting and how it works.
help about_remote*
Code: Select all
$ServerName = "***-*-*-*****"
$sb = {
cd d:\Profiles
Write-Host $env:COMPUTERNAME $PWD
}
Invoke-Command -ScriptBlock $sb -ComputerName $servername
Read the documentation provided that discusses remoting and how it works.
help about_remote*