SCVMM Powershell Scripts


I have been working on setting up a shared VMM configuration where I have multiple servers that are shared with multiple developers (they each have their own server but all ties into the same SCVMM.

I copied over VMs, ISO, and Templates to the individual servers but I wanted the resources on each server to be defined as belonging to the developer using it.

But when you copy them they all show as unknown…… now I am lazy and don’t want to go to the properties of each object and set the owner, and powershell being the wonderful thing it is made this easy so here is my “owner script”

You can run as individual 1 liners or save all together as a single .ps1 file

 

*************************************************************

Get-vmmserver localhost

#Set all TEMPLATES on SERVER1 to USER_ONE

Get-Template | ? {$_.LibraryServer -EQ "SERVER1.LAB.LOCAL"} | Set-Template -Owner USER_ONE | FT name, owner

#Set all ISO on SERVER1 to USER_ONE

Get-iso | ? {$_.LibraryServer -EQ "SERVER1.LAB.LOCAL"} | Set-iso -Owner USER_ONE | FT name, owner

#Set VM on SERVER1 to USER_ONE

get-VM | ? {$_.LibraryServer -EQ "SERVER1.LAB.LOCAL"} | Set-VM -Owner USER_ONE | FT name, owner

get-VM | ? {$_.VMHOst -EQ "SERVER1.LAB.LOCAL"} | Set-VM -Owner USER_ONE | FT name, owner

#Set VHD on SERVER1 to USER_ONE

Get-VirtualHardDisk | ? {$_.LibraryServer -EQ "SERVER1.LAB.LOCAL"} | Set-VirtualHardDisk -Owner USER_ONE | FT name, owner

 

****************************************************************

Advertisements

Compress Every powered off VM’s VHDs


Well its not exchange related but I run all my labs in hyper-v and I recently wanted to compress all the dynamic disks in my hyper-v lab and me being lazy did not want to go to the options on EVERY VM to compress the drives, so I started my google search to find a Powershell script to do them all for me…… well I couldn’t find it so I made one of my own and figured I would share 🙂

FYI- you need SCVMM to run this

Get-VMMServer –ComputerName localhost -TCPPort  8100 (8100 is default)

get-vm | where {$_.status -eq “POwerOFf”} | Get-VirtualDiskDrive |where {$_.status -eq “POwerOFf”}| ForEach-Object {Compress-VirtualDiskDrive -RunAsynchronously -VirtualDiskDrive $_}

Note: this will compress everything that’s “shutdown” so make sure you have the Disk I/O to do this.