When I first fired up Powershell I was searching for the SCVMM related cmdlets but couldn’t see them. I ran Get-Command to list all the cmdlets but I didn’t see any related to VMs. I saw a reference to a Get-VM command after doing some googling, but when I tried to run the command it failed with:
PS C:\> get-vm
'get-vm' is not recognized as a cmdlet, function, operable program, or script file.
At line:1 char:6
+ get-vm <<<<
This was becuase I had started powershell using the shortcut from the PowerShell 1.0 start menu folder and not the shortcut from the Microsoft System Center Virtual Machine Manager 2007 start menu folder.
If you take a look at the shortcut’s target, you can see that it is starting powershell with the -PSConsoleFile switch:
"C:\Program Files\Windows PowerShell\v1.0\powershell.exe" -PSConsoleFile "D:\Program Files\Microsoft Systems Center Virtual Machine Manager 2007\bin\cli.psc1" -NoExit
So it appears that the SCVMM cmdlets are loaded from the cli.psc1 file that is included in the shortcut target, and that would explain why my first attempt at executing Get-VM didn’t work.
Once I started using the correct shortcut I started to explore all of the SCVMM related cmdlets. Get-Command is a good way to do this. You can also use Get-Command *vm to list all of the commands that end in “vm”. This however won’t list all of the commands related to SCVMM as not all of them are associated with VM functions. For example there are also cmdlets associated with Virtual Hard Disks.
I’ve listed all of the SCVMM cmdlets below. To generate this list I used Get-Command | CLIP which outputted all of the cmdlets to the clipboard. I then pasted the restults in notepad and removed all of the non-SCVMM commands by comparing them against the same results that I generated from the standard powershell console (by using the standard shortcut).
Add-VFD
Add-VirtualDisk
add-vmhost
add-vmhostnetworkadapter
Copy-HardDisk
discardsavedstate-vm
discover-vmhost
Get-DVDDrive
Get-FloppyDrive
Get-HardwareConfig
Get-ISO
Get-LibraryServer
Get-MachineConfig
Get-NetworkAdapter
Get-OperatingSystem
Get-OSConfig
Get-Script
Get-SelfServicePolicy
get-step
get-task
Get-Template
Get-VFD
Get-VirtualDisk
get-virtualnetwork
Get-VM
Get-vmcheckpoint
get-vmhost
Get-VMHostGroup
get-vmhostnetworkadapter
Get-VMHostRating
get-vmhostvolume
Move-VM
Move-VMHost
Move-VMHostGroup
New-DVDDrive
New-HardwareConfig
New-MachineConfig
New-NetworkAdapter
new-OSConfig
new-p2v
New-patchcache
New-SelfServicePolicy
New-Template
new-virtualnetwork
New-VM
New-vmcheckpoint
New-VMHostGroup
refresh-vm
refresh-vmhost
Remove-DVDDrive
Remove-HardwareConfig
Remove-ISO
Remove-NetworkAdapter
Remove-OSConfig
Remove-Script
Remove-SelfServicePolicy
Remove-Template
Remove-VFD
Remove-VirtualDisk
remove-virtualnetwork
Remove-VM
Remove-vmcheckpoint
remove-vmhost
Remove-VMHostGroup
remove-vmhostnetworkadapter
restart-task
restart-vm
Restore-vmcheckpoint
resume-vm
savestate-vm
Set-DVDDrive
Set-FloppyDrive
Set-HardwareConfig
Set-ISO
Set-NetworkAdapter
set-OSConfig
Set-Script
Set-SelfServicePolicy
set-server
Set-Template
Set-VFD
Set-VirtualDisk
set-virtualnetwork
Set-VM
set-vmhost
Set-VMHostGroup
shutdown-vm
start-vm
stop-task
stop-vm
Store-VM
suspend-vm
Normally, if you want to learn more about a command, you can use get-help and specify the command. However if I use Get-Help Get-VM I get an error:
PS C:\> get-help get-vm
Get-Help : Error loading help content for Get-VM from file "Monad.ImgLibCmdlet.
dll-Help.xml". Details: Monad.ImgLibCmdlet.dll-Help.xml.
At line:1 char:9
+ get-help <<<< get-vm
I beleive this is because the help file for the command hasn’t been written yet (it is only Beta1 after all!). This is consistent with the fact that the help file for the SCVMM console is mostly empty too. I discovered another way to find out more information about each command. Using Get-Command lists a ‘Definition’ column, but most of the text is truncated. However, if you use the Format-List option it will output all of the text:
PS C:\> get-command get-vm | format-list
Name : Get-VM
CommandType : Cmdlet
Definition : Get-VM -Server [-Verbose] [-Debug] [-Erro
rAction ] [-ErrorVariable ] [-OutV
ariable ] [-OutBuffer ]
Path :
AssemblyInfo :
DLL : D:\Program Files\Microsoft Systems Center Virtual Machine Ma
nager 2007\bin\Monad.ImgLibCmdlet.dll
HelpFile : Monad.ImgLibCmdlet.dll-Help.xml
ParameterSets : {__AllParameterSets}
ImplementingType : Microsoft.VirtualManager.Monad.Cmdlets.GetVMCmdlet
Verb : Get
Noun : VM
This helped me get a bit further with scripting SCVMM, becuase some of the cmdlets prompt for values unless you specify them. For example, if you use Get-VM it will prompt for a server value:
PS C:\> get-vm
cmdlet get-vm at command pipeline position 1
Supply values for the following parameters:
Server:
The server value required is the name of the SCVMM server. You can pipe the name by issuing the command with the -server option, e.g get-vm -server "labscvmm01". This will allow you to actually use the command in a script.
That’s all I’ll cover in this post, but I have more to add so watch this space!