Tag Archives: PowerCLI

Delete multiple NetApp HCI / Solidfire volume snapshots with PowerShell

If you ever need to delete multiple volume snapshots from a NetApp HCI / Solidfire storage array, you will quickly realize there isn’t an efficient way of doing this using the UI – unfortunately you can’t delete multiple snapshots at the same time and each delete request requires a confirmation. Plus if you have a lot of volume snapshots, you will need to search for the snapshot you want to delete every time.

Using PowerShell simplifies the whole process.

First generate a snapshot report using following script.

connect-sfcluster CLUSTER IP

Get-SFSnapshot | select Name, SnapshotID, CreateTime, ExpirationTime, VolumeID, VolumeName | Export-Csv c:\temp\all-snapshots.csv

Sort the resulting CSV file (all-snapshots.csv) by VolumeName then by CreateTime – and highlight the rows including snapshots you want to delete. Then remove all the other rows. Finally remove all columns except the SnapshotID column and save as a new CSV (snapshots-to-delete.csv).

Now run the following script pointing at the new CSV file to delete the snapshots in one go.

$oldsnaps = (Import-Csv 'c:\temp\snapshots-to-delete.csv').SnapshotID

foreach ($snap in $oldsnaps){

Remove-SFSnapshot -SnapshotID $snap -Confirm:$False


For more info on how to install the SolidFire PowerShell module and other programmatic approaches to managing NetApp HCI storage – visit my other blog post.

Enable Hot Add vCPU and Memory on VMs using PowerShell (V2)

This is a script which will allow you to enable the Hot Add vCPU and Memory feature on all or a sub set of your VMs.

IMPORTANT NOTE – the script will recursively power off each VM defined in CSV (unless Hot Add is already enabled), apply the config then power each VM back on. So make sure you run this script in an outage window.

When creating the CSV, make sure to include the header row – Name.

The script will also generate a log file.

Continue reading

Add multiple VMware datastores using PowerCLI

The other day I had to add 60+ new VMware datastores, rather than doing this manually using the vSphere web client wizard, I used a basic PowerCLI script (in a foreach loop) to create the datastores in one big bang!

Before carrying out these steps make sure new LUNs are presented to the ESXi host.  And make a note of the LUN id of first new LUN you created.  

NOTE – You can acquire the LUN id by analyzing “Runtime Name” of LUN.  Or alternatively the storage array may have this information also.  

Continue reading

Backup Citrix VD templates with OVF Tool utility & PowerCLI

This script will automate the process of backing up your Citrix VD templates. As a matter of fact, you can use it for backing up any VM in your vCenter server.

The script leverages the OVF Tool utility. This tool can be downloaded from myvmware.com and should be installed on the server you’re scheduling the script on. For more info: www.vmware.com/support/developer/ovf

The script will run the OVF Tool utility for each Template or VM defined in the CSV file. It will then zip the log files generated by the OVF Tool utility and email them to the email addresses defined in the variables section.

NOTE – Each time the script runs the OVF data is overwritten. Export job logs for previous runs are archived in the Log-Archive folder. The script also creates a console log file in the root of the export folder.

Continue reading

Change VDS Port Group Load Balancing Policy with PowerCLI

#Get current load balancing policy
$VDS = VDS name
$pg = Portgroup name
Get-VDswitch -Name $VDS | Get-VDPortgroup $pg | Get-VDUplinkTeamingPolicy

#Set new load balancing policy

#Set Route based on IP hash
Get-VDswitch -Name $VDS | Get-VDPortgroup $pg | Get-VDUplinkTeamingPolicy | Set-VDUplinkTeamingPolicy -LoadBalancingPolicy LoadBalanceIP

#Set Route based on source MAC hash
Get-VDswitch -Name $VDS | Get-VDPortgroup $pg | Get-VDUplinkTeamingPolicy | Set-VDUplinkTeamingPolicy -LoadBalancingPolicy LoadBalanceSrcMac

#Set Route based on originating virtual port
Get-VDswitch -Name $VDS | Get-VDPortgroup $pg | Get-VDUplinkTeamingPolicy | Set-VDUplinkTeamingPolicy -LoadBalancingPolicy LoadBalanceSrcId

#Set Use explicit failover order
Get-VDswitch -Name $VDS | Get-VDPortgroup $pg | Get-VDUplinkTeamingPolicy | Set-VDUplinkTeamingPolicy -LoadBalancingPolicy ExplicitFailover

#Set Route based on physcial NIC load
Get-VDswitch -Name $VDS | Get-VDPortgroup $pg | Get-VDUplinkTeamingPolicy | Set-VDUplinkTeamingPolicy -LoadBalancingPolicy LoadBalanceLoadBased

#Remove $pg to apply new load balancing policy to all portgroups on the same VDS
Get-VDswitch -Name $VDS | Get-VDPortgroup | Get-VDUplinkTeamingPolicy | Set-VDUplinkTeamingPolicy -LoadBalancingPolicy LoadBalanceIP

For other Set-VDUplinkTeamingPolicy cmdlet parameters refer to the following documentation: