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

**URL:** <https://forums.powershell.org/t/execute-powershell-code-remotely-from-my-workstation-ise-without-install-module/11636>\
**Category:** PowerShell Help\
**Created:** [November 7, 2018, 4:38pm UTC](https://forums.powershell.org/t/execute-powershell-code-remotely-from-my-workstation-ise-without-install-module/11636 "2018-11-07T16:38:48Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![albertwt](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/albertwt/32/2550_2.png) [@albertwt](https://forums.powershell.org/u/albertwt)\
**Post date:** [November 7, 2018, 4:38pm UTC](https://forums.powershell.org/t/execute-powershell-code-remotely-from-my-workstation-ise-without-install-module/11636/1 "2018-11-07T16:38:48Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![kvprasoon](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/kvprasoon/32/4449_2.png) [@kvprasoon](https://forums.powershell.org/u/kvprasoon)\
**Post date:** [November 7, 2018, 11:59pm UTC](https://forums.powershell.org/t/execute-powershell-code-remotely-from-my-workstation-ise-without-install-module/11636/2 "2018-11-07T23:59:08Z")

</div>

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](https://blogs.technet.microsoft.com/heyscriptingguy/2013/09/08/remoting-the-implicit-way/), it will usefull for you.

---

<div class="post-metadata">

**Author:** ![albertwt](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/albertwt/32/2550_2.png) [@albertwt](https://forums.powershell.org/u/albertwt)\
**Post date:** [November 8, 2018, 12:03am UTC](https://forums.powershell.org/t/execute-powershell-code-remotely-from-my-workstation-ise-without-install-module/11636/3 "2018-11-08T00:03:48Z")

</div>

[quote quote=122709]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](https://blogs.technet.microsoft.com/heyscriptingguy/2013/09/08/remoting-the-implicit-way/), it will usefull for you.[/quote]

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.

---

<div class="post-metadata">

**Author:** ![postanote](https://avatars.discourse-cdn.com/v4/letter/p/ebca7d/32.png) [@postanote](https://forums.powershell.org/u/postanote)\
**Post date:** [November 8, 2018, 1:54am UTC](https://forums.powershell.org/t/execute-powershell-code-remotely-from-my-workstation-ise-without-install-module/11636/4 "2018-11-08T01:54:24Z")

</div>

[IT Engineer](https://powershell.org/profile/albertwt/)

;^}

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](https://stackoverflow.com/questions/53198579/how-to-execute-powershell-code-remotely-from-my-workstation-ise-without-install)

&nbsp;

---

<div class="post-metadata">

**Author:** ![shihanpietersz](https://avatars.discourse-cdn.com/v4/letter/s/edb3f5/32.png) [@shihanpietersz](https://forums.powershell.org/u/shihanpietersz)\
**Post date:** [November 8, 2018, 1:54am UTC](https://forums.powershell.org/t/execute-powershell-code-remotely-from-my-workstation-ise-without-install-module/11636/5 "2018-11-08T01:54:41Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![sanchez](https://avatars.discourse-cdn.com/v4/letter/s/35a633/32.png) [@sanchez](https://forums.powershell.org/u/sanchez)\
**Post date:** [November 8, 2018, 6:47am UTC](https://forums.powershell.org/t/execute-powershell-code-remotely-from-my-workstation-ise-without-install-module/11636/6 "2018-11-08T06:47:25Z")

</div>

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

[pre]

function Start-DeltaSync

{

$session = New-PSSession -ComputerName **PRODAZAD-V**

Invoke-Command -Session $session -ScriptBlock {Start-ADSyncSyncCycle Delta}

Remove-PSSession $session

}

&nbsp;

[/pre]

---

<div class="post-metadata">

**Author:** ![albertwt](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/albertwt/32/2550_2.png) [@albertwt](https://forums.powershell.org/u/albertwt)\
**Post date:** [November 8, 2018, 5:13pm UTC](https://forums.powershell.org/t/execute-powershell-code-remotely-from-my-workstation-ise-without-install-module/11636/7 "2018-11-08T17:13:50Z")

</div>

@postanote, Cool, thanks man 🙂

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

@Jon, thanks, man.

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 8:34pm UTC](https://forums.powershell.org/t/execute-powershell-code-remotely-from-my-workstation-ise-without-install-module/11636/8 "2024-05-16T20:34:08Z")

</div>

Closed on May 16, 2024, 8:34pm UTC


