Powershell Import-Modules for Orchestrator

This is just a quick post to use as a reference for when writing powershell scripts for orchestrator. I will update this post in the future with other useful Import-Module powershell snippets as I write them or run across them in my runbooks.

The snippets that don’t say Remote connection next to them you need to have the powershell Cmdlets installed locally on your Orchestrator Server.

Exchange – Remote Connection

$PassUnsecure = “<password>”

$Pass = ConvertTo-SecureString $PassUnsecure -AsPlainText -Force

$Cred = New-Object -TypeName system.management.automation.PSCredential (“<username>”, $Pass)

$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri http://< ServerName>/powershell/ -Credential $Cred -Authentication Kerberos -AllowRedirection

Import-PSSession $Session

Config Mgr

$sitecode = “<siteCode>:”

$installdrive = “C:”

IF(test-path ($installdrive + “Program Files (x86)Microsoft Configuration ManagerAdminConsolebin”)) {

Import-Module ($installdrive + “Program Files (x86)Microsoft Configuration ManagerAdminConsolebinConfigurationManager.psd1”)



{IF(test-path ($installdrive + “Program FilesMicrosoft Configuration ManagerAdminConsolebin”)){

Import-Module ($installdrive + “Program FilesMicrosoft Configuration ManagerAdminConsolebinConfigurationManager.psd1”)




Write-host -Message “ConfigMgr 2012 powershell module not found!” -severity 1 -component “Error”



Set-Location $sitecode


Import-Module OperationsManager

New-SCOMManagementGroupConnection -ComputerName <servername>

Lync – Remote Connection

#Service account

$RunAsAccount = “<username>”

$RunAsPass = “<password>”

$pass = $RunAsPass | ConvertTo-SecureString -AsPlainText -Force

$credentials = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $RunAsAccount, $pass

# connection URI needs to point to the Lync Server, This Creates a remote PS session to Lync and loads the cmdlets

$s = New-PSSession -ConnectionUri https:// <FDQN>/OcsPowershell -Credential $credentials

Import-PSSession $S

Leave a Reply

Your email address will not be published. Required fields are marked *