8 Minute Demo – OIS-SCVMM PowerShell Execution Options

Good Day Readers/Viewers!

Today we are showcasing some standard, but very powerful Opalis functionality. The video walks you through a couple options for executing PowerShell from within Opalis against System Center Virtual Machine Manager.

The two PowerShell Execution Options explored here are:

  1. Run .Net Script Object Execution
  2. Run Program Object Execution

The code variations/examples used within the videos are as follows:

Standard PowerShell for the “Run .Net Script” Object

add-pssnapin Microsoft.SystemCenter.VirtualMachineManager; $test = Get-VMMServer -ComputerName "VMMServer" | Select-Object -ExpandProperty FQDN; remove-pssnapin Microsoft.SystemCenter.VirtualMachineManager;

PSSession and ScriptBlock PowerShell for the “Run .Net Script” Object

$password = convertTo-secureString -string "PASSWORD" -asPlainText -force; $credential = new-object System.Management.automation.Pscredential ("DOMAIN\Username" , $password); $session = New-PSSession -computername "VMMServer" -credential $credential -port 5985 -Authentication Default;

$test = Invoke-Command -session $session -scriptblock {add-pssnapin Microsoft.SystemCenter.VirtualMachineManager; Get-VMMServer -ComputerName "cjdemo-vmm" | Select-Object -ExpandProperty FQDN;}

remove-pssession -session $session;

PSSession and ScriptBlock PowerShell for the .ps1 to be executed by the “Run Program” Object

$password = convertTo-secureString -string "PASSWORD" -asPlainText -force; $credential = new-object System.Management.automation.Pscredential ("DOMAIN\Username" , $password); $session = New-PSSession -computername "VMMServer" -credential $credential -port 5985 -Authentication Default;

$test = Invoke-Command -session $session -scriptblock {add-pssnapin Microsoft.SystemCenter.VirtualMachineManager; Get-VMMServer -ComputerName "cjdemo-vmm" | Select-Object -ExpandProperty FQDN;} $test | out-file C:\Temp\output.txt

remove-pssession -session $session;

Run Program Command Line Example (updated for newer versions of Orchestrator on x64 2008 machine)

cmd.exe /c | C:\Windows\system32\WindowsPowerShell\v1.0\powershell.exe -c .\YourPowerShellScript.ps1 -Parameter1 'foo' -Parameter2 'bar'

NOTE: In the video, the PowerShell scripts include clear text passwords, this is not a requirement and was just for demonstration purposes. For an implementation, it is recommended that the credentials be stored as a Secure String within an encrypted text file. Once this file is created, it can be accessed as necessary where credentials are required. There are many references available for this topic, this is just one.

enJOY!