VI Toolkit powershell simple script #3 – Find Snapshots

This really isn’t a script but more of a command but I think everyone gets the idea.

Find VM Snapshots for all servers in Virtual Infrastructure and display the VM Name, Snapshot Name, Date Created and power state. You can limit the VM’s this affects by using the location specific commands covered earlier.

Get-snapshot –vm (get-vm) | select vm, name, created, powerstate | export-csv [path_filename_csv]

Nothing to modify except the location and name of the csv file you would like to save the information to.  Go ahead and give it a try you’ll be amazed at what you will find.  I frequently hear “We don’t use snapshots” and then I run this little command and always find a few.  Needless to say this little guy becomes a power tool in the VMware admins arsenal of weapons.

VI Toolkit powershell simple script #2 – Create new NFS datastore

This simple little useful script can be used to add a new nfs datastore to all the hosts in an esx cluster.  Alternatively you can modify this and replace get-cluster CLUSTER_NAME with get-datacenter DATACENTER_NAME and add an ISO nfs share to your whole datacenter.

foreach ($ESXhost in get-cluster CLUSTER_NAME| get-vmhost)
                   {
                          New-datastore –nfs –vmhost $ESXhost –name [datastore_name] –path [/remote_path] –nfshost [nfs_server]
                   }

Simply replace CLUSTER_NAME with the name of the cluster you would like to run the script against, replace datastore_name with the name you want the datastore to have, replace remote_path with the nfs path on the nfs server, and nfs_server with the hostname or IP address of the nfs server you are connecting to.

Alternate method:

New-datastore –nfs –vmhost (get-cluster “cluster_name” | get-vmhost) –name [datastore_name] –path[/remote_path] –nfshost [nfs_server]

VI Toolkit powershell simple script #1 – Create new portgroup

This simple little usefull script can be used to create a portgroup at the cluster level.  This enables you to create it once and have it be consistently deployed to all the ESX and/or ESXi hosts in your cluster.

foreach ($ESXhost in get-cluster CLUSTER_NAME| get-vmhost)

                {

                                get-virtualswitch -vmhost $ESXhost -name VSWITCH| new-virtualportgroup -name PORTGROUP_NAME -vlanid VLANID

                }

 

Simply replace CLUSTER_NAME with the name of your cluster, VSWITCH with the name of the vSwitch you would like to create the portgroup on, PORTGROUP_NAME wiht the name of your new portgroup, and VLANID on the VLAN you would like to associate with the portgroup.  If you do not wish to use a VLAN remove the -vlanid VLANID portion of the script.