Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Enter-PSSession Limitations?

I am having an issue with a PSSession and need some guidance on this. I have tried many ways of adjusting this PS Script and for some reason it will not work when written in the same script. My goal is to get AD Sync to work remotely.

What works:

1st Run this – Enter-PSSession -ComputerName (Server Name)

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

2nd Run this – Import-Module adsync
Start-ADSyncSyncCycle -PolicyType Delta
Exit-PSSession

What does not work:

All in one script –

Enter-PSSession -ComputerName (Server Name)
Import-Module adsync
Start-ADSyncSyncCycle -PolicyType Delta
Exit-PSSession

Am I missing something very obvious? When I do the two step, I see that the session changes from system32 to the remote one, however when I run it all in 1 step, I dont see it change to the remote one. 🙁

I tried time delays and Invoke-Commands a little bit

>Solution :

Enter-PSSession is exclusively for interactive use.

For scripts, you’ll want to use the Invoke-Command cmdlet:

Invoke-Command -ComputerName "Server Name" -ScriptBlock {
  Import-Module adsync
  Start-ADSyncSyncCycle -PolicyType Delta
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading