Blog D'Joy

This [we]blog will be used to share thoughts (mostly technical), examples, tutorials, etc. for Microsoft Tech (mostly System Center).

8 Minute Demo – OIS-SCVMM PowerShell Execution Options

8 Minute Demo – OIS-SCVMM PowerShell Execution Options

  • Comments 5
  • Likes

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!

Comments
  • Hi Charles nice tutorial, was trying to implement the same but could not do that as in my machine it gives an error that "Add-PSSnapin : The Windows PowerShell snap-in 'Microsoft.SystemCenter.VirtualMachineManager' is not installed on this machine." tried installing it but the same error. For your information I am using Orchestrator 2012 beta, SCVMM 2012 beta. Can you please guide me.

  • If you are using the "Run .Net Script" object, you will have to be sure you are using the ScriptBlock option above (second or third row in the above table). You will need to make sure you have the VMM PowerShell components install on the Runbook Server (and possibly the Designer) machine(s). Keep this in mind: PS for OIS and Orchestrator execute as 32-bit, this is the entire reason behind the "ScriptBlock" and "PSSession" mentioned above. If you would like, you could try the following: blogs.technet.com/.../ois-integration-pack-for-powershell-script-execution-1-00.aspx

  • Hi Charles, i was trying to implement this but i am getting an error -

    Cannot validate argument on parameter 'Session'. The argument is null or empty. Supply an argument that is not null or empty and then try the command again.

    Any idea why this is occuring.Please help.

  • @Anjoli - In my experience, this means that the following command is not configured correctly:

    $session = New-PSSession -computername "VMMServer" -credential $credential -port 5985 -Authentication Default;

    Usually misconfiguration of the -computername parameter (make sure it is attempting connection to your server. The other place to check is the $credential where you define $password and username.

  • Thanks  Charles

Your comment has been posted.   Close
Thank you, your comment requires moderation so it may take a while to appear.   Close
Leave a Comment