Are there any scripts or reports that would give me information on VMware VM’s with snapshots?
was pretty sure this was a straight forward one, so I jumped on the test network.
Solution: Get Snapshot Information
Connect to your vCenter and use the following commands.
[box]
Connect-viserver vCenter-Name
THEN AUTHENTICATEGet-VM | Get-Snapshot | Select-Object VM, Name, SizeGB, Created
[/box]
That was easy!
Get Snapshot Information : With RV Tools
You can also get the same information from RVTools, which if you don’t already use, do so!
Solution: PowerShell Delete Snapshots
You can delete all snapshots by simply piping the command above to Remove-Snapshot, But you will porbably want to do that on a VM by VM basis. Use the cfollowing command.
[box]
Get-VM VM-Name| Get-Snapshot | Remove-Snapshot
[/box]
Related Articles, References, Credits, or External Links
I was doing some work recently and tried to connect to my vCenter server and was greeted with this.
PS C:\Users\administrator.PNL> connect-viserver vc-70.pnl.com connect-viserver : Object reference not set to an instance of an object. At line:1 char:1 + connect-viserver vc-70.pnl.com + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [Connect-VIServer], NullReferenceException + FullyQualifiedErrorId : System.NullReferenceException,VMware.VimAutomation.ViCore.Cmdlets.Commands.ConnectVIServer
Some internet searching led me to find out I simply needed to update PowerCLI – but when I did that this happened.
PS C:\Users\administrator.PNL> Update-Module VMware.PowerCLI PackageManagement\Install-Package : Authenticode issuer ‘CN=DigiCert Trusted Root G4, OU=www.digicert.com, O=DigiCert Inc, C=US’ of the new module ‘VMware.VimAutomation.Sdk’ with version ‘13.1.0.21605170’ is not matching with the authenticode issuer ‘CN=VeriSign Class 3 Public Primary Certification Authority – G5, OU=”(c) 2006 VeriSign, Inc. – For authorized use only”, OU=VeriSign Trust Network, O=”VeriSign, Inc.”, C=US’ of the previously-installed module ‘VMware.VimAutomation.Sdk’ with version ‘12.0.0.15939651’. If you still want to install or update, use -SkipPublisherCheck parameter. At C:\Program Files\WindowsPowerShell\Modules\PowerShellGet\1.0.0.1\PSModule.psm1:2089 char:20 + … $sid = PackageManagement\Install-Package @PSBoundParameters + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidOperation: (Microsoft.Power….InstallPackage:InstallPackage) [Install-Package], Exception + FullyQualifiedErrorId : AuthenticodeIssuerMismatch,Validate-ModuleAuthenticodeSignature,Microsoft.PowerShell.PackageManagement.Cmdlets.InstallPackage
Errm OK?
Solution: PowerCLI Errors
Seems like the fix for both errors is to simply update PowerCLI, updating actually does not work (as you can see). So, you need to FORCE an clean install of PowerCLI and also ignore the certificate error (above) with a SkipPublisherCheck switch.
This was asked on EE today, and it was an interesting one so I wrote it up. How to locate all the Snapshots in your VMware virtual infrastructure, and see how much space they are taking.
Solution
Use the following PowerCLI;
[box]
Get-Snapshot * | Select-Object -Property VM, Name, SizeGB, Children | Sort-Object -Property sizeGB -Descending | ft -AutoSize
[/box]
Related Articles, References, Credits, or External Links
A few weeks ago I needed to sort out some extended warranty for a customers servers. To do that I needed the serial numbers of those servers, (a mixture of IBM/Lenovo and Dell Servers).
As I didn’t fancy a drive to two different datacenters, I wanted to try and get them programatically.
Solution
After some searching I came across a post by one of my old EE buddies LucD with exactly what I needed. I’m assuming you have PowerCLI setup before beginning.
Connect to your Virtual infrastructure;
[box]
Connect-VIServer {vCenter-server-FQDN}
[/box]
Then, (assuming you have a folder called C:\Temp that you can write to).
When attempting to connect to a vCenter or ESXi host, you see the following error;
[box]
Connect-VIServer : {Date} {Time} Connect-VIServer Error: Invalid server certificate. Use Set-PowerCLIConfiguration
to set the value for the InvalidCertificateAction option to Prompt if you'd like to connect once or to add a
permanent exception for this server.
Additional Information: Could not establish trust relationship for the SSL/TLS secure channel with authority
'{Server-Name}'.
At line:1 char:1
+ Connect-VIServer
+ ~~~~~~~~~~~~~~~~
+ CategoryInfo : SecurityError: (:) [Connect-VIServer], ViSecurityNegotiationException
+ FullyQualifiedErrorId : Client20_ConnectivityServiceImpl_Reconnect_CertificateError,VMware.VimAutomation.ViCore.
Cmdlets.Commands.ConnectVIServer
Over the past few weeks I’ve been doing some work for a client that involves me adding some new ESX hosts. These will be setup the same as their existing ESX hosts. That’s fine, but they use standard vSwitches and have A LOT of port groups and VLANs.
I could sit and create them all manually, and tag them onto the the correct VLANs, but something that’s boring and repetitive is better solved with a bit of scripting!
Pre Requisites: You will need VMware PowerCLI installing (Install-Module -Name VMware.PowerCLI)
Solution
Connect to your vCenter
[box]
Connect-VIServer server-name.domain-name.com
[/box]
Note: If it complains about certificates (see below) issue this command ‘Set-PowerCLIConfiguration -InvalidCertificateAction Ignore -Confirm:$false‘ then try to connect again
Connect-VIServer Error: Invalid server certificate. Use Set-PowerCLIConfiguration to set the value for the InvalidCertificateAction option to Prompt if you’d like to connect once or to add a permanent exception for this server.
Note2: If migrating between hosts on different vCenters, then Connect-VIServer to BOTH vCenters before proceeding.
Once connected use the following two commands to specify your existing SOURCE ESX server name, and your new TARGET ESX server names, change yours accordingly.
Now, to copy and create all the port groups and VLANs use the following command. Note: Change the vSwitch numbers accordingly to match the source and destination vSwitch you are copying from and to.
You can observe them getting created in the vSphere web client like so;
Note: If you are migrating ‘vanilla’ Port Groups, you may see a couple of errors fly past if it tries to create ‘Management Network‘ and ‘VM Network‘ as these exist by default, so it can’t recreate them.
Related Articles, References, Credits, or External Links
It’s pretty easy to create an OVA/OVF from the vCenter Web console, but what about from Powershell / PowerCLI? Below I run though converting a 2008 x32 Windows server to OVA.
Solution
I’ll leave the web console in the background so you can see whats happening. From PowerCLI the first task is to connect to the vCenter.
If your VM has an ISO connected to it, it can have an annoying habit of adding that to the OVA file! So remove any presented .iso files with the following command;