You may have seen the great post by Microsoft’s Matt Shadbolt on how to create an add-on for the Powershell ISE that will import the ConfigMgr module for you. This is very useful if you are working on the Site Server itself, or have a fast remote connection to it, but in my environment, I work an a different geographical location to the Site Server. Using the ConfigMgr module installed on my local workstation is a bit slow, so I usually use an RDP session to the server itself.
Implicit remoting, where you import a remote module, doesn’t seem to work because you need the PSDrive for the remote session.
So why not just create an ISE add-on for a remote Powershell session? Then I can work on my local workstation, but run all the commands on the SCCM server itself with no latency penalty.
It’s easy enough to do: add the following code to your Powershell ISE profile script, located at $home\Documents\WindowsPowershell\Microsoft.PowerShellISE_profile.ps1. Add your SCCM Site Server to the $SiteServer variable.
$SiteServer = "MySCCMServer" $CurrentTab = $psISE.CurrentPowerShellTab if ("$SiteServer" -notin @($psISE.PowerShellTabs.DisplayName)) { $psISE.PowerShellTabs.Add().DisplayName = "$SiteServer" } $RemoteTab = $psISE.PowerShellTabs | ? DisplayName -eq $SiteServer while (-not $RemoteTab.CanInvoke) { Sleep 1 } $RemoteTab.Invoke({ Enter-PSSession -ComputerName $SiteServer }) while (-not $RemoteTab.CanInvoke) { Sleep 1 } $RemoteTab.Invoke({ import-module ($Env:SMS_ADMIN_UI_PATH.Substring(0, $Env:SMS_ADMIN_UI_PATH.Length - 5) + '\ConfigurationManager.psd1')}) while (-not $RemoteTab.CanInvoke) { Sleep 1 } $RemoteTab.Invoke({ $PSD = Get-PSDrive -PSProvider CMSite }) while (-not $RemoteTab.CanInvoke) { Sleep 1 } $RemoteTab.Invoke({ CD "($PSD)" }) while (-not $RemoteTab.CanInvoke) { Sleep 1 } $RemoteTab.Invoke({ cls })
Then simply run the add-on after opening your ISE to get a remote session tab to your SCCM server with the ConfigMgr module imported 🙂