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)
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
}