Using SCVMM 2012 Cmdlets in PowerShell

SCVMM Cmdlets allow SCVMM admin/users to do everything they can do in SCVMM AdminConsole in windows PowerShell command line. In SCVMM 2008 R2, you can run following command in PowerShell to run SCVMM cmdlets.

Add-PSSnapin Microsoft.SystemCenter.VirtualMachineManager

But this does not work in SCVMM 2012 as SCVMM 2012 uses PowerShell module. For SCVMM 2012 now you need run following in PowerShell instead

Import-Module "C:\Program Files\Microsoft System Center 2012\Virtual Machine Manager\bin\psModules\virtualmachinemanager\virtualmachinemanager"

(This assumes that you have SCVMM 2012 installed on the default location C:\Program Files\Microsoft System Center 2012 )

The PowerShell cmdlets in SCVMM 2012 change a lot in SCVMM 2012, you can get a list of all SCVMM 2012 cmdlets by typing the following at the PowerShell command shell prompt

Get-Command -Module virtualmachinemanager -Type cmdlet

And you can run Get-Help on any of the cmdlets to get the syntax for that cmdlet.

Get-Help <cmdlet name> -detailed

Update: Microsoft has published the SCVMM 2012 cmdlets help to TechNet, check it out http://technet.microsoft.com/en-us/library/hh801697.aspx

How to run ps1 scripts

PowerShell scripts are text files with ".ps1" extensions that contain PowerShell commands. Starting with Windows Server 2008, PowerShell is built into the OS. For earlier OS versions, you will need to download PowerShell at Microsoft PowerShell Site and install it.

To run ps1 scripts, you first need to enable scripts by running:

Set-ExecutionPolicy RemoteSigned

Otherwise, you will get this error message:

File <script> cannot be loaded because the execution of scripts is disabled on this system. Please see "get-help about_signing" for more details.

The most common way to run PowerShell scripts is from Windows PowerShell command prompt. You must specify a path to the script to run it. If the script is in your current folder, then you can run it with:

.\script.ps1

If the script is in another folder, you need specify the full path:

c:\scripts\script.ps1

    Continue reading

    Install PowerShell From Command Line

    To install PowerShell on Windows Server 2008 R2 or Hyper-V Server 2008 R2, following features needs to be installed.

    1. NetFx2-ServerCore
    2. NetFx3-ServerCore
    3. MicrosoftWindowsPowerShell

    Because Powershell is built on DotNet framework, DotNet 2.0 and 3.5  has to be installed prior to PowerShell installation.

    To install PowerShell from command line, run following from elevated command prompt

    DISM.exe /online /enable-feature /featurename:NetFx2-ServerCore DISM.exe /online /enable-feature /featurename:NetFx3-ServerCore DISM.exe /online /enable-feature /featurename:MicrosoftWindowsPowerShell

    Or run following command if it’s an 64bit machine

    DISM.exe /online /enable-feature /featurename:NetFx2-ServerCore-WOW64 
    DISM.exe /online /enable-feature /featurename:NetFx3-ServerCore-WOW64 
    DISM.exe /online /enable-feature /featurename:MicrosoftWindowsPowerShell-WOW64 

    Disable standby/sleep

    powercfg.exe is a windows built in tool to config power management. powercfg.exe is a command line utility, it’s easy to integrate powercfg.exe into scripts.

    Turn hibernation off

    powercfg -hibernate OFF

    Set the power configuration to High Performance

    powercfg -setactive 8c5e7fda-e8bf-4a96-9a85-a6e23a8c635c

    Set the absentia power scheme (the scheme used when no one is logged in)

    powercfg.exe -setabsentia 8c5e7fda-e8bf-4a96-9a85-a6e23a8c635c