Execute PowerShell code remotely from my Workstation ISE without install module?

Welcome Forums General PowerShell Q&A Execute PowerShell code remotely from my Workstation ISE without install module?

This topic contains 6 replies, has 5 voices, and was last updated by

 
Participant
4 months, 1 week ago.

  • Author
    Posts
  • #122603

    Participant
    Points: 141
    Rank: Participant

    Hi All,

    I have one dedicated server called PRODAZAD-V which is running Azure Active Directory Synch to Office 365.

    Enter-PSSession -ComputerName PRODAZAD-V
    Install-Module ADSync
    Import-Module ADSync
    
    Start-ADSyncSyncCycle -PolicyType Delta

    How can I execute the PowerShell code above to force it to Synch from my PowerShell ISE on my laptop without installing the module & loading it every time?

    Thank you in advance.

  • #122709

    Participant
    Points: 1,607
    Helping Hand
    Rank: Community Hero

    I believe above code is not from a script and you have a Tab opened in ISE and the above code snippet in that session.

    You don't need to Install the module every time, if the target node is PowerShell v3 (hope you are not using the deprecated v2) then even the Import module part is also not required as there is a module autoload feature in PowerShell from v3 onwards.

    if you haven't heard about implicit remoting, please check it here, it will usefull for you.

  • #122711

    Participant
    Points: 141
    Rank: Participant

    I believe above code is not from a script and you have a Tab opened in ISE and the above code snippet in that session.

    You don't need to Install the module every time, if the target node is PowerShell v3 (hope you are not using the deprecated v2) then even the Import module part is also not required as there is a module autoload feature in PowerShell from v3 onwards.

    if you haven't heard about implicit remoting, please check it here, it will usefull for you.

    KV,

    My goal is to be able to double click the file as.Batch file or as.PS1 so I can update the Azure AD Synch quickly.

  • #122724

    Participant
    Points: 1,113
    Helping Hand
    Rank: Community Hero

    IT Engineer

    ;^}

    I see you posted to multiple Q&A site.

    Just in case others hit here first, see my response to this here:

    https://stackoverflow.com/questions/53198579/how-to-execute-powershell-code-remotely-from-my-workstation-ise-without-install

     

  • #122726

    Participant
    Points: 3
    Rank: Member

    Hi,
    you would need to utilize PowerShell remoting for this task. The below code snippet is what i had created for another script.

    
             Function Get-UPNAzureADSyncStatus {
                param(
                    [object]$SyncJobStatus
                )
                $Script:ADSyncStauts = $null
                if($SyncJobStatus -eq "Success"){
                    $SyncInProgress = $true
                    do{
                        $SyncInProgress = Invoke-Command -ComputerName $AzureADSyncServerFQDN -ScriptBlock {Get-ADSyncScheduler | select-object -ExpandProperty SyncCycleInProgress} -ErrorAction Stop
                        if($SyncInProgress -eq $true){
                            Start-Sleep -Seconds 10
                        }#end_SubIF 
                    }While($SyncInProgress -eq $true)
                    $Script:ADSyncStauts = "Complete"
                    return 
                }#END_IF
            }#END_ScriptFunction
    
            Function Start-UpnUpdateAzureADSync{
                param(
                [String]$ServerName
                )
                filter Out-Default { $_ | Out-Null }
                $JobStatus = "Success"
                $AzureADjobRunStatus = "Running"
                while($AzureADjobRunStatus -eq "Running"){
                    Get-UPNAzureADSyncStatus -SyncJobStatus $JobStatus
                    if($($Script:ADSyncStauts) -eq "Complete"){
                        $ADSyncStart = Invoke-Command -ComputerName $ServerName -ScriptBlock {Start-ADSyncSyncCycle -PolicyType Delta} -ErrorAction Stop
                        Return $ADSyncStart.Result
                    }#END_IF
                }#While
            }#END_ScriptFunction
    
    

    Regards

  • #122759
    Jon

    Participant
    Points: 77
    Rank: Member

    I have the following code in my powershell profile that handles this task

    
    function Start-DeltaSync
    
    {
    
    $session = New-PSSession -ComputerName PRODAZAD-V
    
    Invoke-Command -Session $session -ScriptBlock {Start-ADSyncSyncCycle Delta}
    
    Remove-PSSession $session
    
    }
    
     
    
    
  • #122952

    Participant
    Points: 141
    Rank: Participant

    @postanote, Cool, thanks man 🙂

    @Spietersz, how to execute that function in Visual Studio code?

    @Jon, thanks, man.

The topic ‘Execute PowerShell code remotely from my Workstation ISE without install module?’ is closed to new replies.

denizli escort samsun escort muğla escort ataşehir escort kuşadası escort