Skip to content

Instantly share code, notes, and snippets.

@PatrickTerlisten
Created May 8, 2016 16:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save PatrickTerlisten/8c34a7387633ecde141d828637e726c8 to your computer and use it in GitHub Desktop.
Save PatrickTerlisten/8c34a7387633ecde141d828637e726c8 to your computer and use it in GitHub Desktop.
PowerShell Snippets
###
# VMware PowerCLI
###
# Create a new entry in the credential store
New-VICredentialStoreItem -Host vcenter.domain.tld -User Username -Password Passw0rd
# Connect to vCenter server (credential store item exist for this vCenter server)
Connect-VIServer vcenter.domain.tld
# Connect to vCenter Server (without credential store item)
Connect-VIServer -Server vcenter.domain.tld -User Username -Password Passw0rd
# Change vNIC type to VMXNET3
Get-VM NAME | Get-NetworkAdapter | Set-NetworkAdapter -Type Vmxnet3
# Changing the multipathing policy for all hosts and datastores in a cluster
Get-Cluster PROD | Get-VMhost | Get-scsiLun -CanonicalName “naa.60030*”| Set-ScsiLun -MultipathPolicy "roundrobin"
# Get a list of all VMs in a cluster and the datastore in which the VMs resides
Get-Cluster | Get-VM | select name, @{N="Datastore";E={Get-Datastore -VM $_}} | sort name
# Get a list of all VMs, their mac-address and the connected port groups
Get-VM | Select Name, @{N="Network Adapter";E={$_.NetworkAdapters| foreach-object {$_.Type}}}, @{N="MacAddress";E={$_.NetworkAdapters| ForEach-Object {$_.MacAddress}}}, @{N="PortGroup";E={Get-VirtualPortGroup -VM $_}}
# vMotion of a VM between hosts without a shared storage (not really a One-liner...)
Move-VM -Destination esx-lab-01.testlab.site -Datastore local_ESX_LAB_01 -VM TSTCLN02
# Enable SSH on all hosts
Get-VMHost | Foreach {Start-VMHostService -HostService ($_ | Get-VMHostService | Where { $_.Key -eq "TSM-SSH"} )}
# Check on which hosts SSH is enabled
Get-VMHost | Get-VMHostService | Where { $_.Key -eq "TSM-SSH" } |select VMHost, Label, Running
# Get a list of hosts and the numer of VM that are running on these hosts
Get-VMHost | Sort-Object Name | Select Name,@{N="VM";E={ if ($_.ExtensionData.Vm -ne $null) { $_.ExtensionData.Vm.Count } else {0}}}
# Get a list of VMs and their UUIDs
Get-VM | select name, @{N="UUID"; E={(Get-View $_.Id).config.uuid}}
# Start, stop or suspend VMs with a specific pattern in the name
Get-VM vsa* | ForEach { Suspend-VM $_ -Confirm:$false}
Get-VM vsa* | ForEach { Start-VM $_ -Confirm:$false}
Get-VM vsa* | ForEach { Stop-VM $_ -Confirm:$false}
# Live migrate VMs without shared storage and with a specific pattern in the name
Get-VM vsa* | ForEach { Move-VM $_ -Destination esx4.lab.local -Datastore ESX4-LOCAL -Confirm:$false}
###
# DataCore SANsymphony-V Cmdlets
# The DataCore SANsymphony-V Cmdlets are part of the SANsymphony-V install package.
# You can get this package from the DataCore support portal.
# You can install the SANsymphony-V Cmdlets on your client. Simply start the installer and choose the
# "SANsymphony-V Cmdlets for Windows PowerShell".
###
# To load the Cmdlets
Import-Module "C:\Program Files\DataCore\SANsymphony\DataCore.Executive.Cmdlets.dll" -ErrorAction SilentlyContinue -WarningAction SilentlyContinue
# To connect to the server group
Connect-DcsServer -Server <Hostname or IP> -UserName Administrator -Password Passw0rd
###
# Microsoft PowerShell
###
# Move all cluster groups of a failover cluster to a another node
foreach ($group in Get-Clustergroup) {Move-Clustergroup $group}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment