none
Script will not run, but if you run each line separately it does. RRS feed

  • Question

  • If I try to run this all at one time it does not work.  If I open it up and run each line one by one it works?  I am not sure why this will not work, running it in a PS1 file?

    Enter-PSSession -ComputerName <server names>
    Import-Module ADSync
    Start-ADSyncSyncCycle -PolicyType Delta

    Friday, May 24, 2019 12:51 PM

All replies

  • Enter-PSSession is designed to be used for INTERACTIVE sessions. If you want to send commands to a remote machine you should use Invoke-Command. Please read the complete help including the examples to learn how to use it.

    Regardless of that: Please format your code as code here in the forum using the code posting tool provided on the icon bar of the post editor (second to last icon). Thanks.

    Something like this could be a start for you:

    Invoke-Command -ComputerName "ComputerName" -ScriptBlock {
        Import-Module ADSync
        Start-ADSyncSyncCycle -PolicyType Delta
    }


    Live long and prosper!

    (79,108,97,102|%{[char]$_})-join''

    Friday, May 24, 2019 1:21 PM
  • Hi,

    what is the behaviour when you run all the lines at once? Do you get any error and if yes, what does it say?

    Did you try to import the module for the session:

    $ADSyncSession = Enter-PSSession -ComputerName <server names>
    Import-Module -Name ADSync -PSSession $ADSyncSesssion

    Regards,


    (Please take a moment to "Vote as Helpful" and/or "Mark as Answer" where applicable. This helps the community, keeps the forums tidy, and recognizes useful contributions. Thanks!) Blog: https://blog.pohn.ch/ Twitter: @StoyanChalakov



    Friday, May 24, 2019 1:24 PM
  • Hi,

    Was your issue resolved?

    If you resolved it using our solution, please "mark it as answer" to help other community members find the helpful reply quickly.

    If you resolve it using your own solution, please share your experience and solution here. It will be very beneficial for other community members who have similar questions.

    If no, please reply and tell us the current situation in order to provide further help.

    Best Regards,

    Lee


    Just do it.

    Monday, May 27, 2019 6:16 AM
    Moderator