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:
- Run .Net Script Object Execution
- 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
Anonymous
January 01, 2003
@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.Anonymous
January 01, 2003
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.Anonymous
January 01, 2003
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.Anonymous
January 01, 2003
Thanks CharlesAnonymous
January 01, 2003
The comment has been removed