From 5ed2afd00d506617d757e83ceb7170eb53cd3a06 Mon Sep 17 00:00:00 2001 From: Gajendra D Ambi Date: Fri, 26 Aug 2016 07:37:47 +0530 Subject: [PATCH 1/8] vTool a menu based collection of vmware tasks vtool : manual time required : calculated against Many of these needs improvement, the script is written in what i call street smart way, not exactly the standard best practices but it will nonetheless work. May be others will see, use, update and improve it. Many functions like creating drs rules etc., are still at their infant stage and are not working. vTool>create cluster vTool>Add hosts 1+ hour per 60 blades vTool>Configure HA vTool>Configure DRS vTool>DRS Rules vTool>vApp vTool>Add Datastores 1+ hour per 60 datastores vTool>SNMP 2+ hour per 60 blades vtool>syslog ip 2+ hour per 60 blades vtool>dns 15 minutes per 60 blades vtool>ntp 10 minutes per 60 blades vtool>any advanced 15 minutes per 60 blades vtool>firewall 15 minutes per 60 blades vtool>scratch 20 minutes per 60 blades vtool>performance settings 5 minutes per 60 blades vtool>core dump 10 minutes per 60 blades vtool>power management 5 minutes per 60 blades vtool>esxi services 10 minutes per 60 blades vtool>vmkernel services 10 minutes per 60 blades vtool>hostfile entries 5 hours per 60 blades vtool>vSwitch 5 minutes per 60 blades vtool>vswitch ports 5 minutes per 60 blades vtool>update nic 10 minutes per 60 blades vtool>update mtu 10 minutes per 60 blades vtool>vm portgroup 15 minutes per 60 blades vtool>vmkernel portgroup 1 hour per 60 blades vtool>sync portgroup 5 minutes per 60 blades vtool>l3 vmotion 1 hour per 60 blades vtool>create vds per 60 blades vtool>dvportgroups 15 minutes per 60 portgroups --- Scripts/vTool_2016aug.ps1 | 4215 +++++++++++++++++++++++++++++++++++++ 1 file changed, 4215 insertions(+) create mode 100644 Scripts/vTool_2016aug.ps1 diff --git a/Scripts/vTool_2016aug.ps1 b/Scripts/vTool_2016aug.ps1 new file mode 100644 index 0000000..f831d7a --- /dev/null +++ b/Scripts/vTool_2016aug.ps1 @@ -0,0 +1,4215 @@ +<# +.SYNOPSIS + A handy multi purpose tool to get those things done quickly +.DESCRIPTION + This is an onging VMware tool to help those with an VMware environment to automate certain repetative tasks +.NOTES + File Name : vTool.ps1 + Author : gajendra d ambi + updated : August 2016 + Prerequisite : PowerShell v4+, powercli 6+ over win7 and upper. + Copyright - None +.LINK + Script posted over: github.com/gajuambi/vmware +#> + +##Start of the script## +Clear-Host #Clear the screen. + +#start of function +function PcliPshell +{ +<# +.SYNOPSIS + Integrate powercli into powershell +.DESCRIPTION + This will add pssnapins/modules of vmware powercli into powershell. You will get + powercli core, vds and vum scriptlets/snapsins/modules in powershell which will enable you + to create, run powercli scripts into powershell ISE since powercli itself lacks an IDE. +.NOTES + File Name : PcliPshell.ps1 + Author : gajendra d ambi + Date : March 2016 + Prerequisite : PowerShell v4+, powercli 6+ over win7 and upper. + Copyright - None +.LINK + Script posted over: github.com/MrAmbiG/vmware +#> +#Start of script# +Import-Module VMware.VimAutomation.Core -ErrorAction SilentlyContinue +Import-Module VMware.VimAutomation.Vds -ErrorAction SilentlyContinue +Import-Module VMware.VimAutomation.Cis.Core -ErrorAction SilentlyContinue +Import-Module VMware.VimAutomation.Storage -ErrorAction SilentlyContinue +Import-Module VMware.VimAutomation.vROps -ErrorAction SilentlyContinue +Import-Module VMware.VimAutomation.HA -ErrorAction SilentlyContinue +Import-Module VMware.VimAutomation.License -ErrorAction SilentlyContinue +Import-Module VMware.VimAutomation.Cloud -ErrorAction SilentlyContinue +Import-Module VMware.VimAutomation.PCloud -ErrorAction SilentlyContinue +Import-Module VMware.VumAutomation -ErrorAction SilentlyContinue +#End of Script# +}#End of function + +#------------------------------Start of Collection of Functions of automation------------------------------# + +#Start of function +function GetPlink +{ +<# +.SYNOPSIS + Gets the plink +.DESCRIPTION + This will make sure plink is either downloaded from the internet if it is not present and if it cannot download + then it will pause the script till you copy it manually. +.NOTES + File Name : GetPlink.ps1 + Author : gajendra d ambi + Date : Audust 2016 + Prerequisite : PowerShell v4+, powercli 6+ over win7 and upper. + Copyright - None +.LINK + Script posted over: + github.com/mrambig + [source] http://www.virtu-al.net/2013/01/07/ssh-powershell-tricks-with-plink-exe/ + +#> +$PlinkLocation = $PSScriptRoot + "\Plink.exe" +$presence = Test-Path $PlinkLocation +if (-not $presence) + { + Write-Host "Missing Plink.exe, trying to download...(10 seconds)" -BackgroundColor White -ForegroundColor Black + Invoke-RestMethod "http://the.earth.li/~sgtatham/putty/latest/x86/plink.exe" -TimeoutSec 10 -OutFile "plink.exe" + if (-not $presence) + { + do + { + Write-Host "Unable to download plink.exe, please download and add it to the same folder as this script" -BackgroundColor Yellow -ForegroundColor Black + Read-host "Hit Enter/Return once plink is present" + $presence = Test-Path $PlinkLocation + } while (-not $presence) + } + } + +if ($presence) { Write-Host "Detected Plink.exe" -BackgroundColor White -ForegroundColor Black } +} #End of function + +#start of function +function FaultToleranceOff +{ +<# +.SYNOPSIS + Enable vMotion +.DESCRIPTION + Enable vMotion across the Cluster +.NOTES + File Name : FaultToleranceOff.ps1 + Author : gajendra d ambi + Date : Feb 2016 + recommended : PowerShell v4+, powercli 6+ over win7 and upper. + Copyright - None +.LINK + Script posted over: github.com/gajuambi/vmware +#> +#start of script +$cluster = Read-Host "name of the cluster[type * to include all clusters]?" +$pg = Read-Host "name of the portgroup?" + +$stopWatch = [system.diagnostics.stopwatch]::startNew() +$stopWatch.Start() + +Get-Cluster $cluster | Get-VMHost | Get-VMHostNetworkAdapter | where PortGroupname -EQ $pg | Set-VMHostNetworkAdapter -FaultToleranceLoggingEnabled $false -Confirm:$false + +$stopWatch.Stop() +Write-Host "Elapsed Runtime:" $stopWatch.Elapsed.Hours "Hours" $stopWatch.Elapsed.Minutes "minutes and" $stopWatch.Elapsed.Seconds "seconds." -BackgroundColor White -ForegroundColor Black +#End of Script# +}#End of function + +#start of function +Function HostPerf +{ +<# +.SYNOPSIS + Set esxi host performance level +.DESCRIPTION + This will change the host's performance level to the following. +.NOTES + File Name : VssPmOn.ps1 + Author : gajendra d ambi + Date : August 2016 + Prerequisite : PowerShell v4+, powercli 6+ over win7 and upper. + Copyright - None +.LINK + Script posted over: github.com/gajuambi/vmware +#> +#Start of Script +$cluster = Read-Host "name of the cluster[type * to include all clusters]?" +Write-Host "choose a number from below +1. High performance +2. Balanced +3. LowPower +" -BackgroundColor White -ForegroundColor Black +$option = Read-Host "?" + +$stopWatch = [system.diagnostics.stopwatch]::startNew() +$stopWatch.Start() + +foreach ($vmhost in (get-cluster $cluster | get-vmhost | sort)) +{$vmhost.Name +(Get-View (Get-VMHost $vmhost | Get-View).ConfigManager.PowerSystem).ConfigurePowerPolicy($option) +} + +$stopWatch.Stop() +Write-Host "Elapsed Runtime:" $stopWatch.Elapsed.Hours "Hours" $stopWatch.Elapsed.Minutes "minutes and" $stopWatch.Elapsed.Seconds "seconds." -BackgroundColor White -ForegroundColor Black + #End of Script# +}#End of function + +#Start of function +function NicStatusPg +{ +<# +.SYNOPSIS + Change nic teaming of nics. +.DESCRIPTION + This will change the nic status on portgroups +.NOTES + File Name : NicStatusPg.ps1 + Author : gajendra d ambi + Date : July 2016 + Prerequisite : PowerShell v4+, powercli 6.3+ over win7 and upper. + Copyright - None +.LINK + Script posted over: github.com/MrAmbiG/vmware +#> +#Start of Script +$cluster = Read-Host "cluster[type * to include all clusters]?" +$pg = Read-Host "standard portgroup?" +$nic = Read-Host "vmnic (ex:vmnic5)?" + +Write-host " +1 . MakeNicActive +2 . MakeNicStandby +3 . MakeNicUnused +" -BackgroundColor white -ForegroundColor black +Write-Host choose from 1 to 3 from above -BackgroundColor Yellow -ForegroundColor Black +$option = Read-Host " " + +$stopWatch = [system.diagnostics.stopwatch]::startNew() +$stopWatch.Start() + +$vmhosts = get-cluster $cluster | get-vmhost | sort + +$vmhosts = get-cluster $cluster | get-vmhost | sort +foreach ($vmhost in $vmhosts) +{ +$vmnic = get-vmhost $vmhost | Get-VMHostNetworkAdapter -Physical -Name $nic + if ($option -eq 1) + {#MakeNicActive + get-vmhost $vmhost | get-virtualportgroup -Name $pg | Get-NicTeamingPolicy | Set-NicTeamingPolicy -MakeNicActive $vmnic -Confirm:$false + } + if ($option -eq 2) + {#MakeNicStandby + get-vmhost $vmhost | get-virtualportgroup -Name $pg | Get-NicTeamingPolicy | Set-NicTeamingPolicy -MakeNicStandby $vmnic -Confirm:$false + } + if ($option -eq 3) + {#MakeNicUnused + get-vmhost $vmhost | get-virtualportgroup -Name $pg | Get-NicTeamingPolicy | Set-NicTeamingPolicy -MakeNicUnused $vmnic -Confirm:$false + } +} +} #end of function + +#start of function +function NicStatusVss +{ +<# +.SYNOPSIS + Change nic teaming of nics. +.DESCRIPTION + This will change the nic status on vSwitchs +.NOTES + File Name : NicStatusVss.ps1 + Author : gajendra d ambi + Date : July 2016 + Prerequisite : PowerShell v4+, powercli 6.3+ over win7 and upper. + Copyright - None +.LINK + Script posted over: github.com/MrAmbiG/vmware +#> + +#Start of Script +$cluster = Read-Host "cluster[type * to include all clusters]?" +$vss = Read-Host "vSphere standard Switch?" +$nic = Read-Host "vmnic (ex:vmnic5)?" + +Write-host " +1 . Add Nic +2 . Remove Nic +3 . MakeNicActive +4 . MakeNicStandby +5 . MakeNicUnused +" -BackgroundColor white -ForegroundColor black +Write-Host choose from 1 to 5 from above -BackgroundColor Yellow -ForegroundColor Black +$option = Read-Host " " + + +$stopWatch = [system.diagnostics.stopwatch]::startNew() +$stopWatch.Start() + +$vmhosts = get-cluster $cluster | get-vmhost | sort +foreach ($vmhost in $vmhosts) +{ +$vmnic = get-vmhost $vmhost | Get-VMHostNetworkAdapter -Physical -Name $nic + if ($option -eq 1 ) + { + #add vmnic + get-vmhost $vmhost | get-virtualswitch -Name $vss | Add-VirtualSwitchPhysicalNetworkAdapter -VMHostPhysicalNic $vmnic -confirm:$false + get-vmhost $vmhost | get-virtualswitch -Name $vss | Get-NicTeamingPolicy + } + + if ($option -eq 2 ) + { + #remove vmnic + get-vmhost $vmhost | Get-VMHostNetworkAdapter -Physical -Name $nic | Remove-VirtualSwitchPhysicalNetworkAdapter -confirm:$false + get-vmhost $vmhost | get-virtualswitch -Name $vss | Get-NicTeamingPolicy + } + + if ($option -eq 3 ) + { + #Make active + Get-VMHost $vmhost | get-virtualswitch -Name $vss | Get-NicTeamingPolicy | Set-NicTeamingPolicy -MakeNicActive $vmnic -confirm:$false + } + + if ($option -eq 4 ) + { + #make standby + Get-VMHost $vmhost | get-virtualswitch -Name $vss | Get-NicTeamingPolicy | Set-NicTeamingPolicy -MakeNicStandby $vmnic -confirm:$false + } + + if ($option -eq 5 ) + { + #make unused + Get-VMHost $vmhost | get-virtualswitch -Name $vss | Get-NicTeamingPolicy | Set-NicTeamingPolicy -MakeNicUnused $vmnic -confirm:$false + } +} +$stopWatch.Stop() +Write-Host "Elapsed Runtime:" $stopWatch.Elapsed.Hours "Hours" $stopWatch.Elapsed.Minutes "minutes and" $stopWatch.Elapsed.Seconds "seconds." -BackgroundColor White -ForegroundColor Black + #End of Script# +}#End of function + +#start of function +Function WinSSH +{ +<# +.SYNOPSIS + Run SSH commands from windows +.DESCRIPTION + This will run commands to be run on VMware/vCenter hosts. + This needs plink to be in the same folder as this script. + This will open create a text file, you paste the commands which are to be run on the SSH target. +.NOTES + File Name : WinSSH.ps1 + Author : gajendra d ambi + Date : June 2016 + Prerequisite : PowerShell v4+, powercli 6+ over win7 and upper. + Copyright - None +.LINK + Script posted over: github.com/MrAmbiG/vmware + http://www.virtu-al.net/2013/01/07/ssh-powershell-tricks-with-plink-exe/ +#> +#Start of Script +GetPlink #custom function gets plink.exe #https://github.com/MrAmbiG/vmware/blob/master/vTool/vToolMenus/MainMenu/vCenterMenu/HostMenu/GetPlink.ps1 + +#server's credentials +$user = Read-Host "Host's username?" +$pass = Read-Host "Host's password?" +$cluster = Read-Host "name of the cluster[type * to include all clusters]?" +$VMHosts = get-cluster $cluster | Get-VMHost | sort + +#copy plink to c:\ for now +Copy-Item $PSScriptRoot\plink.exe C:\ + +$name = "commands" +$commands = "$PSScriptRoot\$name.txt" #create text file +ni -ItemType file $commands -Force +ac $commands "#Paste your each command in a new line which you want to run on each host" +Start-Process $commands + +Read-Host "Hit Return/Enter once you are done copying the commands to the pop up text" + +$stopWatch = [system.diagnostics.stopwatch]::startNew() #timer start +$stopWatch.Start() + +$lines = gc $commands + +Copy-Item $PSScriptRoot\plink.exe C:\ #copy plink to c:\ for now + +ForEach ($VMHost in $VMHosts) + { + Write-Host $vmhost.Name -ForegroundColor Black -BackgroundColor White + Get-VMHost $VMHost | Get-VMHostService | where {$_.Key -eq "TSM-SSH"} | Start-VMHostService -confirm:$false #start ssh + echo y | C:\plink.exe -ssh $user@$VMHost -pw $pass "exit" #store ssh keys + foreach ($line in $lines) + { + C:\plink.exe -ssh -v -noagent $VMHost -l $user -pw $pass "$line" + } + Get-VMHost $VMHost | Get-VMHostService | where {$_.Key -eq "TSM-SSH"} | Stop-VMHostService -confirm:$false #stop ssh + } + +$stopWatch.Stop() +Write-Host "Elapsed Runtime:" $stopWatch.Elapsed.Hours "Hours" $stopWatch.Elapsed.Minutes "minutes and" $stopWatch.Elapsed.Seconds "seconds." -BackgroundColor White -ForegroundColor Black + #End of Script# +}#End of function + +#start of function +Function DrsVmGroup +{ +<# +.SYNOPSIS + Create DrsVmGroup DRS Rule. +.DESCRIPTION + This uses custom functions to create DRS DrsVmGroup rules between VMs where VMs will be made to stay on the same host by the DRS. +.NOTES + File Name : DrsVmGroup.ps1 + Author : gajendra d ambi + Date : February 2016 + Prerequisite : PowerShell v4+, powercli 6+ over win7 and upper. + Copyright - None +.LINK + Script posted over: github.com/gajuambi/vmware +#> + +#Start of Script +$cluster = Read-Host "Name of the Cluster?" +$VMs = Read-Host "Type the Name of the VM/VMs (separated only by a comma and no spaces)" +$VMs = $VMs.split(',') +$vmgroup = Read-Host "Type the Name of the VM group" + +$stopWatch = [system.diagnostics.stopwatch]::startNew() +$stopWatch.Start() + +Get-VM $VMs | New-DrsVmGroup -Name $vmgroup -Cluster $cluster + +$stopWatch.Stop() +Write-Host "Elapsed Runtime:" $stopWatch.Elapsed.Hours "Hours" $stopWatch.Elapsed.Minutes "minutes and" $stopWatch.Elapsed.Seconds "seconds." -BackgroundColor White -ForegroundColor Black +#End of Script# +}#End of function + +#start of function +function shAddNic +{ +<# +.SYNOPSIS + Create New VMware Standard Switch on all hosts +.DESCRIPTION + This will need the 1st host's ip address and the number of subsequent hosts that you want to configure(which should be in series of the ip address). + Lets say you have 10 esxi hosts and the 1st host's ip is 1.1.1.1 then you have to provide the 1st host's ip address and the number of hosts + as an input to this script which will do +1 to the last octet of the 1st host's ip address and connect to all the 10 hosts and + Then it will add physical nics to the standard switch. +.NOTES + File Name : shAddNic.ps1 + Author : gajendra d ambi + Date : April 2016 + Prerequisite : PowerShell v4+, powercli 6+ over win7 and upper. + Copyright - None +.LINK + Script posted over: github.com/gajuambi/vmware +#> +#Start of script# +$vss = Read-Host "name of the vSphere standard Switch?" +$newnic = Read-Host "Name of the Nic (ex:vmnic5)?" + +$stopWatch = [system.diagnostics.stopwatch]::startNew() +$stopWatch.Start() + +foreach ($vmhost in (get-cluster $cluster | get-vmhost | sort)) { + $vmnic = get-vmhost $vmhost | Get-VMHostNetworkAdapter -Physical -Name $newnic + get-vmhost $vmhost | get-virtualswitch -Name $vss | Add-VirtualSwitchPhysicalNetworkAdapter -VMHostPhysicalNic $vmnic -confirm:$false + } + +$stopWatch.Stop() +Write-Host "Elapsed Runtime:" $stopWatch.Elapsed.Hours "Hours" $stopWatch.Elapsed.Minutes "minutes and" $stopWatch.Elapsed.Seconds "seconds." -BackgroundColor White -ForegroundColor Black +#End of Script# +}#End of function + +#start of function +function l3vmotion +{ +<# +.SYNOPSIS + Configure l3 vmotion. +.DESCRIPTION + It will + create the l3 vmotion portgroup + add vmk to the portgroup + assign vlan to the portgroup + add ip, subnet mask to the portgroup + enable netstack l3 vmotion for the portgroup + 1. update the default gateway manually for now +.NOTES + File Name : l3vmotion.ps1 + Author : gajendra d ambi + Date : June 2016 + Prerequisite : PowerShell v4+, powercli 6.3+ over win7 and upper. + Copyright - None +.LINK + Script posted over: github.com/MrAmbiG/vmware + https://communities.vmware.com/thread/519794?start=0&tstart=0 (inok) +#> +#Start of Script +Write-Host " +Don't forget to add gateway after it's completion +" -BackgroundColor White -ForegroundColor Black + +$cluster = Read-Host "Name of the cluster?" +$vss = Read-Host "Name of the vSwitch?" +$pg = Read-Host "name of the portgroup?" +$vlan = Read-Host "vlan?" +$ip = Read-Host "What is the 1st vmkernel ip address?" +$mask = Read-Host "subnet mask?" +$vmk = Read-Host "vmk number? ex: vmk7?" + +$stopWatch = [system.diagnostics.stopwatch]::startNew() +$stopWatch.Start() + +$a = $ip.Split('.')[0..2] +#first 3 octets of the ip address +$b = [string]::Join(".",$a) + +#last octet of the ip address +$c = $ip.Split('.')[3] +$c = [int]$c + +$vmhosts = get-cluster $cluster | get-vmhost | sort +foreach ($vmhost in $vmhosts) + { + Get-VMHost $vmhost | Get-VirtualSwitch -Name $vss | New-VirtualPortGroup $pg -VLanId $vlan -Confirm:$false #creating new VM portgroup + $esxcli = get-vmhost $vmhost | get-esxcli + $esxcli.network.ip.netstack.add($false, "vmotion") #enabling and adding vmotion tcp/ip stack (netstack) + $esxcli.network.ip.interface.add($null, $null, "$vmk", $null, "1500", "vmotion", "$pg") + $esxcli.network.ip.interface.ipv4.set("$vmk", "$b.$(($c++))", "$mask", $null, "static") #update ip informaiton to the vmk + } + +$stopWatch.Stop() +Write-Host "Elapsed Runtime:" $stopWatch.Elapsed.Hours "Hours" $stopWatch.Elapsed.Minutes "minutes and" $stopWatch.Elapsed.Seconds "seconds." -BackgroundColor White -ForegroundColor Black + #End of Script# +}#End of function + +##start of function +function shGetShHosts +{ +<# +.SYNOPSIS + Connect to standalone hosts +.DESCRIPTION + This will get the 1st host's ip address and increment it to a number specified by the user and connect to all of them. +.NOTES + File Name : shGetShHosts.ps1 + Author : gajendra d ambi + Date : April 2016 + Prerequisite : PowerShell v4+, powercli 6+ over win7 and upper. + Copyright - None +.LINK + Script posted over: github.com/gajuambi/vmware +#> +#Start of script# + +$1sthost = Read-Host "1st host's ip address?" +$max = Read-Host "total number of esxi hosts that you want to configure?" +$user = Read-Host "ESXi username?" +$pass = Read-Host "ESXi password?" + +$stopWatch = [system.diagnostics.stopwatch]::startNew() +$stopWatch.Start() + +#generate the range of ip addresses of hosts +$fixed = $1sthost.Split('.')[0..2] +$last = [int]($1sthost.Split('.')[3]) +$maxhosts = $max - 1 +$hosts = +$last..($last + $maxhosts) | %{ + [string]::Join('.',$fixed) + "." + $_ +} + +#connect to all hosts +connect-viserver $hosts -User $user -Password $pass + +$stopWatch.Stop() +Write-Host "Elapsed Runtime:" $stopWatch.Elapsed.Hours "Hours" $stopWatch.Elapsed.Minutes "minutes and" $stopWatch.Elapsed.Seconds "seconds." -BackgroundColor White -ForegroundColor Black +}#End of function + +#start of function +function shShootVmPg +{ +<# +.SYNOPSIS + Create New VMware Standard Switch on all hosts +.DESCRIPTION + This will need the 1st host's ip address and the number of subsequent hosts that you want to configure(which should be in series of the ip address). + Lets say you have 10 esxi hosts and the 1st host's ip is 1.1.1.1 then you have to provide the 1st host's ip address and the number of hosts + as an input to this script which will do +1 to the last octet of the 1st host's ip address and connect to all the 10 hosts and + Then it will Remove VM portgroup. +.NOTES + File Name : shShootVmPg.ps1 + Author : gajendra d ambi + Date : April 2016 + Prerequisite : PowerShell v4+, powercli 6+ over win7 and upper. + Copyright - None +.LINK + Script posted over: github.com/gajuambi/vmware +#> +#Start of script# +$pg = Read-Host "Name of the portgroup?" +$pg = Read-Host "Name of the portgroup?" + +$stopWatch = [system.diagnostics.stopwatch]::startNew() +$stopWatch.Start() + +Get-VMHost | Get-VirtualPortGroup -Name $pg | Remove-VirtualPortGroup -Confirm:$false + +$stopWatch.Stop() +Write-Host "Elapsed Runtime:" $stopWatch.Elapsed.Hours "Hours" $stopWatch.Elapsed.Minutes "minutes and" $stopWatch.Elapsed.Seconds "seconds." -BackgroundColor White -ForegroundColor Black + #End of Script# +}#End of function + +#start of function +function ShootVmkPg +{ +<# +.SYNOPSIS + Remove vmkernel portgroup +.DESCRIPTION + This will remove the virtual machine portgroup of all the hosts of a cluster/clusters. +.NOTES + File Name : ShootVmkPg.ps1 + Author : gajendra d ambi + Date : March 2016 + Prerequisite : PowerShell v4+, powercli 6+ over win7 and upper. + Copyright - None +.LINK + Script posted over: github.com/gajuambi/vmware +#> +#Start of Script +$cluster = Read-Host "name of the cluster[type * to include all clusters]?" +$pg = Read-Host "Name of the portgroup?" + +$stopWatch = [system.diagnostics.stopwatch]::startNew() +$stopWatch.Start() + + foreach ($vmhost in (get-cluster $cluster | get-vmhost | sort)) + { + $vmk = Get-VMHostNetworkAdapter -VMHost $vmhost | where PortgroupName -eq $pg + Write-Host "removing vmkernel from the $pg on $vmhost" + Remove-VMHostNetworkAdapter -Nic $vmk -confirm:$false + + Write-Host "removing $pg on $vmhost" + get-vmhost $vmhost | get-virtualportgroup -Name $pg | Remove-VirtualPortGroup -Confirm:$false + } + +$stopWatch.Stop() +Write-Host "Elapsed Runtime:" $stopWatch.Elapsed.Hours "Hours" $stopWatch.Elapsed.Minutes "minutes and" $stopWatch.Elapsed.Seconds "seconds." -BackgroundColor White -ForegroundColor Black + #End of Script# +}#End of function + +#start of function +function shRenamePg +{ +<# +.SYNOPSIS + Create New VMware Standard Switch on all hosts +.DESCRIPTION + This will need the 1st host's ip address and the number of subsequent hosts that you want to configure(which should be in series of the ip address). + Lets say you have 10 esxi hosts and the 1st host's ip is 1.1.1.1 then you have to provide the 1st host's ip address and the number of hosts + as an input to this script which will do +1 to the last octet of the 1st host's ip address and connect to them all the 10 hosts. + Then it will rename the esxi host's portgroup. +.NOTES + File Name : shRenamePg.ps1 + Author : gajendra d ambi + Date : April 2016 + Prerequisite : PowerShell v4+, powercli 6+ over win7 and upper. + Copyright - None +.LINK + Script posted over: github.com/gajuambi/vmware +#> +#Start of script# +$oldpg = Read-Host "Old Name of the portgroup?" +$newpg = Read-Host "New Name of the portgroup?" + +$stopWatch = [system.diagnostics.stopwatch]::startNew() +$stopWatch.Start() + +Get-VMHost | Get-VirtualPortGroup -Name $oldpg | Set-VirtualPortGroup -Name $newpg -Confirm:$false + +$stopWatch.Stop() +Write-Host "Elapsed Runtime:" $stopWatch.Elapsed.Hours "Hours" $stopWatch.Elapsed.Minutes "minutes and" $stopWatch.Elapsed.Seconds "seconds." -BackgroundColor White -ForegroundColor Black +#End of Script# +}#End of function + +#start of function +function shNewVss +{ +<# +.SYNOPSIS + Create New VMware Standard Switch on all hosts +.DESCRIPTION + This will need the 1st host's ip address and the number of subsequent hosts that you want to configure(which should be in series of the ip address). + Lets say you have 10 esxi hosts and the 1st host's ip is 1.1.1.1 then you have to provide the 1st host's ip address and the number of hosts + as an input to this script which will do +1 to the last octet of the 1st host's ip address and connect to all of the 10 hosts. + Then it will create a new vswitch based on your input. +.NOTES + File Name : shNewVss.ps1 + Author : gajendra d ambi + Date : April 2016 + Prerequisite : PowerShell v4+, powercli 6+ over win7 and upper. + Copyright - None +.LINK + Script posted over: github.com/gajuambi/vmware +#> +#Start of script# +$vss = Read-Host "name of the vSwitch?" + +$stopWatch = [system.diagnostics.stopwatch]::startNew() +$stopWatch.Start() + +get-vmhost | New-VirtualSwitch -Name $vss -Confirm:$false + +$stopWatch.Stop() +Write-Host "Elapsed Runtime:" $stopWatch.Elapsed.Hours "Hours" $stopWatch.Elapsed.Minutes "minutes and" $stopWatch.Elapsed.Seconds "seconds." -BackgroundColor White -ForegroundColor Black + #End of Script# +}#End of function + +##start of function +function shNewVMPg +{ +<# +.SYNOPSIS + Create New VMware Standard Swiportgroup on all hosts +.DESCRIPTION + This will need the 1st host's ip address and the number of subsequent hosts that you want to configure(which should be in series of the ip address). + Lets say you have 10 esxi hosts and the 1st host's ip is 1.1.1.1 then you have to provide the 1st host's ip address and the number of hosts + as an input to this script which will do +1 to the last octet of the 1st host's ip address and connect to all of the 10 hosts and + Then it will create a new virtual machine portgroup based on your input. +.NOTES + File Name : shNewVMPg.ps1 + Author : gajendra d ambi + Date : April 2016 + Prerequisite : PowerShell v4+, powercli 6+ over win7 and upper. + Copyright - None +.LINK + Script posted over: github.com/gajuambi/vmware +#> +#Start of script# +$vss = Read-Host "name of the vSwitch?" +$pg = Read-Host "name of the portgroup?" +$vlan = Read-Host "vlan?" + +$stopWatch = [system.diagnostics.stopwatch]::startNew() +$stopWatch.Start() + +get-vmhost | Get-VirtualSwitch -Name $vss | New-VirtualPortGroup -Name $pg -VLanId $vlan -Confirm:$false + +$stopWatch.Stop() +Write-Host "Elapsed Runtime:" $stopWatch.Elapsed.Hours "Hours" $stopWatch.Elapsed.Minutes "minutes and" $stopWatch.Elapsed.Seconds "seconds." -BackgroundColor White -ForegroundColor Black + #End of Script# +}#End of function + +#start of function +function shNewVMkernelPg +{ +<# +.SYNOPSIS + Create New VMware Standard Swiportgroup on all hosts +.DESCRIPTION + This will need the 1st host's ip address and the number of subsequent hosts that you want to configure(which should be in series of the ip address). + Lets say you have 10 esxi hosts and the 1st host's ip is 1.1.1.1 then you have to provide the 1st host's ip address and the number of hosts + as an input to this script which will do +1 to the last octet of the 1st host's ip address and connect to all of the 10 hosts and + Then it will create a new vmkernel portgroup based on your input. +.NOTES + File Name : shNewVMkernelPg.ps1 + Author : gajendra d ambi + Date : April 2016 + Prerequisite : PowerShell v4+, powercli 6+ over win7 and upper. + Copyright - None +.LINK + Script posted over: github.com/gajuambi/vmware +#> +#Start of script# +$vss = Read-Host "name of the vSwitch?" +$pg = Read-Host "name of the portgroup?" +$vlan = Read-Host "vlan?" + +$ip = Read-Host "What is the 1st vmkernel ip address?" +$mask = Read-Host "subnet mask?" +$vmk = Read-Host "vmk number? ex: vmk7?" + +$stopWatch = [system.diagnostics.stopwatch]::startNew() +$stopWatch.Start() + +get-vmhost | Get-VirtualSwitch -Name $vss | New-VirtualPortGroup -Name $pg -VLanId $vlan -Confirm:$false + +$a = $ip.Split('.')[0..2] +#first 3 octets of the ip address +$b = [string]::Join(".",$a) + +#last octet of the ip address +$c = $ip.Split('.')[3] +$c = [int]$c + + foreach ($vmhost in (get-vmhost | sort)){ + $esxcli = get-vmhost $vmhost | Get-EsxCli + $esxcli.network.ip.interface.add($null, $null, "$vmk", $null, "1500", $null, "$pg") #add vmkernel to the portgroup + $esxcli.network.ip.interface.ipv4.set("$vmk", "$b.$(($c++))", "$mask", $null, "static") #update ip informaiton to the vmkernel + +$stopWatch.Stop() +Write-Host "Elapsed Runtime:" $stopWatch.Elapsed.Hours "Hours" $stopWatch.Elapsed.Minutes "minutes and" $stopWatch.Elapsed.Seconds "seconds." -BackgroundColor White -ForegroundColor Black + }#End of Script# +}#End of function + +#start of function +function shShootVmkPg +{ +<# +.SYNOPSIS + Create New VMware Standard Switch on all hosts +.DESCRIPTION + This will need the 1st host's ip address and the number of subsequent hosts that you want to configure(which should be in series of the ip address). + Lets say you have 10 esxi hosts and the 1st host's ip is 1.1.1.1 then you have to provide the 1st host's ip address and the number of hosts + as an input to this script which will do +1 to the last octet of the 1st host's ip address and connect to all the 10 hosts and + Then it will Remove vmkernel portgroup. +.NOTES + File Name : ShootVmkPg.ps1 + Author : gajendra d ambi + Date : April 2016 + Prerequisite : PowerShell v4+, powercli 6+ over win7 and upper. + Copyright - None +.LINK + Script posted over: github.com/gajuambi/vmware +#> +#Start of script# +$pg = Read-Host "Name of the portgroup?" + foreach ($vmhost in (get-vmhost | sort)) + { + $vmk = Get-VMHostNetworkAdapter -VMHost $vmhost | where PortgroupName -eq $pg + Write-Host "removing vmkernel from the $pg on $vmhost" + Remove-VMHostNetworkAdapter -Nic $vmk -confirm:$false + + Write-Host "removing $pg on $vmhost" + get-vmhost $vmhost | get-virtualportgroup -Name $pg | Remove-VirtualPortGroup -Confirm:$false + }#End of Script# +}#End of function + +#start of function +function PgSync +{ +<# +.SYNOPSIS + Sync portgroups properties with vSwitch +.DESCRIPTION + This will make the portgroup to sync itself with the vswitch's settings. this will make the portgroup inherit the following from the vSwitch + LoadBalancingPolicy + NetworkFailoverDetectionPolicy + NotifySwitches + FailoverOrder +.NOTES + File Name : PowerMgmt.ps1 + Author : gajendra d ambi + Date : March 2016 + Prerequisite : PowerShell v4+, powercli 6+ over win7 and upper. + Copyright - None +.LINK + Script posted over: github.com/gajuambi/vmware +#> +#Start of script# +$cluster = Read-Host "name of the cluster[type * to include all clusters]?" +$pg = Read-Host "name of the portgroup?" + +$stopWatch = [system.diagnostics.stopwatch]::startNew() +$stopWatch.Start() + +get-cluster $cluster | Get-VMHost | sort | Get-virtualswitch -Standard | Get-VirtualPortGroup -Name $pg | get-nicteamingpolicy | Set-NicTeamingPolicy -InheritLoadBalancingPolicy $true -InheritNetworkFailoverDetectionPolicy $true -InheritNotifySwitches $true -InheritFailback $true -InheritFailoverOrder $true -Confirm:$false + +$stopWatch.Stop() +Write-Host "Elapsed Runtime:" $stopWatch.Elapsed.Hours "Hours" $stopWatch.Elapsed.Minutes "minutes and" $stopWatch.Elapsed.Seconds "seconds." -BackgroundColor White -ForegroundColor Black + #End of Script# +}#End of function + +#start of function +Function AddHosts +{ +<# +.SYNOPSIS + Add hosts to cluster. +.DESCRIPTION + This will add hosts to the specified clusters. The function will create a csv file which can be opened in excel. + populate the values under their respective headers in the excel. save it. close it. Hit return/enter to proceed. + Then the script will use the values from csv file and add hosts to the cluster(s). +.NOTES + File Name : AddHosts.ps1 + Author : gajendra d ambi + Date : March 2016 + Prerequisite : PowerShell v4+, powercli 6+ over win7 and upper. + Copyright - None +.LINK + Script posted over: github.com/gajuambi/vmware +#> + +#Start of Script + +Write-Host " +A CSV file will be opened (open in excel/spreadsheet) +populate the values, +save & close the file, +Hit Enter to proceed +" -ForegroundColor Blue -BackgroundColor White +$csv = "$PSScriptRoot/addhosts.csv" +get-process | Select-Object cluster,hostname,username,password | Export-Csv -Path $csv -Encoding ASCII -NoTypeInformation +Start-Process $csv +Read-Host "Hit Enter/Return to proceed" + +$stopWatch = [system.diagnostics.stopwatch]::startNew() +$stopWatch.Start() + +$csv = Import-Csv $csv + foreach ($line in $csv) + { + $cluster = $($line.cluster) + $vmhost = $($line.hostname) + $user = $($line.username) + $pass = $($line.password) + Add-VMHost $vmhost -Location (get-cluster -Name $cluster) -User $user -Password $pass -Force -Confirm:$false + } + +$stopWatch.Stop() +Write-Host "Elapsed Runtime:" $stopWatch.Elapsed.Hours "Hours" $stopWatch.Elapsed.Minutes "minutes and" $stopWatch.Elapsed.Seconds "seconds." -BackgroundColor White -ForegroundColor Black +#End of Script +} #End of function + +#start of function +Function ConfigHA +{ +<# +.SYNOPSIS + Configure HA on the cluster. +.DESCRIPTION + This will configure Ha on a specified cluster. It will + enable HA + disable admission control if the number of hosts is less than or equal to 3 + set the vm monitoring policy. +.NOTES + File Name : ConfigHA.ps1 + Author : gajendra d ambi + Date : March 2016 + Prerequisite : PowerShell v4+, powercli 6+ over win7 and upper. + Copyright - None +.LINK + Script posted over: github.com/gajuambi/vmware +#> + +#Start of Script + +$cluster = Read-Host "name of the cluster?" +$HARestartPriority = Read-Host " +choose one of the following as your VM (HA) Restart Priority +0. ClusterRestartPriority +1. Disabled +2. Low +3. Medium (Recommended) +4. High +" -ForegroundColor Blue -BackgroundColor White + +$stopWatch = [system.diagnostics.stopwatch]::startNew() +$stopWatch.Start() + +get-cluster $cluster | Set-Cluster -HAEnabled:$true + +if ($HARestartPriority -eq 0 ) { get-cluster $cluster | set-cluster -HARestartPriority ClusterRestartPriority -Confirm:$false } +if ($HARestartPriority -eq 1 ) { get-cluster $cluster | set-cluster -HARestartPriority Disabled -Confirm:$false } +if ($HARestartPriority -eq 2 ) { get-cluster $cluster | set-cluster -HARestartPriority Low -Confirm:$false } +if ($HARestartPriority -eq 3 ) { get-cluster $cluster | set-cluster -HARestartPriority Medium -Confirm:$false } +if ($HARestartPriority -eq 4 ) { get-cluster $cluster | set-cluster -HARestartPriority High -Confirm:$false } + +if ((Get-Cluster $cluster | Get-VMHost).count -lt 4) { Get-Cluster $cluster | Set-Cluster -HAAdmissionControlEnabled:$false } + +$stopWatch.Stop() +Write-Host "Elapsed Runtime:" $stopWatch.Elapsed.Hours "Hours" $stopWatch.Elapsed.Minutes "minutes and" $stopWatch.Elapsed.Seconds "seconds." -BackgroundColor White -ForegroundColor Black +#End of Script +}#End of function + +#start of function +Function CreateCluster +{ +<# +.SYNOPSIS + Create CreateCluster DRS Rule. +.DESCRIPTION + This uses custom functions to create DRS CreateCluster rules between VMs where VMs will be made to stay on the same host by the DRS. +.NOTES + File Name : CreateCluster.ps1 + Author : gajendra d ambi + Date : March 2016 + Prerequisite : PowerShell v4+, powercli 6+ over win7 and upper. + Copyright - None +.LINK + Script posted over: github.com/gajuambi/vmware +#> + +#Start of Script +$stopWatch = [system.diagnostics.stopwatch]::startNew() +$stopWatch.Start() + + $cluster = Read-Host "Name of the Cluster?" + if ((Get-datacenter).count -gt 1) { + $dc = Read-Host "name of the datacenter?" + get-datacenter -Name $dc | New-Cluster -Name $cluster -Confirm:$false + } + + if ((Get-datacenter).count -eq 1) { + get-datacenter | New-Cluster -Name $cluster -Confirm:$false + } + + if ((Get-datacenter).count -eq 0) { + Write-Host "Please create a datacenter first" -ForegroundColor DarkYellow -BackgroundColor White + } + +$stopWatch.Stop() +Write-Host "Elapsed Runtime:" $stopWatch.Elapsed.Hours "Hours" $stopWatch.Elapsed.Minutes "minutes and" $stopWatch.Elapsed.Seconds "seconds." -BackgroundColor White -ForegroundColor Black +#End of Script +} #End of function + +#start of function +Function CreateVapp +{ +<# +.SYNOPSIS + Create new vApp. +.DESCRIPTION + This will create vApp in a cluster. It is very easy and less time consuming to do manually but + the motto here is 'manual is an evil when you are automating' and most importantly in future this might have more options where + you can add VMs and control the startup/shutdown order of VMs. +.NOTES + File Name : CreateVapp.ps1 + Author : gajendra d ambi + Date : March 2016 + Prerequisite : PowerShell v4+, powercli 6+ over win7 and upper. + Copyright - None +.LINK + Script posted over: github.com/gajuambi/vmware +#> + +#Start of Script +$cluster = Read-Host "name of the cluster?" +$vapp = Read-Host "Name of the vApp?" + +$stopWatch = [system.diagnostics.stopwatch]::startNew() +$stopWatch.Start() + +New-VApp -Name $vapp -Location (get-cluster $cluster) -Confirm:$false + +$stopWatch.Stop() +Write-Host "Elapsed Runtime:" $stopWatch.Elapsed.Hours "Hours" $stopWatch.Elapsed.Minutes "minutes and" $stopWatch.Elapsed.Seconds "seconds." -BackgroundColor White -ForegroundColor Black +#End of Script +}#End of function + + +#start of function +Function AddDatastores +{ +<# +.SYNOPSIS + Add datastores to a cluster. +.DESCRIPTION + This will create a csv file whcih is opened in excel. Once you popuate the details, you have to save & close it. + Hit return/enter to proceed and the script will + add the datastores to the 1st host of the cluster + rescan all the hosts of the cluster +.NOTES + File Name : AddDatastores.ps1 + Author : gajendra d ambi + Date : March 2016 + Prerequisite : PowerShell v4+, powercli 6+ over win7 and upper. + Copyright - None +.LINK + Script posted over: github.com/gajuambi/vmware +#> + +#Start of Script + +New-VIProperty -Name "Runtime" -ObjectType "ScsiLun" -Value { + param($scsilun) + #http://www.lucd.info/2010/10/17/runtime-name-via-extensiondata-and-new-viproperty/ + #twitter/lucd22 + #many a times (for some storages) runtime is empty, thus using this scriptlet to populate/repopulate the same + $storDev = $scsilun.VMHost.ExtensionData.Config.StorageDevice + $key = ($storDev.PlugStoreTopology.Device | where {$_.Lun -eq $scsilun.Key}).Key + $stordev.PlugStoreTopology.Path | where {$_.Device -eq $key} | %{ + $device = $_ + $adapterKey = ($stordev.PlugStoreTopology.Adapter | where {$_.Key -eq $device.Adapter}).Adapter + $adapter = ($stordev.HostBusAdapter | where {$_.Key -eq $adapterKey}).Device + $adapter + ":C" + $device.ChannelNumber + ":T" + $device.TargetNumber + ":L" + $device.LunNumber + } +} -Force + + +Write-Host " +A CSV file will be opened (open in excel/spreadsheet) +populate the values, +save & close the file, +Hit Enter to proceed +" -ForegroundColor Blue -BackgroundColor White +$csv = "$PSScriptRoot/AddLuns.csv" +get-process | Select-Object Cluster,LunID,DatastoreName,vmhba | Export-Csv -Path $csv -Encoding ASCII -NoTypeInformation +Start-Process $csv +Read-Host "Hit Enter/Return to proceed" + +$stopWatch = [system.diagnostics.stopwatch]::startNew() +$stopWatch.Start() + +$csv = Import-Csv $csv + foreach ($line in $csv) #using trim() to make sure unnecessary spaces before or after any values in the csv files are removed + { + $cluster = $($line.Cluster) + $cluster = $cluster.trim() + + $lunid = $($line.LunID) + $lunid = $lunid.trim() + + $ds = $($line.DatastoreName) + $ds = $ds.trim() + + $vmhba = $($line.vmhba) + $runtime = ":C0:T0:L$lunid" + $runtime = $vmhba+$runtime + $vmhost = (get-cluster $cluster | get-vmhost)[0] + $naa = (Get-SCSILun -VMhost $vmhost -LunType Disk | where Runtime -eq $runtime).CanonicalName + New-Datastore -VMHost $vmhost -Name $ds -Path $naa -vmfs -Confirm:$false + } + + $cluster = $csv.Cluster | get-unique + get-cluster $cluster | get-vmhost | Get-VMHostStorage -RescanAllHba + +$stopWatch.Stop() +Write-Host "Elapsed Runtime:" $stopWatch.Elapsed.Hours "Hours" $stopWatch.Elapsed.Minutes "minutes and" $stopWatch.Elapsed.Seconds "seconds." -BackgroundColor White -ForegroundColor Black +#End of Script +}#End of function + +#start of function +Function ConfigDrs +{ +<# +.SYNOPSIS + Configure DRS on the cluster. +.DESCRIPTION + This will configure DRS on a specified cluster. +.NOTES + File Name : ConfigDrs.ps1 + Author : gajendra d ambi + Date : March 2016 + Prerequisite : PowerShell v4+, powercli 6+ over win7 and upper. + Copyright - None +.LINK + Script posted over: github.com/gajuambi/vmware +#> + +#Start of Script + +$cluster = Read-Host "name of the cluster?" +Write-Host " +choose the DRS Mode +1. FullyAutomated +2. Manual +3. PartiallyAutomated +" -ForegroundColor Blue -BackgroundColor White +$DrsLevel = Read-Host "type 1 or 2 or 3" + +$stopWatch = [system.diagnostics.stopwatch]::startNew() +$stopWatch.Start() + +if ($DrsLevel -eq 1) { $DrsLevel = "FullyAutomated" } +if ($DrsLevel -eq 2) { $DrsLevel = "Manual" } +if ($DrsLevel -eq 3) { $DrsLevel = "PartiallyAutomated" } + +Get-Cluster $cluster | Set-Cluster -DrsEnabled:$true -DrsAutomationLevel $DrsLevel -confirm:$false + +$stopWatch.Stop() +Write-Host "Elapsed Runtime:" $stopWatch.Elapsed.Hours "Hours" $stopWatch.Elapsed.Minutes "minutes and" $stopWatch.Elapsed.Seconds "seconds." -BackgroundColor White -ForegroundColor Black +#End of Script +}#End of function + + +#start of function +Function VMAffinity +{ +<# +.SYNOPSIS + Create VMAffinity DRS Rule. +.DESCRIPTION + This uses custom functions to create DRS VMAffinity rules between VMs where VMs will be made to stay on the same host by the DRS. +.NOTES + File Name : VMAffinity.ps1 + Author : gajendra d ambi + Date : February 2016 + Prerequisite : PowerShell v4+, powercli 6+ over win7 and upper. + Copyright - None +.LINK + Script posted over: github.com/gajuambi/vmware +#> + +#Start of Script +$cluster = Read-Host "Name of the Cluster?" +$drsrule = Read-Host "Type the Name of the DRS Rule" +$vms = Read-Host "Name of the VMs (separated by comma, no space)?" +$vms = $vms.split(',') + +$stopWatch = [system.diagnostics.stopwatch]::startNew() +$stopWatch.Start() + +New-DrsRule –Name $drsrule -Cluster $cluster –KeepTogether $true –VM $vms + +$stopWatch.Stop() +Write-Host "Elapsed Runtime:" $stopWatch.Elapsed.Hours "Hours" $stopWatch.Elapsed.Minutes "minutes and" $stopWatch.Elapsed.Seconds "seconds." -BackgroundColor White -ForegroundColor Black +#End of Script +}#End of function + +Function New-DrsVmGroup { +<# +.SYNOPSIS + Creates a new DRS VM group +.DESCRIPTION + This function creates a new DRS VM group in the DRS Group Manager +.NOTES + Author: Arnim van Lieshout +.PARAMETER VM + The VMs to add to the group. Supports objects from the pipeline. +.PARAMETER Cluster + The cluster to create the new group on. +.PARAMETER Name + The name for the new group. +.EXAMPLE + PS> Get-VM VM001,VM002 | New-DrsVmGroup -Name "VmGroup01" -Cluster CL01 +.EXAMPLE + PS> New-DrsVmGroup -VM VM001,VM002 -Name "VmGroup01" -Cluster (Get-CLuster CL01) +#> + + Param( + #http://www.van-lieshout.com/2011/06/drs-rules/ + #Arnim van Lieshout + [parameter(valuefrompipeline = $true, mandatory = $true, + HelpMessage = "Enter a vm entity")] + [PSObject]$VM, + [parameter(mandatory = $true, + HelpMessage = "Enter a cluster entity")] + [PSObject]$Cluster, + [parameter(mandatory = $true, + HelpMessage = "Enter a name for the group")] + [String]$Name) + + begin { + switch ($Cluster.gettype().name) { + "String" {$cluster = Get-Cluster $cluster | Get-View} + "ClusterImpl" {$cluster = $cluster | Get-View} + "Cluster" {} + default {throw "No valid type for parameter -Cluster specified"} + } + $spec = New-Object VMware.Vim.ClusterConfigSpecEx + $group = New-Object VMware.Vim.ClusterGroupSpec + $group.operation = "add" + $group.Info = New-Object VMware.Vim.ClusterVmGroup + $group.Info.Name = $Name + } + + Process { + switch ($VM.gettype().name) { + "String" {Get-VM -Name $VM | %{$group.Info.VM += $_.Extensiondata.MoRef}} + "VirtualMachineImpl" {$group.Info.VM += $VM.Extensiondata.MoRef} + "VirtualMachine" {$group.Info.VM += $VM.MoRef} + default {throw "No valid type for parameter -VM specified"} + } + } + + End { + if ($group.Info.VM) { + $spec.GroupSpec += $group + $cluster.ReconfigureComputeResource_Task($spec,$true) + } + else { + throw "No valid VMs specified" + } + } + +} + +#start of function +Function DrsHostGroup +{ +<# +.SYNOPSIS + Create DrsHostGroup DRS Rule. +.DESCRIPTION + This uses custom functions to create DRS DrsHostGroup rules between VMs where VMs will be made to stay on the same host by the DRS. +.NOTES + File Name : DrsHostGroup.ps1 + Author : gajendra d ambi + Date : February 2016 + Prerequisite : PowerShell v4+, powercli 6+ over win7 and upper. + Copyright - None +.LINK + Script posted over: github.com/gajuambi/vmware +#> + +#Start of Script +$cluster = Read-Host "Name of the Cluster?" +$vmhosts = Read-Host "Type the Name of the host/hosts (separated only by a comma and no spaces)" +$vmhosts = $vmhosts.split(',') +$hostgroup = Read-Host "Type the Name of the Hostgroup" + +$stopWatch = [system.diagnostics.stopwatch]::startNew() +$stopWatch.Start() + +Get-Cluster $cluster | Get-VMHost $vmhosts | New-DrsHostGroup -Name $hostgroup + +$stopWatch.Stop() +Write-Host "Elapsed Runtime:" $stopWatch.Elapsed.Hours "Hours" $stopWatch.Elapsed.Minutes "minutes and" $stopWatch.Elapsed.Seconds "seconds." -BackgroundColor White -ForegroundColor Black +#End of Script +}#End of function + +#start of function +Function DrsHostGroup +{ +<# +.SYNOPSIS + Create DrsHostGroup DRS Rule. +.DESCRIPTION + This uses custom functions to create DRS DrsHostGroup rules between VMs where VMs will be made to stay on the same host by the DRS. +.NOTES + File Name : DrsHostGroup.ps1 + Author : gajendra d ambi + Date : February 2016 + Prerequisite : PowerShell v4+, powercli 6+ over win7 and upper. + Copyright - None +.LINK + Script posted over: github.com/gajuambi/vmware +#> + +#Start of Script +$cluster = Read-Host "Name of the Cluster?" +$vmhosts = Read-Host "Type the Name of the host/hosts (separated only by a comma and no spaces)" +$vmhosts = $vmhosts.split(',') +$hostgroup = Read-Host "Type the Name of the Hostgroup" +Get-Cluster $cluster | Get-VMHost $vmhosts | New-DrsHostGroup -Name $hostgroup + +#End of Script +}#End of function + +#start of function +Function DRSVMToHostRule +{ +<# +.SYNOPSIS + Create DRSVMToHostRule DRS Rule. +.DESCRIPTION + This uses custom functions to create DRS DRSVMToHostRule rules between VMs where VMs will be made to stay on the same host by the DRS. +.NOTES + File Name : DRSVMToHostRule.ps1 + Author : gajendra d ambi + Date : February 2016 + Prerequisite : PowerShell v4+, powercli 6+ over win7 and upper. + Copyright - None +.LINK + Script posted over: github.com/gajuambi/vmware +#> + +#Start of Script +$cluster = Read-Host "Name of the Cluster?" +$drsrule = Read-Host "Type the Name of the DRS Rule" +$vmgroup = Read-Host "Type the Name of the VM group" +$hostgroup = Read-Host "Type the Name of the Hostgroup" + +$stopWatch = [system.diagnostics.stopwatch]::startNew() +$stopWatch.Start() + +New-DrsVMToHostRule -VMGroup $vmgroup -HostGroup $hostgroup -Name $drsrule -Cluster $cluster -AntiAffine -Mandatory + +$stopWatch.Stop() +Write-Host "Elapsed Runtime:" $stopWatch.Elapsed.Hours "Hours" $stopWatch.Elapsed.Minutes "minutes and" $stopWatch.Elapsed.Seconds "seconds." -BackgroundColor White -ForegroundColor Black +#End of Script# +}#End of function + +#start of function +Function VMAntiAffinity +{ +<# +.SYNOPSIS + Create VMAntiAffinity DRS Rule. +.DESCRIPTION + This uses custom functions to create DRS VMAntiAffinity rules between VMs where VMs will be made to stay on different hosts by the DRS. +.NOTES + File Name : VMAntiAffinity.ps1 + Author : gajendra d ambi + Date : February 2016 + Prerequisite : PowerShell v4+, powercli 6+ over win7 and upper. + Copyright - None +.LINK + Script posted over: github.com/gajuambi/vmware +#> + +#Start of Script +$cluster = Read-Host "Name of the Cluster?" +$drsrule = Read-Host "Type the Name of the DRS Rule" +$vms = Read-Host "Name of the VMs (separated by comma, no space)?" +$vms = $vms.split(',') + +$stopWatch = [system.diagnostics.stopwatch]::startNew() +$stopWatch.Start() + +New-DrsRule –Name $drsrule -Cluster $cluster –KeepTogether $false –VM $vms + +$stopWatch.Stop() +Write-Host "Elapsed Runtime:" $stopWatch.Elapsed.Hours "Hours" $stopWatch.Elapsed.Minutes "minutes and" $stopWatch.Elapsed.Seconds "seconds." -BackgroundColor White -ForegroundColor Black +#End of Script +}#End of function + +Function New-DRSVMToHostRule { +<# +.SYNOPSIS + Creates a new DRS VM to host rule +.DESCRIPTION + This function creates a new DRS vm to host rule +.NOTES + Author: Arnim van Lieshout +.PARAMETER VMGroup + The VMGroup name to include in the rule. +.PARAMETER HostGroup + The VMHostGroup name to include in the rule. +.PARAMETER Cluster + The cluster to create the new rule on. +.PARAMETER Name + The name for the new rule. +.PARAMETER AntiAffine + Switch to make the rule an AntiAffine rule. Default rule type is Affine. +.PARAMETER Mandatory + Switch to make the rule mandatory (Must run rule). Default rule is not mandatory (Should run rule) +.EXAMPLE + PS> New-DrsVMToHostRule -VMGroup "VMGroup01" -HostGroup "HostGroup01" -Name "VMToHostRule01" -Cluster CL01 -AntiAffine -Mandatory +#> + + Param( + #http://www.van-lieshout.com/2011/06/drs-rules/ + #Arnim van Lieshout + [parameter(mandatory = $true, + HelpMessage = "Enter a VM DRS group name")] + [String]$VMGroup, + [parameter(mandatory = $true, + HelpMessage = "Enter a host DRS group name")] + [String]$HostGroup, + [parameter(mandatory = $true, + HelpMessage = "Enter a cluster entity")] + [PSObject]$Cluster, + [parameter(mandatory = $true, + HelpMessage = "Enter a name for the group")] + [String]$Name, + [Switch]$AntiAffine, + [Switch]$Mandatory) + + switch ($Cluster.gettype().name) { + "String" {$cluster = Get-Cluster $cluster | Get-View} + "ClusterImpl" {$cluster = $cluster | Get-View} + "Cluster" {} + default {throw "No valid type for parameter -Cluster specified"} + } + + $spec = New-Object VMware.Vim.ClusterConfigSpecEx + $rule = New-Object VMware.Vim.ClusterRuleSpec + $rule.operation = "add" + $rule.info = New-Object VMware.Vim.ClusterVmHostRuleInfo + $rule.info.enabled = $true + $rule.info.name = $Name + $rule.info.mandatory = $Mandatory + $rule.info.vmGroupName = $VMGroup + if ($AntiAffine) { + $rule.info.antiAffineHostGroupName = $HostGroup + } + else { + $rule.info.affineHostGroupName = $HostGroup + } + $spec.RulesSpec += $rule + $cluster.ReconfigureComputeResource_Task($spec,$true) + +} + +Function New-DrsHostGroup +{ +<# +.SYNOPSIS + Creates a new DRS host group +.DESCRIPTION + This function creates a new DRS host group in the DRS Group Manager +.NOTES + Author: Arnim van Lieshout +.PARAMETER VMHost + The hosts to add to the group. Supports objects from the pipeline. +.PARAMETER Cluster + The cluster to create the new group on. +.PARAMETER Name + The name for the new group. +.EXAMPLE + PS> Get-VMHost ESX001,ESX002 | New-DrsHostGroup -Name "HostGroup01" -Cluster CL01 +.EXAMPLE + PS> New-DrsHostGroup -Host ESX001,ESX002 -Name "HostGroup01" -Cluster (Get-CLuster CL01) +#> + + Param( + #http://www.van-lieshout.com/2011/06/drs-rules/ + #Arnim van Lieshout + [parameter(valuefrompipeline = $true, mandatory = $true, + HelpMessage = "Enter a host entity")] + [PSObject]$VMHost, + [parameter(mandatory = $true, + HelpMessage = "Enter a cluster entity")] + [PSObject]$Cluster, + [parameter(mandatory = $true, + HelpMessage = "Enter a name for the group")] + [String]$Name) + + begin { + switch ($Cluster.gettype().name) { + "String" {$cluster = Get-Cluster $cluster | Get-View} + "ClusterImpl" {$cluster = $cluster | Get-View} + "Cluster" {} + default {throw "No valid type for parameter -Cluster specified"} + } + $spec = New-Object VMware.Vim.ClusterConfigSpecEx + $group = New-Object VMware.Vim.ClusterGroupSpec + $group.operation = "add" + $group.Info = New-Object VMware.Vim.ClusterHostGroup + $group.Info.Name = $Name + } + + Process { + switch ($VMHost.gettype().name) { + "String" {Get-VMHost -Name $VMHost | %{$group.Info.Host += $_.Extensiondata.MoRef}} + "VMHostImpl" {$group.Info.Host += $VMHost.Extensiondata.MoRef} + "HostSystem" {$group.Info.Host += $VMHost.MoRef} + default {throw "No valid type for parameter -VMHost specified"} + } + } + + End { + if ($group.Info.Host) { + $spec.GroupSpec += $group + $cluster.ReconfigureComputeResource_Task($spec,$true) + } + else { + throw "No valid hosts specified" + } + } + +} + +#start of function +function SetDNS +{ +<# +.SYNOPSIS + Update DNS +.DESCRIPTION + This will update the DNS, domain and searchdomain for the esxi hosts. +.NOTES + File Name : SetDNS.ps1 + Author : gajendra d ambi + Date : March 2016 + Prerequisite : PowerShell v4+, powercli 6+ over win7 and upper. + Copyright - None +.LINK + Script posted over: github.com/gajuambi/vmware +#> +#Start of script# +$cluster = Read-Host "name of the cluster[type * to include all clusters]?" +Write-Host "This new values will replace the existing values, hence add all the values" -ForegroundColor Yellow +$dnsadd = Read-Host "DNS Addresses(separate multiple entries with a comma)?" +$dnsadd = $dnsadd.split(',') +$domain = Read-Host "domain name?" + +$stopWatch = [system.diagnostics.stopwatch]::startNew() +$stopWatch.Start() + +get-cluster $cluster | get-vmhost | Get-VMHostNetwork | Set-VMHostNetwork -DnsAddress $dnsadd -DomainName $domain -SearchDomain $domain -Confirm:$false + +$stopWatch.Stop() +Write-Host "Elapsed Runtime:" $stopWatch.Elapsed.Hours "Hours" $stopWatch.Elapsed.Minutes "minutes and" $stopWatch.Elapsed.Seconds "seconds." -BackgroundColor White -ForegroundColor Black +#End of Script# +}#End of function + +#Start of function +function CoreDump +{ +<# +.SYNOPSIS + configure Coredump on esxi hosts +.DESCRIPTION + This will check the version of the esxi and based on the version of it, it will set the coredump settings on the host +.NOTES + File Name : CoreDump.ps1 + Author : gajendra d ambi + Date : January 2016 + recommended : PowerShell v4+, powercli 6+ over win7 and upper. + Copyright - None +.LINK + Script posted over: github.com/gajuambi/vmware +#> + +#start of the script +#start of the function + +$DumpTarget = Read-Host "Type the DumpTarget?:" +$vmk = Read-Host "Type the vmk number?:" + +$stopWatch = [system.diagnostics.stopwatch]::startNew() +$stopWatch.Start() + + foreach ($vmhost in (get-vmhost | sort)) { + if ((get-vmhost $vmhost).version -match 5.) { + $esxcli = get-vmhost $VMHost | Get-EsxCli + $esxcli.system.coredump.network.set($null, $vmk , $DumpTarget , "6500") + $esxcli.system.coredump.network.set("true") + $esxcli.system.coredump.network.get() + } + + if ((get-vmhost $vmhost).version -match 6.) { + $esxcli = get-vmhost $vmhost | get-esxcli + $esxcli.system.coredump.network.set($null , $vmk , $null , $DumpTarget , "6500") + $esxcli.system.coredump.network.set("true") + $esxcli.system.coredump.network.get() + } + } + +$stopWatch.Stop() +Write-Host "Elapsed Runtime:" $stopWatch.Elapsed.Hours "Hours" $stopWatch.Elapsed.Minutes "minutes and" $stopWatch.Elapsed.Seconds "seconds." -BackgroundColor White -ForegroundColor Black +#End of Script# +}#End of function + +#start of function +function EsxiAdvanced +{ +<# +.SYNOPSIS + Set value to a chosen advancedsettig +.DESCRIPTION + This will ask set many of the esxi advancedsettings which are exposed in esxi>configuration>advancedsettings. + It will require 2 inputs from the user. + name of the advanced setting and value of the advancedsetting. +.NOTES + File Name : EsxiAdvanced.ps1 + Author : gajendra d ambi + Date : March 2016 + Prerequisite : PowerShell v4+, powercli 6+ over win7 and upper. + Copyright - None +.LINK + Script posted over: github.com/gajuambi/vmware +#> +#Start of script# +$cluster = Read-Host "name of the cluster[type * to include all clusters]?" +$AdvSet = Read-Host "name of the advancedsetting[case sensitive]?" +$value = Read-Host "value for the advancedsetting?" + +$stopWatch = [system.diagnostics.stopwatch]::startNew() +$stopWatch.Start() + + foreach ($vmhost in (Get-Cluster $cluster)) + { + Get-VMHost $vmhost | get-advancedsetting -Name $AdvSet | Set-AdvancedSetting -Value $value -Confirm:$false + } + +$stopWatch.Stop() +Write-Host "Elapsed Runtime:" $stopWatch.Elapsed.Hours "Hours" $stopWatch.Elapsed.Minutes "minutes and" $stopWatch.Elapsed.Seconds "seconds." -BackgroundColor White -ForegroundColor Black +#End of Script# +}#End of function + +#start of function +function SetIpv6 +{ +<# +.SYNOPSIS + Update Ipv6 +.DESCRIPTION + This will disable/enable Ipv6 on esxi hosts of a chosen cluster. +.NOTES + File Name : SetIpv6.ps1 + Author : gajendra d ambi + Date : March 2016 + Prerequisite : PowerShell v4+, powercli 6+ over win7 and upper. + Copyright - None +.LINK + Script posted over: github.com/gajuambi/vmware +#> +#Start of script# +$cluster = Read-Host "name of the cluster[type * to include all clusters]?" +Write-Host " +1. Disable IPv6 +2. Enable IPv6 +" -ForegroundColor Blue -BackgroundColor White +$choice = Read-Host "type between 1 & 2" + +$stopWatch = [system.diagnostics.stopwatch]::startNew() +$stopWatch.Start() + +If ($choice -eq 1) { get-cluster $cluster | get-vmhost | Get-VMHostNetwork | Set-VMHostNetwork -IPv6Enabled $false } +If ($choice -eq 2) { get-cluster $cluster | get-vmhost | Get-VMHostNetwork | Set-VMHostNetwork -IPv6Enabled $true } + +$stopWatch.Stop() +Write-Host "Elapsed Runtime:" $stopWatch.Elapsed.Hours "Hours" $stopWatch.Elapsed.Minutes "minutes and" $stopWatch.Elapsed.Seconds "seconds." -BackgroundColor White -ForegroundColor Black + #End of Script# +}#End of function + +#start of function +function SetNTP +{ +<# +.SYNOPSIS + Update NTP +.DESCRIPTION + This will update the NTP servers to the esxi hosts. It will add one NTP server at a time. + It will not replace or overwrite any existing NTP servers. This will set the ntpd service to on. +.NOTES + File Name : SetNTP.ps1 + Author : gajendra d ambi + Date : March 2016 + Prerequisite : PowerShell v4+, powercli 6+ over win7 and upper. + Copyright - None +.LINK + Script posted over: github.com/gajuambi/vmware +#> +#Start of script# +$cluster = Read-Host "name of the cluster[type * to include all clusters]?" +Write-Host "This new values will replace the existing values, hence add all the values" -ForegroundColor Yellow +$ntp = Read-Host "NTP address(separate them with comma,no space..)" + +$stopWatch = [system.diagnostics.stopwatch]::startNew() +$stopWatch.Start() + +$ntp = $ntp.split(',') + + foreach ($vmhost in (Get-Cluster $cluster | get-vmhost | sort)) + { + Write-Host "adding ntp server to $vmhost" -ForegroundColor Green + Add-VMHostNTPServer -NtpServer $ntp -VMHost (Get-VMHost $vmhost) -Confirm:$false + Write-Host "setting ntp policy to on on $vmhost" -ForegroundColor Green + Get-VMHostService -VMHost (Get-VMHost $vmhost) | where Key -eq "ntpd" | Restart-VMHostService -Confirm:$false + Get-VMHostService -VMHost (Get-VMHost $vmhost) | where Key -eq "ntpd" | Set-VMHostService -policy "on" -Confirm:$false + } + +$stopWatch.Stop() +Write-Host "Elapsed Runtime:" $stopWatch.Elapsed.Hours "Hours" $stopWatch.Elapsed.Minutes "minutes and" $stopWatch.Elapsed.Seconds "seconds." -BackgroundColor White -ForegroundColor Black +#End of Script# +}#End of function + +#start of function +function SetFirewall +{ +<# +.SYNOPSIS + firewall settings for esxi hosts +.DESCRIPTION + Configure firewall per host in a cluster. These is a sample firewall setting here. You can populate the rest as per your business + standards. Run + get-vmhost | Get-VmhostFirewallException + to list the available firewall settings that you can turn on or off. +.NOTES + File Name : SetFirewall.ps1 + Author : gajendra d ambi + Date : March 2016 + Prerequisite : PowerShell v4+, powercli 6+ over win7 and upper. + Copyright - None +.LINK + Script posted over: github.com/gajuambi/vmware +#> +#Start of script# + +$stopWatch = [system.diagnostics.stopwatch]::startNew() +$stopWatch.Start() + +$cluster = Read-Host "name of the cluster[type * to include all clusters]?" + + foreach ($vmhost in (Get-Cluster $cluster)) + { + Get-VMHost $vmhost | Get-VmhostFirewallException -Name "NTP Client" | Set-VMHostFirewallException -enabled:$true -Confirm:$false + } + +$stopWatch.Stop() +Write-Host "Elapsed Runtime:" $stopWatch.Elapsed.Hours "Hours" $stopWatch.Elapsed.Minutes "minutes and" $stopWatch.Elapsed.Seconds "seconds." -BackgroundColor White -ForegroundColor Black +#End of Script# +}#End of function + +#start of function +function SetEsxiPerf +{ +<# +.SYNOPSIS + Configure powersaving policy or performance policy on esxi. +.DESCRIPTION + This will configure 1 of the 3 levels of energy saving or performance setting on your esxi hosts. + 3 valid options are HighPerformance, Balanced, LowPower. +.NOTES + File Name : SetEsxiPerf.ps1 + Author : gajendra d ambi + Date : March 2016 + Prerequisite : PowerShell v4+, powercli 6+ over win7 and upper. + Copyright - None +.LINK + Script posted over: github.com/gajuambi/vmware +#> +#Start of script# + +$cluster = Read-Host "name of the cluster[type * to include all clusters]?" +Write-Host " +1. HighPerformance +2. Balanced +3. LowPower +" -ForegroundColor Blue -BackgroundColor White +$perf = Read-Host "one of the following is a valid choice. Type 1,2 or 3" + +$stopWatch = [system.diagnostics.stopwatch]::startNew() +$stopWatch.Start() + +if ($perf -eq 1) {$perf = "HighPerformance"} +if ($perf -eq 2) {$perf = "Balanced" } +if ($perf -eq 3) {$perf = "LowPower" } + +(Get-View (Get-Cluster $cluster | Get-VMHost | Get-View).ConfigManager.PowerSystem).ConfigurePowerPolicy($perf) + +$stopWatch.Stop() +Write-Host "Elapsed Runtime:" $stopWatch.Elapsed.Hours "Hours" $stopWatch.Elapsed.Minutes "minutes and" $stopWatch.Elapsed.Seconds "seconds." -BackgroundColor White -ForegroundColor Black +#End of Script# +}#End of function + +#start of function +function SetScratch +{ +<# +.SYNOPSIS + Create & configure Scratch partition on Esxi hosts +.DESCRIPTION + This will create scratch location on the local storage of the esxi hosts and then map that as the + scratch location for that host. Please note that if the local storage of your esxi blades is of different + format that '*-localstorage' then please change the line + $ds = Get-VMHost -name $vmhost | get-datastore -Name '*-localstorage' + accordingly. +.NOTES + File Name : SetScratch.ps1 + Author : gajendra d ambi + Date : March 2016 + Prerequisite : PowerShell v4+, powercli 6+ over win7 and upper. + Copyright - None +.LINK + Script posted over: github.com/gajuambi/vmware +#> +#Start of script# +$resetloc = get-location +$cluster = Read-Host "name of the cluster[type * to include all clusters]?" +Write-Host " +Leave blank if there is just one datastore, +to create scratch on a datastore with it's name matching 'localstorage' type localstorage, +" -BackgroundColor White -ForegroundColor Black +$pattern = Read-Host "?" +$pattern = "*"+$pattern+"*" + +$stopWatch = [system.diagnostics.stopwatch]::startNew() +$stopWatch.Start() + +foreach ($vmhost in (get-cluster $cluster | get-vmhost | sort)) { + $vmhost = (get-vmhost $vmhost).Name + $scratchfolder = '.locker_'+($vmhost.Split('.')[0]) + $ds = Get-VMHost -name $vmhost | get-datastore -Name $pattern + $location = ($vmhost.Split('.')[0]) + New-PSDrive -Name $location -Root \ -PSProvider VimDatastore -Datastore ($ds) -Scope global + Set-Location $location":" + ni $scratchfolder -ItemType directory -ErrorAction SilentlyContinue + Get-VMhost $vmhost | Get-AdvancedSetting -Name "ScratchConfig.ConfiguredScratchLocation" | Set-AdvancedSetting -Value "/vmfs/volumes/$ds/$scratchfolder" -confirm:$false + Set-Location $resetloc + Remove-PSDrive $location + } + get-cluster $cluster | get-vmhost | sort | Get-AdvancedSetting -Name "ScratchConfig.ConfiguredScratchLocation" | select Entity, Value | fl + +$stopWatch.Stop() +Write-Host "Elapsed Runtime:" $stopWatch.Elapsed.Hours "Hours" $stopWatch.Elapsed.Minutes "minutes and" $stopWatch.Elapsed.Seconds "seconds." -BackgroundColor White -ForegroundColor Black +#End of Script# +}#End of function + +#start of function +function SetSnmp +{ +<# +.SYNOPSIS + Configure SNMP +.DESCRIPTION + This will configure SNMP using powercli on esxi hosts. It uses esxcli commands into powercli. +.NOTES + File Name : SetSnmp.ps1 + Author : gajendra d ambi + Date : March 2016 + Prerequisite : PowerShell v4+, powercli 6+ over win7 and upper. + Copyright - None +.LINK + Script posted over: github.com/gajuambi/vmware +#> +#Start of script# +$cluster = Read-Host "name of the cluster[type * to include all clusters]?" +$snmp = Read-Host "Type the snmp target" +$string = Read-Host "Type the snmp communities string" + +$stopWatch = [system.diagnostics.stopwatch]::startNew() +$stopWatch.Start() + + foreach ($vmhost in (get-cluster $cluster | get-vmhost | sort)) { + $esxcli = get-vmhost $vmhost | get-esxcli + $esxcli.system.snmp.set($null,$null,$null,$null,$null,$null,$null,$null,$null,$null,$null,"true",$null,$null,$null,$null) + $esxcli.system.snmp.set($null,$string,$null,$null,$null,$null,$null,$null,$null,$null,$null,$null,$null,$null,$null,$null) + $esxcli.system.snmp.set($null,$null,$null,$null,$null,$null,$null,$null,$null,$null,$null,$null,$null,"$snmp/$string","$snmp/$string",$null) + $esxcli.system.snmp.set($null,$null,"true",$null,$null,$null,$null,$null,$null,$null,$null,$null,$null,$null,$null,$null) + $esxcli.system.snmp.get() + } + +$stopWatch.Stop() +Write-Host "Elapsed Runtime:" $stopWatch.Elapsed.Hours "Hours" $stopWatch.Elapsed.Minutes "minutes and" $stopWatch.Elapsed.Seconds "seconds." -BackgroundColor White -ForegroundColor Black +#End of Script# +}#End of function + +#start of function +function SetSyslog +{ +<# +.SYNOPSIS + Configure Syslog +.DESCRIPTION + This will configure Syslog using powercli. This only set the syslog servers and enable syslog on the esxi hosts. + You may however include additional advanced syslog configuarations like Syslog.global.defaultSize and others. + This will also create a firewall exception for the syslog. +.NOTES + File Name : SetSyslog.ps1 + Author : gajendra d ambi + Date : March 2016 + Prerequisite : PowerShell v4+, powercli 6+ over win7 and upper. + Copyright - None +.LINK + Script posted over: github.com/gajuambi/vmware +#> +#Start of script# +$cluster = Read-Host "name of the cluster[type * to include all clusters]?" +$syslog = Read-Host "Syslog Target?" + +$stopWatch = [system.diagnostics.stopwatch]::startNew() +$stopWatch.Start() + +foreach ($vmhost in (get-cluster $cluster | get-vmhost | sort)) { +get-vmhost $vmhost | Get-AdvancedSetting -Name Syslog.global.logHost | Set-AdvancedSetting -Value $Syslog -Confirm:$false +get-vmhost $vmhost | Get-VMHostFirewallException -Name "syslog" | Set-VMHostFirewallException -enabled:$true -Confirm:$false + } + +$stopWatch.Stop() +Write-Host "Elapsed Runtime:" $stopWatch.Elapsed.Hours "Hours" $stopWatch.Elapsed.Minutes "minutes and" $stopWatch.Elapsed.Seconds "seconds." -BackgroundColor White -ForegroundColor Black +#End of Script# +}#End of function + +#start of function +function PowerMgmt +{ +<# +.SYNOPSIS + Perform power actions on esxi +.DESCRIPTION + When we poweroff, shutdown, reboot a host we need to provide a reason to do so. This is especially + boring and time consuming if you have a lot of hosts on which you have to do this. This is to ease + that pain. It has 4 options to choose from + A. Enter Maintenance Mode + B. Exit Maintenance Mode + C. Shutdown + D. Reboot + It will ask the reason to perform that action and it will input that reason before it performs the + chosen action. +.NOTES + File Name : PowerMgmt.ps1 + Author : gajendra d ambi + Date : March 2016 + Prerequisite : PowerShell v4+, powercli 6+ over win7 and upper. + Copyright - None +.LINK + Script posted over: github.com/gajuambi/vmware +#> +#Start of script# +$cluster = Read-Host "name of the cluster[type * to include all clusters]?" +Write-Host " +1.Enter Maintenance Mode +2.Exit Maintenance Mode +3.Shutdown (the hosts which are in maintenance mode) +4.Reboot (the hosts which are in maintenance mode) +" -ForegroundColor Blue -BackgroundColor White +$axn = Read-Host "Type a number from 1 to 4" + +$stopWatch = [system.diagnostics.stopwatch]::startNew() +$stopWatch.Start() + +$vmhosts = Get-cluster $cluster | get-vmhost +if ($axn -eq 1) {$vmhosts | set-vmhost -State Maintenance} +if ($axn -eq 2) {$vmhosts | set-vmhost -State Connected} +$vmhosts = get-cluster $cluster | get-vmhost -State Maintenance +if ($axn -eq 3) + {Write-Host "enter a reason for this action" -ForegroundColor Yellow + $reason = Read-Host "" + foreach ($vmhost in $vmhosts) { + $esxcli = get-esxcli + $esxcli.system.shutdown.poweroff($null,$reason) + } + } +if ($axn -eq 4) + {Write-Host "enter a reason for this action" -ForegroundColor Yellow + $reason = Read-Host "" + foreach ($vmhost in $vmhosts) { + $esxcli = get-esxcli + $esxcli.system.shutdown.poweroff($null,$reason) + } + } + +$stopWatch.Stop() +Write-Host "Elapsed Runtime:" $stopWatch.Elapsed.Hours "Hours" $stopWatch.Elapsed.Minutes "minutes and" $stopWatch.Elapsed.Seconds "seconds." -BackgroundColor White -ForegroundColor Black +#End of Script# +}#End of function + +#start of function +function Setpcscd +{ +<# +.SYNOPSIS + Configure pcscd [PC/SC Smart Card Daemon] +.DESCRIPTION + Depending upon the choice that you make + This will enable pcscd. + This will disable pcscd. + This will set pcscd policy to On which will be persistent across reboot. + This will set pcscd policy to Off which will be persistent across reboot. +.NOTES + File Name : Setpcscd.ps1 + Author : gajendra d ambi + Date : March 2016 + Prerequisite : PowerShell v4+, powercli 6+ over win7 and upper. + Copyright - None +.LINK + Script posted over: github.com/gajuambi/vmware +#> +#Start of script# +$cluster = Read-Host "name of the cluster[type * to include all clusters]?" +Write-Host "pcscd [PC/SC Smart Card Daemon] options + 1. Enable pcscd + 2. Disable pcscd + 3. pcscd Policy On + 4. pcscd Policy Off + " -BackgroundColor White -ForegroundColor Blue #options to choose from + $a = Read-Host "Choose a number from 1 to 4" + +$stopWatch = [system.diagnostics.stopwatch]::startNew() +$stopWatch.Start() + + if ($a -eq 1) {get-cluster $cluster | get-vmhost | get-vmhostservice | where Key -EQ pcscd | Start-VMHostService -Confirm:$false} + if ($a -eq 2) {get-cluster $cluster | get-vmhost | get-vmhostservice | where Key -EQ pcscd | stop-VMHostService -Confirm:$false} + if ($a -eq 3) {get-cluster $cluster | get-vmhost | get-vmhostservice | where Key -EQ pcscd | Set-VMHostService -Policy On -Confirm:$false} + if ($a -eq 4) {get-cluster $cluster | get-vmhost | get-vmhostservice | where Key -EQ pcscd | Set-VMHostService -Policy Off -Confirm:$false} + +$stopWatch.Stop() +Write-Host "Elapsed Runtime:" $stopWatch.Elapsed.Hours "Hours" $stopWatch.Elapsed.Minutes "minutes and" $stopWatch.Elapsed.Seconds "seconds." -BackgroundColor White -ForegroundColor Black +#End of Script# +}#End of function + +#start of function +function Setsfcbd +{ +<# +.SYNOPSIS + Configure sfcbd-watchdog [CIM Server] +.DESCRIPTION + Depending upon the choice that you make + This will enable sfcbd. + This will disable sfcbd. + This will set sfcbd policy to On which will be persistent across reboot. + This will set sfcbd policy to Off which will be persistent across reboot. +.NOTES + File Name : Setsfcbd.ps1 + Author : gajendra d ambi + Date : March 2016 + Prerequisite : PowerShell v4+, powercli 6+ over win7 and upper. + Copyright - None +.LINK + Script posted over: github.com/gajuambi/vmware +#> +#Start of script# +$cluster = Read-Host "name of the cluster[type * to include all clusters]?" +Write-Host "sfcbd-watchdog [CIM Server] options + 1. Enable sfcbd + 2. Disable sfcbd + 3. sfcbd Policy On + 4. sfcbd Policy Off + " -BackgroundColor White -ForegroundColor Blue #options to choose from + $a = Read-Host "Choose a number from 1 to 4" + +$stopWatch = [system.diagnostics.stopwatch]::startNew() +$stopWatch.Start() + + if ($a -eq 1) {get-cluster $cluster | get-vmhost | get-vmhostservice | where Key -EQ sfcbd | Start-VMHostService -Confirm:$false} + if ($a -eq 2) {get-cluster $cluster | get-vmhost | get-vmhostservice | where Key -EQ sfcbd | stop-VMHostService -Confirm:$false} + if ($a -eq 3) {get-cluster $cluster | get-vmhost | get-vmhostservice | where Key -EQ sfcbd | Set-VMHostService -Policy On -Confirm:$false} + if ($a -eq 4) {get-cluster $cluster | get-vmhost | get-vmhostservice | where Key -EQ sfcbd | Set-VMHostService -Policy Off -Confirm:$false} + +$stopWatch.Stop() +Write-Host "Elapsed Runtime:" $stopWatch.Elapsed.Hours "Hours" $stopWatch.Elapsed.Minutes "minutes and" $stopWatch.Elapsed.Seconds "seconds." -BackgroundColor White -ForegroundColor Black +#End of Script# +}#End of function + +#start of function +function SetTSM +{ +<# +.SYNOPSIS + Configure TSM [ESXi Shell] +.DESCRIPTION + Depending upon the choice that you make + This will enable TSM. + This will disable TSM. + This will set TSM policy to On which will be persistent across reboot. + This will set TSM policy to Off which will be persistent across reboot. +.NOTES + File Name : SetTSM.ps1 + Author : gajendra d ambi + Date : March 2016 + Prerequisite : PowerShell v4+, powercli 6+ over win7 and upper. + Copyright - None +.LINK + Script posted over: github.com/gajuambi/vmware +#> +#Start of script# +$cluster = Read-Host "name of the cluster[type * to include all clusters]?" +Write-Host "TSM [ESXi Shell] options + 1. Enable TSM + 2. Disable TSM + 3. TSM Policy On + 4. TSM Policy Off + " -BackgroundColor White -ForegroundColor Blue #options to choose from + $a = Read-Host "Choose a number from 1 to 4" + +$stopWatch = [system.diagnostics.stopwatch]::startNew() +$stopWatch.Start() + + if ($a -eq 1) {get-cluster $cluster | get-vmhost | get-vmhostservice | where Key -EQ TSM | Start-VMHostService -Confirm:$false} + if ($a -eq 2) {get-cluster $cluster | get-vmhost | get-vmhostservice | where Key -EQ TSM | stop-VMHostService -Confirm:$false} + if ($a -eq 3) {get-cluster $cluster | get-vmhost | get-vmhostservice | where Key -EQ TSM | Set-VMHostService -Policy On -Confirm:$false} + if ($a -eq 4) {get-cluster $cluster | get-vmhost | get-vmhostservice | where Key -EQ TSM | Set-VMHostService -Policy Off -Confirm:$false} + +$stopWatch.Stop() +Write-Host "Elapsed Runtime:" $stopWatch.Elapsed.Hours "Hours" $stopWatch.Elapsed.Minutes "minutes and" $stopWatch.Elapsed.Seconds "seconds." -BackgroundColor White -ForegroundColor Black +#End of Script# +}#End of function + +#start of function +function Setvpxa +{ +<# +.SYNOPSIS + Configure vpxa [VMware vCenter Agent] +.DESCRIPTION + Depending upon the choice that you make + This will enable vpxa. + This will disable vpxa. + This will set vpxa policy to On which will be persistent across reboot. + This will set vpxa policy to Off which will be persistent across reboot. +.NOTES + File Name : Setvpxa.ps1 + Author : gajendra d ambi + Date : March 2016 + Prerequisite : PowerShell v4+, powercli 6+ over win7 and upper. + Copyright - None +.LINK + Script posted over: github.com/gajuambi/vmware +#> +#Start of script# +$cluster = Read-Host "name of the cluster[type * to include all clusters]?" +Write-Host "vpxa [VMware vCenter Agent] options + 1. Enable vpxa + 2. Disable vpxa + 3. vpxa Policy On + 4. vpxa Policy Off + " -BackgroundColor White -ForegroundColor Blue #options to choose from + $a = Read-Host "Choose a number from 1 to 4" + +$stopWatch = [system.diagnostics.stopwatch]::startNew() +$stopWatch.Start() + + if ($a -eq 1) {get-cluster $cluster | get-vmhost | get-vmhostservice | where Key -EQ vpxa | Start-VMHostService -Confirm:$false} + if ($a -eq 2) {get-cluster $cluster | get-vmhost | get-vmhostservice | where Key -EQ vpxa | stop-VMHostService -Confirm:$false} + if ($a -eq 3) {get-cluster $cluster | get-vmhost | get-vmhostservice | where Key -EQ vpxa | Set-VMHostService -Policy On -Confirm:$false} + if ($a -eq 4) {get-cluster $cluster | get-vmhost | get-vmhostservice | where Key -EQ vpxa | Set-VMHostService -Policy Off -Confirm:$false} + +$stopWatch.Stop() +Write-Host "Elapsed Runtime:" $stopWatch.Elapsed.Hours "Hours" $stopWatch.Elapsed.Minutes "minutes and" $stopWatch.Elapsed.Seconds "seconds." -BackgroundColor White -ForegroundColor Black +#End of Script# +}#End of function + +#start of function +function Setvprobed +{ +<# +.SYNOPSIS + Configure vprobed [VProbe Daemon] +.DESCRIPTION + Depending upon the choice that you make + This will enable vprobed. + This will disable vprobed. + This will set vprobed policy to On which will be persistent across reboot. + This will set vprobed policy to Off which will be persistent across reboot. +.NOTES + File Name : Setvprobed.ps1 + Author : gajendra d ambi + Date : March 2016 + Prerequisite : PowerShell v4+, powercli 6+ over win7 and upper. + Copyright - None +.LINK + Script posted over: github.com/gajuambi/vmware +#> +#Start of script# +$cluster = Read-Host "name of the cluster[type * to include all clusters]?" +Write-Host "vprobed [VProbe Daemon] options + 1. Enable vprobed + 2. Disable vprobed + 3. vprobed Policy On + 4. vprobed Policy Off + " -BackgroundColor White -ForegroundColor Blue #options to choose from + $a = Read-Host "Choose a number from 1 to 4" + +$stopWatch = [system.diagnostics.stopwatch]::startNew() +$stopWatch.Start() + + if ($a -eq 1) {get-cluster $cluster | get-vmhost | get-vmhostservice | where Key -EQ vprobed | Start-VMHostService -Confirm:$false} + if ($a -eq 2) {get-cluster $cluster | get-vmhost | get-vmhostservice | where Key -EQ vprobed | stop-VMHostService -Confirm:$false} + if ($a -eq 3) {get-cluster $cluster | get-vmhost | get-vmhostservice | where Key -EQ vprobed | Set-VMHostService -Policy On -Confirm:$false} + if ($a -eq 4) {get-cluster $cluster | get-vmhost | get-vmhostservice | where Key -EQ vprobed | Set-VMHostService -Policy Off -Confirm:$false} + +$stopWatch.Stop() +Write-Host "Elapsed Runtime:" $stopWatch.Elapsed.Hours "Hours" $stopWatch.Elapsed.Minutes "minutes and" $stopWatch.Elapsed.Seconds "seconds." -BackgroundColor White -ForegroundColor Black +#End of Script# +}#End of function + +#start of function +function Setntpd +{ +<# +.SYNOPSIS + Configure ntpd [NTP Daemon] +.DESCRIPTION + Depending upon the choice that you make + This will enable ntpd. + This will disable ntpd. + This will set ntpd policy to On which will be persistent across reboot. + This will set ntpd policy to Off which will be persistent across reboot. +.NOTES + File Name : Setntpd.ps1 + Author : gajendra d ambi + Date : March 2016 + Prerequisite : PowerShell v4+, powercli 6+ over win7 and upper. + Copyright - None +.LINK + Script posted over: github.com/gajuambi/vmware +#> +#Start of script# +$cluster = Read-Host "name of the cluster[type * to include all clusters]?" +Write-Host "ntpd [NTP Daemon] options + 1. Enable ntpd + 2. Disable ntpd + 3. ntpd Policy On + 4. ntpd Policy Off + " -BackgroundColor White -ForegroundColor Blue #options to choose from + $a = Read-Host "Choose a number from 1 to 4" + +$stopWatch = [system.diagnostics.stopwatch]::startNew() +$stopWatch.Start() + + if ($a -eq 1) {get-cluster $cluster | get-vmhost | get-vmhostservice | where Key -EQ ntpd | Start-VMHostService -Confirm:$false} + if ($a -eq 2) {get-cluster $cluster | get-vmhost | get-vmhostservice | where Key -EQ ntpd | stop-VMHostService -Confirm:$false} + if ($a -eq 3) {get-cluster $cluster | get-vmhost | get-vmhostservice | where Key -EQ ntpd | Set-VMHostService -Policy On -Confirm:$false} + if ($a -eq 4) {get-cluster $cluster | get-vmhost | get-vmhostservice | where Key -EQ ntpd | Set-VMHostService -Policy Off -Confirm:$false} + +$stopWatch.Stop() +Write-Host "Elapsed Runtime:" $stopWatch.Elapsed.Hours "Hours" $stopWatch.Elapsed.Minutes "minutes and" $stopWatch.Elapsed.Seconds "seconds." -BackgroundColor White -ForegroundColor Black +#End of Script# +}#End of function + +#start of function +function Setvmsyslogd +{ +<# +.SYNOPSIS + Configure vmsyslogd [Syslog Server] +.DESCRIPTION + Depending upon the choice that you make + This will enable vmsyslogd. + This will disable vmsyslogd. + This will set vmsyslogd policy to On which will be persistent across reboot. + This will set vmsyslogd policy to Off which will be persistent across reboot. +.NOTES + File Name : Setvmsyslogd.ps1 + Author : gajendra d ambi + Date : March 2016 + Prerequisite : PowerShell v4+, powercli 6+ over win7 and upper. + Copyright - None +.LINK + Script posted over: github.com/gajuambi/vmware +#> +#Start of script# +$cluster = Read-Host "name of the cluster[type * to include all clusters]?" +Write-Host "vmsyslogd [Syslog Server] options + 1. Enable vmsyslogd + 2. Disable vmsyslogd + 3. vmsyslogd Policy On + 4. vmsyslogd Policy Off + " -BackgroundColor White -ForegroundColor Blue #options to choose from + $a = Read-Host "Choose a number from 1 to 4" + +$stopWatch = [system.diagnostics.stopwatch]::startNew() +$stopWatch.Start() + + if ($a -eq 1) {get-cluster $cluster | get-vmhost | get-vmhostservice | where Key -EQ vmsyslogd | Start-VMHostService -Confirm:$false} + if ($a -eq 2) {get-cluster $cluster | get-vmhost | get-vmhostservice | where Key -EQ vmsyslogd | stop-VMHostService -Confirm:$false} + if ($a -eq 3) {get-cluster $cluster | get-vmhost | get-vmhostservice | where Key -EQ vmsyslogd | Set-VMHostService -Policy On -Confirm:$false} + if ($a -eq 4) {get-cluster $cluster | get-vmhost | get-vmhostservice | where Key -EQ vmsyslogd | Set-VMHostService -Policy Off -Confirm:$false} + +$stopWatch.Stop() +Write-Host "Elapsed Runtime:" $stopWatch.Elapsed.Hours "Hours" $stopWatch.Elapsed.Minutes "minutes and" $stopWatch.Elapsed.Seconds "seconds." -BackgroundColor White -ForegroundColor Black +#End of Script# +}#End of function + +#start of function +function Setlwsmd +{ +<# +.SYNOPSIS + Configure lwsmd [Active Directory Service] +.DESCRIPTION + Depending upon the choice that you make + This will enable lwsmd. + This will disable lwsmd. + This will set lwsmd policy to On which will be persistent across reboot. + This will set lwsmd policy to Off which will be persistent across reboot. +.NOTES + File Name : Setlwsmd.ps1 + Author : gajendra d ambi + Date : March 2016 + Prerequisite : PowerShell v4+, powercli 6+ over win7 and upper. + Copyright - None +.LINK + Script posted over: github.com/gajuambi/vmware +#> +#Start of script# +$cluster = Read-Host "name of the cluster[type * to include all clusters]?" +Write-Host "lwsmd [Active Directory Service] options + 1. Enable lwsmd + 2. Disable lwsmd + 3. lwsmd Policy On + 4. lwsmd Policy Off + " -BackgroundColor White -ForegroundColor Blue #options to choose from + $a = Read-Host "Choose a number from 1 to 4" + +$stopWatch = [system.diagnostics.stopwatch]::startNew() +$stopWatch.Start() + + if ($a -eq 1) {get-cluster $cluster | get-vmhost | get-vmhostservice | where Key -EQ lwsmd | Start-VMHostService -Confirm:$false} + if ($a -eq 2) {get-cluster $cluster | get-vmhost | get-vmhostservice | where Key -EQ lwsmd | stop-VMHostService -Confirm:$false} + if ($a -eq 3) {get-cluster $cluster | get-vmhost | get-vmhostservice | where Key -EQ lwsmd | Set-VMHostService -Policy On -Confirm:$false} + if ($a -eq 4) {get-cluster $cluster | get-vmhost | get-vmhostservice | where Key -EQ lwsmd | Set-VMHostService -Policy Off -Confirm:$false} + +$stopWatch.Stop() +Write-Host "Elapsed Runtime:" $stopWatch.Elapsed.Hours "Hours" $stopWatch.Elapsed.Minutes "minutes and" $stopWatch.Elapsed.Seconds "seconds." -BackgroundColor White -ForegroundColor Black +#End of Script# +}#End of function + +#start of function +function SetSSH +{ +<# +.SYNOPSIS + Configure TSM-SSH [SSH] +.DESCRIPTION + Depending upon the choice that you make + This will enable TSM-SSH. + This will disable TSM-SSH. + This will set TSM-SSH policy to On which will be persistent across reboot. + This will set TSM-SSH policy to Off which will be persistent across reboot. +.NOTES + File Name : SetSSH.ps1 + Author : gajendra d ambi + Date : March 2016 + Prerequisite : PowerShell v4+, powercli 6+ over win7 and upper. + Copyright - None +.LINK + Script posted over: github.com/gajuambi/vmware +#> +#Start of script# +$cluster = Read-Host "name of the cluster[type * to include all clusters]?" +Write-Host "TSM-SSH [SSH] options + 1. Enable TSM-SSH + 2. Disable TSM-SSH + 3. TSM-SSH Policy On + 4. TSM-SSH Policy Off + " -BackgroundColor White -ForegroundColor Blue #options to choose from + $a = Read-Host "Choose a number from 1 to 4" + +$stopWatch = [system.diagnostics.stopwatch]::startNew() +$stopWatch.Start() + + if ($a -eq 1) {get-cluster $cluster | get-vmhost | get-vmhostservice | where Key -EQ TSM-SSH | Start-VMHostService -Confirm:$false} + if ($a -eq 2) {get-cluster $cluster | get-vmhost | get-vmhostservice | where Key -EQ TSM-SSH | stop-VMHostService -Confirm:$false} + if ($a -eq 3) {get-cluster $cluster | get-vmhost | get-vmhostservice | where Key -EQ TSM-SSH | Set-VMHostService -Policy On -Confirm:$false} + if ($a -eq 4) {get-cluster $cluster | get-vmhost | get-vmhostservice | where Key -EQ TSM-SSH | Set-VMHostService -Policy Off -Confirm:$false} + +$stopWatch.Stop() +Write-Host "Elapsed Runtime:" $stopWatch.Elapsed.Hours "Hours" $stopWatch.Elapsed.Minutes "minutes and" $stopWatch.Elapsed.Seconds "seconds." -BackgroundColor White -ForegroundColor Black +#End of Script# +}#End of function + +#start of function +function Setxorg +{ +<# +.SYNOPSIS + Configure xorg [X.Org Server] +.DESCRIPTION + Depending upon the choice that you make + This will enable xorg. + This will disable xorg. + This will set xorg policy to On which will be persistent across reboot. + This will set xorg policy to Off which will be persistent across reboot. +.NOTES + File Name : Setxorg.ps1 + Author : gajendra d ambi + Date : March 2016 + Prerequisite : PowerShell v4+, powercli 6+ over win7 and upper. + Copyright - None +.LINK + Script posted over: github.com/gajuambi/vmware +#> +#Start of script# +$cluster = Read-Host "name of the cluster[type * to include all clusters]?" +Write-Host "xorg [X.Org Server] options + 1. Enable xorg + 2. Disable xorg + 3. xorg Policy On + 4. xorg Policy Off + " -BackgroundColor White -ForegroundColor Blue #options to choose from + $a = Read-Host "Choose a number from 1 to 4" + +$stopWatch = [system.diagnostics.stopwatch]::startNew() +$stopWatch.Start() + + if ($a -eq 1) {get-cluster $cluster | get-vmhost | get-vmhostservice | where Key -EQ xorg | Start-VMHostService -Confirm:$false} + if ($a -eq 2) {get-cluster $cluster | get-vmhost | get-vmhostservice | where Key -EQ xorg | stop-VMHostService -Confirm:$false} + if ($a -eq 3) {get-cluster $cluster | get-vmhost | get-vmhostservice | where Key -EQ xorg | Set-VMHostService -Policy On -Confirm:$false} + if ($a -eq 4) {get-cluster $cluster | get-vmhost | get-vmhostservice | where Key -EQ xorg | Set-VMHostService -Policy Off -Confirm:$false} + +$stopWatch.Stop() +Write-Host "Elapsed Runtime:" $stopWatch.Elapsed.Hours "Hours" $stopWatch.Elapsed.Minutes "minutes and" $stopWatch.Elapsed.Seconds "seconds." -BackgroundColor White -ForegroundColor Black +#End of Script# +}#End of function + +#start of function +function Setsnmpd +{ +<# +.SYNOPSIS + Configure snmpd [SNMP Server] +.DESCRIPTION + Depending upon the choice that you make + This will enable snmpd. + This will disable snmpd. + This will set snmpd policy to On which will be persistent across reboot. + This will set snmpd policy to Off which will be persistent across reboot. +.NOTES + File Name : Setsnmpd.ps1 + Author : gajendra d ambi + Date : March 2016 + Prerequisite : PowerShell v4+, powercli 6+ over win7 and upper. + Copyright - None +.LINK + Script posted over: github.com/gajuambi/vmware +#> +#Start of script# +$cluster = Read-Host "name of the cluster[type * to include all clusters]?" +Write-Host "snmpd [SNMP Server] options + 1. Enable snmpd + 2. Disable snmpd + 3. snmpd Policy On + 4. snmpd Policy Off + " -BackgroundColor White -ForegroundColor Blue #options to choose from + $a = Read-Host "Choose a number from 1 to 4" + +$stopWatch = [system.diagnostics.stopwatch]::startNew() +$stopWatch.Start() + + if ($a -eq 1) {get-cluster $cluster | get-vmhost | get-vmhostservice | where Key -EQ snmpd | Start-VMHostService -Confirm:$false} + if ($a -eq 2) {get-cluster $cluster | get-vmhost | get-vmhostservice | where Key -EQ snmpd | stop-VMHostService -Confirm:$false} + if ($a -eq 3) {get-cluster $cluster | get-vmhost | get-vmhostservice | where Key -EQ snmpd | Set-VMHostService -Policy On -Confirm:$false} + if ($a -eq 4) {get-cluster $cluster | get-vmhost | get-vmhostservice | where Key -EQ snmpd | Set-VMHostService -Policy Off -Confirm:$false} + +$stopWatch.Stop() +Write-Host "Elapsed Runtime:" $stopWatch.Elapsed.Hours "Hours" $stopWatch.Elapsed.Minutes "minutes and" $stopWatch.Elapsed.Seconds "seconds." -BackgroundColor White -ForegroundColor Black +#End of Script# +}#End of function + +#start of function +function SetDCUI +{ +<# +.SYNOPSIS + Configure DCUI [Direct Console UI] +.DESCRIPTION + Depending upon the choice that you make + This will enable DCUI. + This will disable DCUI. + This will set DCUI policy to On which will be persistent across reboot. + This will set DCUI policy to Off which will be persistent across reboot. +.NOTES + File Name : SetDCUI.ps1 + Author : gajendra d ambi + Date : March 2016 + Prerequisite : PowerShell v4+, powercli 6+ over win7 and upper. + Copyright - None +.LINK + Script posted over: github.com/gajuambi/vmware +#> +#Start of script# +$cluster = Read-Host "name of the cluster[type * to include all clusters]?" +Write-Host "DCUI [Direct Console UI] options + 1. Enable DCUI + 2. Disable DCUI + 3. DCUI Policy On + 4. DCUI Policy Off + " -BackgroundColor White -ForegroundColor Blue #options to choose from + $a = Read-Host "Choose a number from 1 to 4" + +$stopWatch = [system.diagnostics.stopwatch]::startNew() +$stopWatch.Start() + + if ($a -eq 1) {get-cluster $cluster | get-vmhost | get-vmhostservice | where Key -EQ DCUI | Start-VMHostService -Confirm:$false} + if ($a -eq 2) {get-cluster $cluster | get-vmhost | get-vmhostservice | where Key -EQ DCUI | stop-VMHostService -Confirm:$false} + if ($a -eq 3) {get-cluster $cluster | get-vmhost | get-vmhostservice | where Key -EQ DCUI | Set-VMHostService -Policy On -Confirm:$false} + if ($a -eq 4) {get-cluster $cluster | get-vmhost | get-vmhostservice | where Key -EQ DCUI | Set-VMHostService -Policy Off -Confirm:$false} + +$stopWatch.Stop() +Write-Host "Elapsed Runtime:" $stopWatch.Elapsed.Hours "Hours" $stopWatch.Elapsed.Minutes "minutes and" $stopWatch.Elapsed.Seconds "seconds." -BackgroundColor White -ForegroundColor Black +#End of Script# +}#End of function + +#start of function +function Setlbtd +{ +<# +.SYNOPSIS + Configure lbtd[Load-Based Teaming Daemon] +.DESCRIPTION + Depending upon the choice that you make + This will enable lbtd. + This will disable lbtd. + This will set lbtdpolicy to On which will be persistent across reboot. + This will set lbtdpolicy to Off which will be persistent across reboot. +.NOTES + File Name : SetLbtd.ps1 + Author : gajendra d ambi + Date : March 2016 + Prerequisite : PowerShell v4+, powercli 6+ over win7 and upper. + Copyright - None +.LINK + Script posted over: github.com/gajuambi/vmware +#> +#Start of script# +$cluster = Read-Host "name of the cluster[type * to include all clusters]?" +Write-Host "lbtd[Load-Based Teaming Daemon] options + 1. Enable lbtd + 2. Disable lbtd + 3. lbtdPolicy On + 4. lbtdPolicy Off + " -BackgroundColor White -ForegroundColor Blue #options to choose from + $a = Read-Host "Choose a number from 1 to 4" + +$stopWatch = [system.diagnostics.stopwatch]::startNew() +$stopWatch.Start() + + if ($a -eq 1) {get-cluster $cluster | get-vmhost | get-vmhostservice | where Key -EQ lbtd| Start-VMHostService -Confirm:$false} + if ($a -eq 2) {get-cluster $cluster | get-vmhost | get-vmhostservice | where Key -EQ lbtd| stop-VMHostService -Confirm:$false} + if ($a -eq 3) {get-cluster $cluster | get-vmhost | get-vmhostservice | where Key -EQ lbtd| Set-VMHostService -Policy On -Confirm:$false} + if ($a -eq 4) {get-cluster $cluster | get-vmhost | get-vmhostservice | where Key -EQ lbtd| Set-VMHostService -Policy Off -Confirm:$false} + +$stopWatch.Stop() +Write-Host "Elapsed Runtime:" $stopWatch.Elapsed.Hours "Hours" $stopWatch.Elapsed.Minutes "minutes and" $stopWatch.Elapsed.Seconds "seconds." -BackgroundColor White -ForegroundColor Black +#End of Script# +}#End of function + +#start of function +function VMotionOff +{ +<# +.SYNOPSIS + Enable vMotion +.DESCRIPTION + Enable vMotion across the Cluster +.NOTES + File Name : VMotionOff.ps1 + Author : gajendra d ambi + Date : Feb 2016 + recommended : PowerShell v4+, powercli 6+ over win7 and upper. + Copyright - None +.LINK + Script posted over: github.com/gajuambi/vmware +#> +#start of script +$cluster = Read-Host "name of the cluster[type * to include all clusters]?" +$pg = Read-Host "name of the portgroup?" + +$stopWatch = [system.diagnostics.stopwatch]::startNew() +$stopWatch.Start() + +Get-Cluster $cluster | Get-VMHost | Get-VMHostNetworkAdapter | where PortGroupname -EQ $pg | Set-VMHostNetworkAdapter -VMotionEnabled $false -Confirm:$false + +$stopWatch.Stop() +Write-Host "Elapsed Runtime:" $stopWatch.Elapsed.Hours "Hours" $stopWatch.Elapsed.Minutes "minutes and" $stopWatch.Elapsed.Seconds "seconds." -BackgroundColor White -ForegroundColor Black +#End of Script# +}#End of function + +#start of function +function VmotionOn +{ +<# +.SYNOPSIS + Enable vMotion +.DESCRIPTION + Enable vMotion across the Cluster +.NOTES + File Name : VmotionOn.ps1 + Author : gajendra d ambi + Date : Feb 2016 + recommended : PowerShell v4+, powercli 6+ over win7 and upper. + Copyright - None +.LINK + Script posted over: github.com/gajuambi/vmware +#> +#start of script +$cluster = Read-Host "name of the cluster[type * to include all clusters]?" +$pg = Read-Host "name of the portgroup?" + +$stopWatch = [system.diagnostics.stopwatch]::startNew() +$stopWatch.Start() + +Get-Cluster $cluster | Get-VMHost | Get-VMHostNetworkAdapter | where PortGroupname -EQ $pg | Set-VMHostNetworkAdapter -VMotionEnabled $true -Confirm:$false + +$stopWatch.Stop() +Write-Host "Elapsed Runtime:" $stopWatch.Elapsed.Hours "Hours" $stopWatch.Elapsed.Minutes "minutes and" $stopWatch.Elapsed.Seconds "seconds." -BackgroundColor White -ForegroundColor Black +#End of Script# +}#End of function + +#start of function +function FaultToleranceOn +{ +<# +.SYNOPSIS + Enable vMotion +.DESCRIPTION + Enable vMotion across the Cluster +.NOTES + File Name : FaultToleranceOn.ps1 + Author : gajendra d ambi + Date : Feb 2016 + recommended : PowerShell v4+, powercli 6+ over win7 and upper. + Copyright - None +.LINK + Script posted over: github.com/gajuambi/vmware +#> +#start of script +$cluster = Read-Host "name of the cluster[type * to include all clusters]?" +$pg = Read-Host "name of the portgroup?" + +$stopWatch = [system.diagnostics.stopwatch]::startNew() +$stopWatch.Start() + +Get-Cluster $cluster | Get-VMHost | Get-VMHostNetworkAdapter | where PortGroupname -EQ $pg | Set-VMHostNetworkAdapter -FaultToleranceLoggingEnabled $true -Confirm:$false + +$stopWatch.Stop() +Write-Host "Elapsed Runtime:" $stopWatch.Elapsed.Hours "Hours" $stopWatch.Elapsed.Minutes "minutes and" $stopWatch.Elapsed.Seconds "seconds." -BackgroundColor White -ForegroundColor Black +#End of Script# +}#End of function + +#start of function +function VsanTrafficOn +{ +<# +.SYNOPSIS + Enable VsanTrafficOn +.DESCRIPTION + Enable vMotion across the Cluster +.NOTES + File Name : VsanTrafficOn.ps1 + Author : gajendra d ambi + Date : Feb 2016 + recommended : PowerShell v4+, powercli 6+ over win7 and upper. + Copyright - None +.LINK + Script posted over: github.com/gajuambi/vmware +#> +#start of script +$cluster = Read-Host "name of the cluster[type * to include all clusters]?" +$pg = Read-Host "name of the portgroup?" + +$stopWatch = [system.diagnostics.stopwatch]::startNew() +$stopWatch.Start() + +Get-Cluster $cluster | Get-VMHost | Get-VMHostNetworkAdapter | where PortGroupname -EQ $pg | Set-VMHostNetworkAdapter -VsanTrafficEnabled $true -Confirm:$false + +$stopWatch.Stop() +Write-Host "Elapsed Runtime:" $stopWatch.Elapsed.Hours "Hours" $stopWatch.Elapsed.Minutes "minutes and" $stopWatch.Elapsed.Seconds "seconds." -BackgroundColor White -ForegroundColor Black +#End of Script# +}#End of function + +#start of function +function ManagementTrafficOn +{ +<# +.SYNOPSIS + Enable vMotion +.DESCRIPTION + Enable vMotion across the Cluster +.NOTES + File Name : ManagementTrafficOn.ps1 + Author : gajendra d ambi + Date : Feb 2016 + recommended : PowerShell v4+, powercli 6+ over win7 and upper. + Copyright - None +.LINK + Script posted over: github.com/gajuambi/vmware +#> +#start of script +$cluster = Read-Host "name of the cluster[type * to include all clusters]?" +$pg = Read-Host "name of the portgroup?" + +$stopWatch = [system.diagnostics.stopwatch]::startNew() +$stopWatch.Start() + +Get-Cluster $cluster | Get-VMHost | Get-VMHostNetworkAdapter | where PortGroupname -EQ $pg | Set-VMHostNetworkAdapter -ManagementTrafficEnabled $false -Confirm:$false +$stopWatch.Stop() +Write-Host "Elapsed Runtime:" $stopWatch.Elapsed.Hours "Hours" $stopWatch.Elapsed.Minutes "minutes and" $stopWatch.Elapsed.Seconds "seconds." -BackgroundColor White -ForegroundColor Black +#End of Script# +}#End of function + +#start of function +function ManagementTrafficOff +{ +<# +.SYNOPSIS + Enable vMotion +.DESCRIPTION + Enable vMotion across the Cluster +.NOTES + File Name : ManagementTrafficOff.ps1 + Author : gajendra d ambi + Date : Feb 2016 + recommended : PowerShell v4+, powercli 6+ over win7 and upper. + Copyright - None +.LINK + Script posted over: github.com/gajuambi/vmware +#> +#start of script +$cluster = Read-Host "name of the cluster[type * to include all clusters]?" +$pg = Read-Host "name of the portgroup?" + +$stopWatch = [system.diagnostics.stopwatch]::startNew() +$stopWatch.Start() + +Get-Cluster $cluster | Get-VMHost | Get-VMHostNetworkAdapter | where PortGroupname -EQ $pg | Set-VMHostNetworkAdapter -ManagementTrafficEnabled $false -Confirm:$false + +$stopWatch.Stop() +Write-Host "Elapsed Runtime:" $stopWatch.Elapsed.Hours "Hours" $stopWatch.Elapsed.Minutes "minutes and" $stopWatch.Elapsed.Seconds "seconds." -BackgroundColor White -ForegroundColor Black +#End of Script# +}#End of function + +#start of function +function ManagementTrafficOff +{ +<# +.SYNOPSIS + Enable vMotion +.DESCRIPTION + Enable vMotion across the Cluster +.NOTES + File Name : ManagementTrafficOff.ps1 + Author : gajendra d ambi + Date : Feb 2016 + recommended : PowerShell v4+, powercli 6+ over win7 and upper. + Copyright - None +.LINK + Script posted over: github.com/gajuambi/vmware +#> +#start of script +$cluster = Read-Host "name of the cluster[type * to include all clusters]?" +$pg = Read-Host "name of the portgroup?" + +$stopWatch = [system.diagnostics.stopwatch]::startNew() +$stopWatch.Start() + +Get-Cluster $cluster | Get-VMHost | Get-VMHostNetworkAdapter | where PortGroupname -EQ $pg | Set-VMHostNetworkAdapter -ManagementTrafficEnabled $false -Confirm:$false + +$stopWatch.Stop() +Write-Host "Elapsed Runtime:" $stopWatch.Elapsed.Hours "Hours" $stopWatch.Elapsed.Minutes "minutes and" $stopWatch.Elapsed.Seconds "seconds." -BackgroundColor White -ForegroundColor Black +#End of Script# +}#End of function + +#start of function +function VsanTrafficOff +{ +<# +.SYNOPSIS + Enable VsanTrafficOff +.DESCRIPTION + Enable vMotion across the Cluster +.NOTES + File Name : VsanTrafficOff.ps1 + Author : gajendra d ambi + Date : Feb 2016 + recommended : PowerShell v4+, powercli 6+ over win7 and upper. + Copyright - None +.LINK + Script posted over: github.com/gajuambi/vmware +#> +#start of script +$cluster = Read-Host "name of the cluster[type * to include all clusters]?" +$pg = Read-Host "name of the portgroup?" + +$stopWatch = [system.diagnostics.stopwatch]::startNew() +$stopWatch.Start() + +Get-Cluster $cluster | Get-VMHost | Get-VMHostNetworkAdapter | where PortGroupname -EQ $pg | Set-VMHostNetworkAdapter -VsanTrafficEnabled $false -Confirm:$false + +$stopWatch.Stop() +Write-Host "Elapsed Runtime:" $stopWatch.Elapsed.Hours "Hours" $stopWatch.Elapsed.Minutes "minutes and" $stopWatch.Elapsed.Seconds "seconds." -BackgroundColor White -ForegroundColor Black +#End of Script# +}#End of function + +#start of function +Function HostVds +{ +<# +.SYNOPSIS + Add Esxi host to distributed switch. +.DESCRIPTION + This will create a csv file whcih is opened in excel. Once you popuate the details, you have to save & close it. + Hit return/enter to proceed and the script will + add the esxi hosts to a chosen dvswitch. +.NOTES + File Name : HostVds.ps1 + Author : gajendra d ambi + Date : March 2016 + Prerequisite : PowerShell v4+, powercli 6+ over win7 and upper. + Copyright - None +.LINK + Script posted over: github.com/gajuambi/vmware +#> + +#Start of Script +Write-Host " +A CSV file will be opened (open in excel/spreadsheet) +populate the values, +save & close the file, +Hit Enter to proceed +" -ForegroundColor Blue -BackgroundColor White +$csv = "$PSScriptRoot/HostVds.csv" +get-process | Select-Object dvSwitch,hostname,vmnic | Export-Csv -Path $csv -Encoding ASCII -NoTypeInformation +Start-Process $csv +Read-Host "Hit Enter/Return to proceed" + +$stopWatch = [system.diagnostics.stopwatch]::startNew() +$stopWatch.Start() + +$csv = Import-Csv $csv + foreach ($line in $csv) + { + $dvs = $($line.dvSwitch) + $vmhost = $($line.hostname) + $vmnic = $($line.vmnic) + Get-VDSwitch -Name $dvs | Add-VDSwitchVMHost -VMHost $vmhost + $vmhostNetworkAdapter = Get-VMHost $vmhost | Get-VMHostNetworkAdapter -Physical -Name $vmnic + Get-VDSwitch $dvs | Add-VDSwitchPhysicalNetworkAdapter -VMHostNetworkAdapter $vmhostNetworkAdapter + } + +$stopWatch.Stop() +Write-Host "Elapsed Runtime:" $stopWatch.Elapsed.Hours "Hours" $stopWatch.Elapsed.Minutes "minutes and" $stopWatch.Elapsed.Seconds "seconds." -BackgroundColor White -ForegroundColor Black + #End of Script# +}#End of function + +#start of function +Function AddDpg +{ +<# +.SYNOPSIS + Add dvportgroups to a dvswitch. +.DESCRIPTION + This will create a csv file whcih is opened in excel. Once you popuate the details, you have to save & close it. + Hit return/enter to proceed and the script will + add the dvportgroups to a chosen dvswitch. +.NOTES + File Name : AddDpg.ps1 + Author : gajendra d ambi + Date : March 2016 + Prerequisite : PowerShell v4+, powercli 6+ over win7 and upper. + Copyright - None +.LINK + Script posted over: github.com/gajuambi/vmware +#> + +#Start of Script +Write-Host " +A CSV file will be opened (open in excel/spreadsheet) +populate the values, +save & close the file, +Hit Enter to proceed +" -ForegroundColor Blue -BackgroundColor White + +$stopWatch = [system.diagnostics.stopwatch]::startNew() +$stopWatch.Start() + +$csv = "$PSScriptRoot/AddDpg.csv" +get-process | Select-Object dvSwitch,dvPortgroup,VlanId,NumberOfPorts | Export-Csv -Path $csv -Encoding ASCII -NoTypeInformation +Start-Process $csv +Read-Host "Hit Enter/Return to proceed" + +$csv = Import-Csv $csv + foreach ($line in $csv) + { + $dvs = $($line.dvSwitch) + $dpg = $($line.dvPortgroup) + $vlan = $($line.VlanId) + $ports = $($line.NumberOfPorts) + Get-VDSwitch -Name $dvs | New-VDPortgroup -Name $dpg -VlanId $vlan -NumPorts $ports + } + +$stopWatch.Stop() +Write-Host "Elapsed Runtime:" $stopWatch.Elapsed.Hours "Hours" $stopWatch.Elapsed.Minutes "minutes and" $stopWatch.Elapsed.Seconds "seconds." -BackgroundColor White -ForegroundColor Black + #End of Script# +}#End of function + +#start of function +Function CreateVds +{ +<# +.SYNOPSIS + Create VDS. +.DESCRIPTION + This will create a vds on a chosen datacenter.. +.NOTES + File Name : CreateVds.ps1 + Author : gajendra d ambi + Date : March 2016 + Prerequisite : PowerShell v4+, powercli 6+ over win7 and upper. + Copyright - None +.LINK + Script posted over: github.com/gajuambi/vmware +#> +#Start of Script +$dc = Read-Host "name of the datacenter?" +$ul = Read-Host "number of uplinks?" +$dvs = Read-Host "name of the dvSwitch?" + +$stopWatch = [system.diagnostics.stopwatch]::startNew() +$stopWatch.Start() + +New-VDSwitch -Name $dvs -Location $dc -NumUplinkPorts $ul -Confirm:$false + +$stopWatch.Stop() +Write-Host "Elapsed Runtime:" $stopWatch.Elapsed.Hours "Hours" $stopWatch.Elapsed.Minutes "minutes and" $stopWatch.Elapsed.Seconds "seconds." -BackgroundColor White -ForegroundColor Black +#End of Script# +}#End of function + +#start of function +Function Setef +{ +<# +.SYNOPSIS + Set ExplicitFailover on VDS. +.DESCRIPTION + This will set the loadbalancing on the vds as ExplicitFailover. +.NOTES + File Name : Setef.ps1 + Author : gajendra d ambi + Date : March 2016 + Prerequisite : PowerShell v4+, powercli 6+ over win7 and upper. + Copyright - None +.LINK + Script posted over: github.com/gajuambi/vmware +#> +#Start of Script +$dvs = Read-Host "name of the dvSwitch?" + +$stopWatch = [system.diagnostics.stopwatch]::startNew() +$stopWatch.Start() + +Get-VDSwitch -Name $dvs | Get-VDUplinkTeamingPolicy | Set-VDUplinkTeamingPolicy -LoadBalancingPolicy ExplicitFailover -Confirm:$false + +$stopWatch.Stop() +Write-Host "Elapsed Runtime:" $stopWatch.Elapsed.Hours "Hours" $stopWatch.Elapsed.Minutes "minutes and" $stopWatch.Elapsed.Seconds "seconds." -BackgroundColor White -ForegroundColor Black + #End of Script# +}#End of function + +#start of function +Function Setlbsm +{ +<# +.SYNOPSIS + Set LoadBalanceSrcMac on VDS. +.DESCRIPTION + This will set the loadbalancing on the vds as LoadBalanceSrcMac. +.NOTES + File Name : Setlbsm.ps1 + Author : gajendra d ambi + Date : March 2016 + Prerequisite : PowerShell v4+, powercli 6+ over win7 and upper. + Copyright - None +.LINK + Script posted over: github.com/gajuambi/vmware +#> +#Start of Script +$dvs = Read-Host "name of the dvSwitch?" + +$stopWatch = [system.diagnostics.stopwatch]::startNew() +$stopWatch.Start() + +Get-VDSwitch -Name $dvs | Get-VDUplinkTeamingPolicy | Set-VDUplinkTeamingPolicy -LoadBalancingPolicy LoadBalanceSrcMac -Confirm:$false + +$stopWatch.Stop() +Write-Host "Elapsed Runtime:" $stopWatch.Elapsed.Hours "Hours" $stopWatch.Elapsed.Minutes "minutes and" $stopWatch.Elapsed.Seconds "seconds." -BackgroundColor White -ForegroundColor Black + #End of Script# +}#End of function + +#start of function +Function SetLbip +{ +<# +.SYNOPSIS + Set LoadBalanceIP on VDS. +.DESCRIPTION + This will set the loadbalancing on the vds as LoadBalanceIP. +.NOTES + File Name : SetLbip.ps1 + Author : gajendra d ambi + Date : March 2016 + Prerequisite : PowerShell v4+, powercli 6+ over win7 and upper. + Copyright - None +.LINK + Script posted over: github.com/gajuambi/vmware +#> +#Start of Script +$dvs = Read-Host "name of the dvSwitch?" + +$stopWatch = [system.diagnostics.stopwatch]::startNew() +$stopWatch.Start() + +Get-VDSwitch -Name $dvs | Get-VDUplinkTeamingPolicy | Set-VDUplinkTeamingPolicy -LoadBalancingPolicy LoadBalanceIP -Confirm:$false + +$stopWatch.Stop() +Write-Host "Elapsed Runtime:" $stopWatch.Elapsed.Hours "Hours" $stopWatch.Elapsed.Minutes "minutes and" $stopWatch.Elapsed.Seconds "seconds." -BackgroundColor White -ForegroundColor Black + #End of Script# +}#End of function + +#start of function +Function Setlbsi +{ +<# +.SYNOPSIS + Set LoadBalanceSrcId on VDS. +.DESCRIPTION + This will set the loadbalancing on the vds as LoadBalanceSrcId. +.NOTES + File Name : Setlbsi.ps1 + Author : gajendra d ambi + Date : March 2016 + Prerequisite : PowerShell v4+, powercli 6+ over win7 and upper. + Copyright - None +.LINK + Script posted over: github.com/gajuambi/vmware +#> +#Start of Script +$dvs = Read-Host "name of the dvSwitch?" + +$stopWatch = [system.diagnostics.stopwatch]::startNew() +$stopWatch.Start() + +Get-VDSwitch -Name $dvs | Get-VDUplinkTeamingPolicy | Set-VDUplinkTeamingPolicy -LoadBalancingPolicy LoadBalanceSrcId -Confirm:$false + +$stopWatch.Stop() +Write-Host "Elapsed Runtime:" $stopWatch.Elapsed.Hours "Hours" $stopWatch.Elapsed.Minutes "minutes and" $stopWatch.Elapsed.Seconds "seconds." -BackgroundColor White -ForegroundColor Black + #End of Script# +}#End of function + +#start of function +Function Setllb +{ +<# +.SYNOPSIS + Set LoadBalanceLoadBased on VDS. +.DESCRIPTION + This will set the loadbalancing on the vds as LoadBalanceLoadBased. +.NOTES + File Name : Setllb.ps1 + Author : gajendra d ambi + Date : March 2016 + Prerequisite : PowerShell v4+, powercli 6+ over win7 and upper. + Copyright - None +.LINK + Script posted over: github.com/gajuambi/vmware +#> +#Start of Script +$dvs = Read-Host "name of the dvSwitch?" + +$stopWatch = [system.diagnostics.stopwatch]::startNew() +$stopWatch.Start() + +Get-VDSwitch -Name $dvs | Get-VDUplinkTeamingPolicy | Set-VDUplinkTeamingPolicy -LoadBalancingPolicy LoadBalanceLoadBased -Confirm:$false + +$stopWatch.Stop() +Write-Host "Elapsed Runtime:" $stopWatch.Elapsed.Hours "Hours" $stopWatch.Elapsed.Minutes "minutes and" $stopWatch.Elapsed.Seconds "seconds." -BackgroundColor White -ForegroundColor Black + #End of Script# +}#End of function + +#start of function +function ShootVmkPg +{ +<# +.SYNOPSIS + Remove vmkernel portgroup +.DESCRIPTION + This will remove the virtual machine portgroup of all the hosts of a cluster/clusters. +.NOTES + File Name : ShootVmkPg.ps1 + Author : gajendra d ambi + Date : March 2016 + Prerequisite : PowerShell v4+, powercli 6+ over win7 and upper. + Copyright - None +.LINK + Script posted over: github.com/gajuambi/vmware +#> +#Start of Script +$cluster = Read-Host "name of the cluster[type * to include all clusters]?" +$pg = Read-Host "Name of the portgroup?" + foreach ($vmhost in (get-cluster $cluster | get-vmhost | sort)) + { + $vmk = Get-VMHostNetworkAdapter -VMHost $vmhost | where PortgroupName -eq $pg + Write-Host "removing vmkernel from the $pg on $vmhost" + Remove-VMHostNetworkAdapter -Nic $vmk -confirm:$false + + Write-Host "removing $pg on $vmhost" + get-vmhost $vmhost | get-virtualportgroup -Name $pg | Remove-VirtualPortGroup -Confirm:$false + }#End of Script +}#End of function + +#start of function +Function ShootVmPg +{ +<# +.SYNOPSIS + Remove virtual machine portgroup +.DESCRIPTION + This will remove the virtual machine portgroup of all the hosts of a cluster/clusters. +.NOTES + File Name : ShootVmPg.ps1 + Author : gajendra d ambi + Date : March 2016 + Prerequisite : PowerShell v4+, powercli 6+ over win7 and upper. + Copyright - None +.LINK + Script posted over: github.com/gajuambi/vmware +#> +#Start of Script +$cluster = Read-Host "name of the cluster[type * to include all clusters]?" +$pg = Read-Host "Name of the portgroup?" + +$stopWatch = [system.diagnostics.stopwatch]::startNew() +$stopWatch.Start() + +Get-cluster $cluster | Get-VMHost | Get-VirtualPortGroup -Name $pg | Remove-VirtualPortGroup -Confirm:$false + +$stopWatch.Stop() +Write-Host "Elapsed Runtime:" $stopWatch.Elapsed.Hours "Hours" $stopWatch.Elapsed.Minutes "minutes and" $stopWatch.Elapsed.Seconds "seconds." -BackgroundColor White -ForegroundColor Black + #End of Script# +}#End of function + +#start of function +Function Pglbip +{ +<# +.SYNOPSIS + update virtual machine portgroup's loadbalancing to LoadBalanceIP on vSwitch. +.DESCRIPTION + This will update virtual machine portgroup's loadbalancing to LoadBalanceIP on a chosen standard portgroup of hosts of a chosen cluster. +.NOTES + File Name : Pglbip.ps1 + Author : gajendra d ambi + Date : March 2016 + Prerequisite : PowerShell v4+, powercli 6+ over win7 and upper. + Copyright - None +.LINK + Script posted over: github.com/gajuambi/vmware +#> +#Start of Script +$cluster = Read-Host "name of the cluster[type * to include all clusters]?" +$pg = Read-Host "Name of the portgroup?" + +$stopWatch = [system.diagnostics.stopwatch]::startNew() +$stopWatch.Start() + +Get-cluster $cluster | Get-VMHost | Get-VirtualPortGroup -Name $pg | Get-NicTeamingPolicy | Set-NicTeamingPolicy -LoadBalancingPolicy LoadBalanceIP -Confirm:$false + +$stopWatch.Stop() +Write-Host "Elapsed Runtime:" $stopWatch.Elapsed.Hours "Hours" $stopWatch.Elapsed.Minutes "minutes and" $stopWatch.Elapsed.Seconds "seconds." -BackgroundColor White -ForegroundColor Black + #End of Script# +}#End of function + +#start of function +Function CreateVss +{ +<# +.SYNOPSIS + Create standard vSwitch. +.DESCRIPTION + This will create a standard vSwitch of hosts of a chosen cluster. +.NOTES + File Name : CreateVss.ps1 + Author : gajendra d ambi + Date : March 2016 + Prerequisite : PowerShell v4+, powercli 6+ over win7 and upper. + Copyright - None +.LINK + Script posted over: github.com/gajuambi/vmware +#> +#Start of Script +$cluster = Read-Host "name of the cluster[type * to include all clusters]?" +$vss = Read-Host "name of the vSphere standard Switch?" + +$stopWatch = [system.diagnostics.stopwatch]::startNew() +$stopWatch.Start() + +Get-Cluster $cluster | Get-VMHost | New-VirtualSwitch -Name $vss -Confirm:$false + +$stopWatch.Stop() +Write-Host "Elapsed Runtime:" $stopWatch.Elapsed.Hours "Hours" $stopWatch.Elapsed.Minutes "minutes and" $stopWatch.Elapsed.Seconds "seconds." -BackgroundColor White -ForegroundColor Black + #End of Script# +}#End of function + +#start of function +Function Pglbsi +{ +<# +.SYNOPSIS + update virtual machine portgroup's loadbalancing to LoadBalanceSrcId on vSwitch. +.DESCRIPTION + This will update virtual machine portgroup's loadbalancing to LoadBalanceSrcId on a chosen standard portgroup of hosts of a chosen cluster. +.NOTES + File Name : Pglbsi.ps1 + Author : gajendra d ambi + Date : March 2016 + Prerequisite : PowerShell v4+, powercli 6+ over win7 and upper. + Copyright - None +.LINK + Script posted over: github.com/gajuambi/vmware +#> +#Start of Script +$cluster = Read-Host "name of the cluster[type * to include all clusters]?" +$pg = Read-Host "Name of the portgroup?" + +$stopWatch = [system.diagnostics.stopwatch]::startNew() +$stopWatch.Start() + +Get-cluster $cluster | Get-VMHost | Get-VirtualPortGroup -Name $pg | Get-NicTeamingPolicy | Set-NicTeamingPolicy -LoadBalancingPolicy LoadBalanceSrcId -Confirm:$false + +$stopWatch.Stop() +Write-Host "Elapsed Runtime:" $stopWatch.Elapsed.Hours "Hours" $stopWatch.Elapsed.Minutes "minutes and" $stopWatch.Elapsed.Seconds "seconds." -BackgroundColor White -ForegroundColor Black + #End of Script# +}#End of function + +#start of function +Function Pglbsm +{ +<# +.SYNOPSIS + update virtual machine portgroup's loadbalancing to LoadBalanceSrcMac on vSwitch. +.DESCRIPTION + This will update virtual machine portgroup's loadbalancing to LoadBalanceSrcMac on a chosen standard portgroup of hosts of a chosen cluster. +.NOTES + File Name : Pglbsm.ps1 + Author : gajendra d ambi + Date : March 2016 + Prerequisite : PowerShell v4+, powercli 6+ over win7 and upper. + Copyright - None +.LINK + Script posted over: github.com/gajuambi/vmware +#> +#Start of Script +$cluster = Read-Host "name of the cluster[type * to include all clusters]?" +$pg = Read-Host "Name of the portgroup?" + +$stopWatch = [system.diagnostics.stopwatch]::startNew() +$stopWatch.Start() + +Get-cluster $cluster | Get-VMHost | Get-VirtualPortGroup -Name $pg | Get-NicTeamingPolicy | Set-NicTeamingPolicy -LoadBalancingPolicy LoadBalanceSrcMac -Confirm:$false + +$stopWatch.Stop() +Write-Host "Elapsed Runtime:" $stopWatch.Elapsed.Hours "Hours" $stopWatch.Elapsed.Minutes "minutes and" $stopWatch.Elapsed.Seconds "seconds." -BackgroundColor White -ForegroundColor Black + #End of Script# +}#End of function + +#start of function +Function PgVlan +{ +<# +.SYNOPSIS + update virtual machine portgroup's Vlan on vSwitch. +.DESCRIPTION + This will update virtual machine portgroup's Vlan on a chosen portgroup of hosts of a chosen cluster. +.NOTES + File Name : PgVlan.ps1 + Author : gajendra d ambi + Date : March 2016 + Prerequisite : PowerShell v4+, powercli 6+ over win7 and upper. + Copyright - None +.LINK + Script posted over: github.com/gajuambi/vmware +#> +#Start of Script +$cluster = Read-Host "name of the cluster[type * to include all clusters]?" +$pg = Read-Host "Name of the portgroup?" +$vlan = Read-Host "New Vlan?" + +$stopWatch = [system.diagnostics.stopwatch]::startNew() +$stopWatch.Start() + +Get-cluster $cluster | Get-VMHost | Get-VirtualPortGroup -Name $pg | Set-VirtualPortGroup -VLanId $vlan -Confirm:$false + +$stopWatch.Stop() +Write-Host "Elapsed Runtime:" $stopWatch.Elapsed.Hours "Hours" $stopWatch.Elapsed.Minutes "minutes and" $stopWatch.Elapsed.Seconds "seconds." -BackgroundColor White -ForegroundColor Black + #End of Script# +}#End of function + +#start of function +Function Pgef +{ +<# +.SYNOPSIS + update virtual machine portgroup's loadbalancing to ExplicitFailover on vSwitch. +.DESCRIPTION + This will update virtual machine portgroup's loadbalancing to ExplicitFailover on a chosen standard portgroup of hosts of a chosen cluster. +.NOTES + File Name : Pgef.ps1 + Author : gajendra d ambi + Date : March 2016 + Prerequisite : PowerShell v4+, powercli 6+ over win7 and upper. + Copyright - None +.LINK + Script posted over: github.com/gajuambi/vmware +#> +#Start of Script +$cluster = Read-Host "name of the cluster[type * to include all clusters]?" +$pg = Read-Host "Name of the portgroup?" + +$stopWatch = [system.diagnostics.stopwatch]::startNew() +$stopWatch.Start() + +Get-cluster $cluster | Get-VMHost | Get-VirtualPortGroup -Name $pg | Get-NicTeamingPolicy | Set-NicTeamingPolicy -LoadBalancingPolicy ExplicitFailover -Confirm:$false + +$stopWatch.Stop() +Write-Host "Elapsed Runtime:" $stopWatch.Elapsed.Hours "Hours" $stopWatch.Elapsed.Minutes "minutes and" $stopWatch.Elapsed.Seconds "seconds." -BackgroundColor White -ForegroundColor Black + #End of Script# +}#End of function + +#start of function +Function PgRename +{ +<# +.SYNOPSIS + update virtual machine portgroup's name on vSwitch. +.DESCRIPTION + This will update virtual machine portgroup's name on a chosen standard vSwitch of hosts of a chosen cluster. +.NOTES + File Name : PgRename.ps1 + Author : gajendra d ambi + Date : March 2016 + Prerequisite : PowerShell v4+, powercli 6+ over win7 and upper. + Copyright - None +.LINK + Script posted over: github.com/gajuambi/vmware +#> +#Start of Script +$cluster = Read-Host "name of the cluster[type * to include all clusters]?" +$oldpg = Read-Host "Old Name of the portgroup?" +$newpg = Read-Host "New Name of the portgroup?" + +$stopWatch = [system.diagnostics.stopwatch]::startNew() +$stopWatch.Start() + +Get-cluster $cluster | Get-VMHost | Get-VirtualPortGroup -Name $oldpg | Set-VirtualPortGroup -Name $newpg -Confirm:$false + +$stopWatch.Stop() +Write-Host "Elapsed Runtime:" $stopWatch.Elapsed.Hours "Hours" $stopWatch.Elapsed.Minutes "minutes and" $stopWatch.Elapsed.Seconds "seconds." -BackgroundColor White -ForegroundColor Black + #End of Script# +}#End of function + +#start of function +Function VssPmOn +{ +<# +.SYNOPSIS + Allow promiscous mode +.DESCRIPTION + This will allow promiscous mode on a vswitch. +.NOTES + File Name : VssPmOn.ps1 + Author : gajendra d ambi + Date : March 2016 + Prerequisite : PowerShell v4+, powercli 6+ over win7 and upper. + Copyright - None +.LINK + Script posted over: github.com/gajuambi/vmware +#> +#Start of Script +$cluster = Read-Host "name of the cluster[type * to include all clusters]?" +$vss = Read-Host "Name of the vSwitch?" + +$stopWatch = [system.diagnostics.stopwatch]::startNew() +$stopWatch.Start() + +Get-cluster $cluster | Get-VMHost | Get-VirtualSwitch -Name $vss | Get-SecurityPolicy | Set-SecurityPolicy -AllowPromiscuous $true -Confirm:$false + +$stopWatch.Stop() +Write-Host "Elapsed Runtime:" $stopWatch.Elapsed.Hours "Hours" $stopWatch.Elapsed.Minutes "minutes and" $stopWatch.Elapsed.Seconds "seconds." -BackgroundColor White -ForegroundColor Black + #End of Script# +}#End of function + +#start of function +Function VssPmOff +{ +<# +.SYNOPSIS + Allow promiscous mode +.DESCRIPTION + This will allow promiscous mode on a vswitch. +.NOTES + File Name : VssPmOff.ps1 + Author : gajendra d ambi + Date : March 2016 + Prerequisite : PowerShell v4+, powercli 6+ over win7 and upper. + Copyright - None +.LINK + Script posted over: github.com/gajuambi/vmware +#> +#Start of Script +$cluster = Read-Host "name of the cluster[type * to include all clusters]?" +$vss = Read-Host "Name of the vSwitch?" + +$stopWatch = [system.diagnostics.stopwatch]::startNew() +$stopWatch.Start() + +Get-cluster $cluster | Get-VMHost | Get-VirtualSwitch -Name $vss | Get-SecurityPolicy | Set-SecurityPolicy -AllowPromiscuous $false -Confirm:$false + +$stopWatch.Stop() +Write-Host "Elapsed Runtime:" $stopWatch.Elapsed.Hours "Hours" $stopWatch.Elapsed.Minutes "minutes and" $stopWatch.Elapsed.Seconds "seconds." -BackgroundColor White -ForegroundColor Black + #End of Script# +}#End of function + +#start of function +Function VssVmkPg +{ +<# +.SYNOPSIS + update vmkernel portgroup on vSwitch. +.DESCRIPTION + This will update vmkernel portgroup on a chosen standard vSwitch of hosts of a chosen cluster. +.NOTES + File Name : VssVmkPg.ps1 + Author : gajendra d ambi + Date : March 2016 + Prerequisite : PowerShell v4+, powercli 6+ over win7 and upper. + Copyright - None +.LINK + Script posted over: github.com/gajuambi/vmware +#> +#Start of Script +$cluster = Read-Host "name of the cluster[type * to include all clusters]?" +$vss = Read-Host "name of the vSphere standard Switch?" +$pg = Read-Host "Name of the portgroup?" +$vmk = Read-Host "vmk number? ex:- vmk9" +$ip = Read-Host "starting ip address?" +$mask = Read-Host "subnet mask" +$vlan = Read-Host "Vlan?" + +$stopWatch = [system.diagnostics.stopwatch]::startNew() +$stopWatch.Start() + +$a = $ip.Split('.')[0..2] + + #first 3 octets of the ip address + $b = [string]::Join(".",$a) + + #last octet of the ip address + $c = $ip.Split('.')[3] + $c = [int]$c + + foreach ($vmhost in (get-cluster $cluster | get-vmhost | sort)) { + get-vmhost $vmhost | get-virtualswitch -Name $vss | New-VirtualPortGroup -Name $pg -VLanId $vlan -Confirm:$false + $esxcli = get-vmhost $vmhost | Get-EsxCli + $esxcli.network.ip.interface.add($null, $null, "$vmk", $null, "1500", $null, "$pg") + $esxcli.network.ip.interface.ipv4.set("$vmk", "$b.$(($c++))", "$mask", $null, "static") + } + +$stopWatch.Stop() +Write-Host "Elapsed Runtime:" $stopWatch.Elapsed.Hours "Hours" $stopWatch.Elapsed.Minutes "minutes and" $stopWatch.Elapsed.Seconds "seconds." -BackgroundColor White -ForegroundColor Black + #End of Script# +}#End of function + +#start of function +Function VssPorts +{ +<# +.SYNOPSIS + update portgroups on vSwitch. +.DESCRIPTION + This will update portgroups on a chosen standard vSwitch of hosts of a chosen cluster. +.NOTES + File Name : VssPorts.ps1 + Author : gajendra d ambi + Date : March 2016 + Prerequisite : PowerShell v4+, powercli 6+ over win7 and upper. + Copyright - None +.LINK + Script posted over: github.com/gajuambi/vmware +#> +#Start of Script +$cluster = Read-Host "name of the cluster[type * to include all clusters]?" +$vss = Read-Host "name of the vSphere standard Switch?" +$ports = Read-Host "number of ports?" + +$stopWatch = [system.diagnostics.stopwatch]::startNew() +$stopWatch.Start() + +Get-Cluster $cluster | Get-VMHost | Get-VirtualSwitch -Name $vss | Set-VirtualSwitch -NumPorts $ports -Confirm:$false + +$stopWatch.Stop() +Write-Host "Elapsed Runtime:" $stopWatch.Elapsed.Hours "Hours" $stopWatch.Elapsed.Minutes "minutes and" $stopWatch.Elapsed.Seconds "seconds." -BackgroundColor White -ForegroundColor Black + #End of Script# +}#End of function + +#start of function +Function VssFtOff +{ +<# +.SYNOPSIS + Allow promiscous mode +.DESCRIPTION + This will allow promiscous mode on a vswitch. +.NOTES + File Name : VssFtOff.ps1 + Author : gajendra d ambi + Date : March 2016 + Prerequisite : PowerShell v4+, powercli 6+ over win7 and upper. + Copyright - None +.LINK + Script posted over: github.com/gajuambi/vmware +#> +#Start of Script +$cluster = Read-Host "name of the cluster[type * to include all clusters]?" +$vss = Read-Host "Name of the vSwitch?" + +$stopWatch = [system.diagnostics.stopwatch]::startNew() +$stopWatch.Start() + +Get-cluster $cluster | Get-VMHost | Get-VirtualSwitch -Name $vss | Get-SecurityPolicy | Set-SecurityPolicy -ForgedTransmits $false -Confirm:$false + +$stopWatch.Stop() +Write-Host "Elapsed Runtime:" $stopWatch.Elapsed.Hours "Hours" $stopWatch.Elapsed.Minutes "minutes and" $stopWatch.Elapsed.Seconds "seconds." -BackgroundColor White -ForegroundColor Black + #End of Script# +}#End of function + +#start of function +Function VssVmPg +{ +<# +.SYNOPSIS + update virtual machine portgroup on vSwitch. +.DESCRIPTION + This will update virtual machie portgroup on a chosen standard vSwitch of hosts of a chosen cluster. +.NOTES + File Name : VssVmPg.ps1 + Author : gajendra d ambi + Date : March 2016 + Prerequisite : PowerShell v4+, powercli 6+ over win7 and upper. + Copyright - None +.LINK + Script posted over: github.com/gajuambi/vmware +#> +#Start of Script +$cluster = Read-Host "name of the cluster[type * to include all clusters]?" +$vss = Read-Host "name of the vSphere standard Switch?" +$pg = Read-Host "Name of the portgroup?" +$vlan = read-host "VLAN?" + +$stopWatch = [system.diagnostics.stopwatch]::startNew() +$stopWatch.Start() + +Get-cluster $cluster | Get-VMHost | Get-VirtualSwitch -Name $vss | New-VirtualPortGroup -Name $pg -VLanId $vlan -Confirm:$false + +$stopWatch.Stop() +Write-Host "Elapsed Runtime:" $stopWatch.Elapsed.Hours "Hours" $stopWatch.Elapsed.Minutes "minutes and" $stopWatch.Elapsed.Seconds "seconds." -BackgroundColor White -ForegroundColor Black + #End of Script# +}#End of function + +#start of function +Function VssMcOff +{ +<# +.SYNOPSIS + Allow promiscous mode +.DESCRIPTION + This will allow promiscous mode on a vswitch. +.NOTES + File Name : VssMcOff.ps1 + Author : gajendra d ambi + Date : March 2016 + Prerequisite : PowerShell v4+, powercli 6+ over win7 and upper. + Copyright - None +.LINK + Script posted over: github.com/gajuambi/vmware +#> +#Start of Script +$cluster = Read-Host "name of the cluster[type * to include all clusters]?" +$vss = Read-Host "Name of the vSwitch?" + +$stopWatch = [system.diagnostics.stopwatch]::startNew() +$stopWatch.Start() + +Get-cluster $cluster | Get-VMHost | Get-VirtualSwitch -Name $vss | Get-SecurityPolicy | Set-SecurityPolicy -MacChanges $false -Confirm:$false + +$stopWatch.Stop() +Write-Host "Elapsed Runtime:" $stopWatch.Elapsed.Hours "Hours" $stopWatch.Elapsed.Minutes "minutes and" $stopWatch.Elapsed.Seconds "seconds." -BackgroundColor White -ForegroundColor Black + #End of Script# +}#End of function + +#start of function +Function VssMcOn +{ +<# +.SYNOPSIS + Allow promiscous mode +.DESCRIPTION + This will allow promiscous mode on a vswitch. +.NOTES + File Name : VssMcOn.ps1 + Author : gajendra d ambi + Date : March 2016 + Prerequisite : PowerShell v4+, powercli 6+ over win7 and upper. + Copyright - None +.LINK + Script posted over: github.com/gajuambi/vmware +#> +#Start of Script +$cluster = Read-Host "name of the cluster[type * to include all clusters]?" +$vss = Read-Host "Name of the vSwitch?" + +$stopWatch = [system.diagnostics.stopwatch]::startNew() +$stopWatch.Start() + +Get-cluster $cluster | Get-VMHost | Get-VirtualSwitch -Name $vss | Get-SecurityPolicy | Set-SecurityPolicy -MacChanges $true -Confirm:$false + +$stopWatch.Stop() +Write-Host "Elapsed Runtime:" $stopWatch.Elapsed.Hours "Hours" $stopWatch.Elapsed.Minutes "minutes and" $stopWatch.Elapsed.Seconds "seconds." -BackgroundColor White -ForegroundColor Black + #End of Script# +}#End of function + +#start of function +Function VssFtOn +{ +<# +.SYNOPSIS + Allow promiscous mode +.DESCRIPTION + This will allow promiscous mode on a vswitch. +.NOTES + File Name : VssFtOn.ps1 + Author : gajendra d ambi + Date : March 2016 + Prerequisite : PowerShell v4+, powercli 6+ over win7 and upper. + Copyright - None +.LINK + Script posted over: github.com/gajuambi/vmware +#> +#Start of Script +$cluster = Read-Host "name of the cluster[type * to include all clusters]?" +$vss = Read-Host "Name of the vSwitch?" + +$stopWatch = [system.diagnostics.stopwatch]::startNew() +$stopWatch.Start() + +Get-cluster $cluster | Get-VMHost | Get-VirtualSwitch -Name $vss | Get-SecurityPolicy | Set-SecurityPolicy -ForgedTransmits $true -Confirm:$false + +$stopWatch.Stop() +Write-Host "Elapsed Runtime:" $stopWatch.Elapsed.Hours "Hours" $stopWatch.Elapsed.Minutes "minutes and" $stopWatch.Elapsed.Seconds "seconds." -BackgroundColor White -ForegroundColor Black + #End of Script# +}#End of function + +#start of function +Function VssMtu +{ +<# +.SYNOPSIS + update Mtu on vSwitch. +.DESCRIPTION + This will update Mtu on a chosen standard vSwitch of hosts of a chosen cluster. +.NOTES + File Name : VssMtu.ps1 + Author : gajendra d ambi + Date : March 2016 + Prerequisite : PowerShell v4+, powercli 6+ over win7 and upper. + Copyright - None +.LINK + Script posted over: github.com/gajuambi/vmware +#> +#Start of Script +$cluster = Read-Host "name of the cluster[type * to include all clusters]?" +$vss = Read-Host "name of the vSphere standard Switch?" +$mtu = Read-Host "mtu?" + +$stopWatch = [system.diagnostics.stopwatch]::startNew() +$stopWatch.Start() + +Get-Cluster $cluster | get-vmhost | Get-Virtualswitch -Name $vss | Set-VirtualSwitch -Mtu $mtu -Confirm:$false + +$stopWatch.Stop() +Write-Host "Elapsed Runtime:" $stopWatch.Elapsed.Hours "Hours" $stopWatch.Elapsed.Minutes "minutes and" $stopWatch.Elapsed.Seconds "seconds." -BackgroundColor White -ForegroundColor Black + #End of Script# +}#End of function + +#------------------------------End of Collection of Functions of automation------------------------# + +#------------------------------Start of Collection of Menu Functions-------------------------------# + +#Start of NicMenu +function NicMenu +{ + do { + do { + Write-Host "`NicMenu" -BackgroundColor White -ForegroundColor Black + Write-Host " + A. vSwitch + B. portgroup + " #options to choose from + + Write-Host " + X. Previous Menu + Y. Main Menu + Z. Exit" -BackgroundColor Black -ForegroundColor Green #return to main menu + + $choice = Read-Host "choose one of the above" #Get user's entry + $ok = $choice -match '^[abxyz]+$' + if ( -not $ok) { write-host "Invalid selection" -BackgroundColor Red } + } until ( $ok ) + switch -Regex ($choice) + { + "A" { NicStatusVss } + "B" { NicStatusPg } + + "X" { vCenterMenu } + "Y" { MainMenu } + } + } until ( $choice -match "Z" ) +} #end of NicMenu + +#Start of StandHostsMenu +function StandHostsMenu +{ + do { + do { + Write-Host "`StandHostsMenu" -BackgroundColor White -ForegroundColor Black + Write-Host " + A. Connect to standalone hosts + B. Create virtual Standard Switch + C. Create virtual Machine Portgroup + D. Create VMkernel Portgroup + E. Rename Portgroups + F. Add Nics to vSwitch + G. Remove VM portgroup + H. Remove VMkernel portgroup" #options to choose from + + Write-Host " + X. Previous Menu + Y. Main Menu + Z. Exit" -BackgroundColor Black -ForegroundColor Green #return to main menu + + $choice = Read-Host "choose one of the above" #Get user's entry + $ok = $choice -match '^[abcdefghxyz]+$' + if ( -not $ok) { write-host "Invalid selection" -BackgroundColor Red } + } until ( $ok ) + switch -Regex ($choice) + { + "A" { shGetShHosts } + "B" { shNewVss } + "C" { shNewVMPg } + "D" { shNewVMkernelPg } + "E" { shRenamePg } + "F" { shAddNic } + "G" { shShootVmPg } + "H" { shShootVmkPg } + + "X" { vCenterMenu } + "Y" { MainMenu } + } + } until ( $choice -match "Z" ) +} +#end of StandHostsMenu + +#Start of vdsLoadBalancingMenu +function vdsLoadBalancingMenu +{ + do { + do { + Write-Host "Make sure you are connected to a vCenter" -ForegroundColor Yellow + Write-Host "`nvdsLoadBalancingMenu" -BackgroundColor White -ForegroundColor Black + Write-Host " + A. LoadBalanceIP + B. LoadBalanceLoadBased + C. LoadBalanceSrcMac + D. LoadBalanceSrcId + E. ExplicitFailover" #options to choose from + + Write-Host " + X. Previous Menu + Y. Main Menu + Z. Exit" -BackgroundColor Black -ForegroundColor Green #return to main menu + + $choice = Read-Host "choose one of the above" #Get user's entry + $ok = $choice -match '^[abcdexyz]+$' + if ( -not $ok) { write-host "Invalid selection" -BackgroundColor Red } + } until ( $ok ) + switch -Regex ($choice) + { + "A" { SetLbip } + "B" { Setllb } + "C" { Setlbsm } + "D" { Setlbsi } + "E" { Setef } + "X" { vdsMenu } + "Y" { MainMenu } + } + } until ( $choice -match "Z" ) +} +#end of vdsLoadBalancingMenu + +#Start of VMKservicesMenu +function VMKservicesMenu +{ + do { + do { + Write-Host "Make sure you are connected to a vCenter" -ForegroundColor Yellow + Write-Host "`nVMKservicesMenu" -BackgroundColor White -ForegroundColor Black + Write-Host " + A. Enable VMotion + B. Enable VsanTraffic + C. Enable FaultTolerance + D. Enable ManagementTraffic + E. Disable VMotion + F. Disable VsanTraffic + G. Disable FaultTolerance + H. Disable ManagementTraffic" #options to choose from + + Write-Host " + X. Previous Menu + Y. Main Menu + Z. Exit" -BackgroundColor Black -ForegroundColor Green #return to main menu + + $choice = Read-Host "choose one of the above" #Get user's entry + $ok = $choice -match '^[abcdefghxyz]+$' + if ( -not $ok) { write-host "Invalid selection" -BackgroundColor Red } + } until ( $ok ) + switch -Regex ($choice) + { + "A" { VmotionOn } + "B" { VsanTrafficOn } + "C" { FaultToleranceOn } + "D" { ManagementTrafficOn } + "E" { VMotionOff } + "F" { VsanTrafficOff } + "G" { FaultToleranceOff } + "H" { ManagementTrafficOff } + "X" { HostMenu } + "Y" { MainMenu } + } + } until ( $choice -match "Z" ) +} +#end of VMKservicesMenu + +#Start of vdsMenu +function vdsMenu +{ + do { + do { + Write-Host "Make sure you are connected to a vCenter" -ForegroundColor Yellow + Write-Host "`nvdsMenu" -BackgroundColor White -ForegroundColor Black + Write-Host " + A. Create VDS + B. Create dvPortgroup + C. Add hosts to VDS + D. Load balancing + E. (L3)TCP/IP stack" #options to choose from + + Write-Host " + X. Previous Menu + Y. Main Menu + Z. Exit" -BackgroundColor Black -ForegroundColor Green #return to main menu + + $choice = Read-Host "choose one of the above" #Get user's entry + $ok = $choice -match '^[abcdexyz]+$' + if ( -not $ok) { write-host "Invalid selection" -BackgroundColor Red } + } until ( $ok ) + switch -Regex ($choice) + { + "A" { CreateVds } + "B" { AddDpg } + "C" { HostVds } + "D" { vdsLoadBalancingMenu } + "E" { Write-Host This feature is not available yet } + "X" { vCenterMenu } + "Y" { MainMenu } + } + } until ( $choice -match "Z" ) +} +#end of vdsMenu + +#Start of VssMenu +Function VssMenu +{ + do { + do { + Write-Host -BackgroundColor White -ForegroundColor Black "`nVssMenu" + Write-Host " + A. Create vSwitch + B. Update NumPorts + C. Update Nic + D Update MTU + E. Create VM Portgroup + F. Create VMkernel Portgroup + G. Rename Portgroup + H. Update Portgroup's Vlan + I. LoadBalanceIP + J. LoadBalanceSrcMac + K. LoadBalanceSrcId + L. ExplicitFailover + M. Delete VM Portgroup + N. Enable AllowPromiscuous + O. Enable ForgedTransmits + P. Enable MacChanges + Q. Disable AllowPromiscuous + R. Disable ForgedTransmits + S. Disable MacChanges + T. Delete VMkernel Portgroup + U. Sync portgroup with vSwitch(inherit all properties of vswitch to portgroup) + V. L3 vMotion Portgroup + " #options to choose from... + + Write-Host " + X. Previous Menu + Y. Main Menu + Z. Exit + " -BackgroundColor White -ForegroundColor Black + + $user = [Environment]::UserName + $choice = Read-Host "choose one of the above" #Get user's entry + $ok = $choice -match '^[abcdefghijklmnopqrstuvxyz]+$' + if ( -not $ok) { write-host "Invalid selection" -BackgroundColor Red } + } until ( $ok ) + switch -Regex ($choice) + { + "A" { CreateVss } + "B" { VssPorts } + "C" { NicMenu } + "D" { VssMtu } + "E" { VssVmPg } + "F" { VssVmkPg } + "G" { PgRename } + "H" { PgVlan } + "I" { Pglbip } + "J" { Pglbsm } + "K" { Pglbsi } + "L" { Pgef } + "M" { ShootVmPg } + "N" { VssPmOn } + "O" { VssFtOn } + "P" { VssMcOn } + "Q" { VssPmOff } + "R" { VssFtOff } + "S" { VssMcOff } + "T" { ShootVmkPg } + "U" { PgSync } + "V" { l3vmotion } + "X" { vCenterMenu } + "Y" { MainMenu } + } + } until ( $choice -match "Z" ) +} #End of VssMenu + +#Start of MainMenu +function MainMenu +{ + do { + do { + $version = '2016Aug' + Write-Host -BackgroundColor Black -ForegroundColor Cyan "`nvTool $version" + Write-Host -BackgroundColor White -ForegroundColor Black "`nMain Menu" + Write-Host " + A. vCenter + B. Standalone Hosts" #options to choose from... + + write-host " + Z - Exit" -ForegroundColor Yellow #exits the script + + $user = [Environment]::UserName + $choice = Read-Host "Hi $user, choose one of the above" #Get user's entry + $ok = $choice -match '^[abz]+$' + if ( -not $ok) { write-host "Invalid selection" -BackgroundColor Red } + } until ( $ok ) + switch -Regex ($choice) + { + "A" { vCenterMenu } + "B" { StandHostsMenu } + } + } until ( $choice -match "Z" ) + #if ($choice -eq "z") { exit } +} +#end of MainMenu + +#Start of DrsRulesMenu +function DrsRulesMenu +{ + do { + do { + Write-Host "Make sure you are connected to a vCenter" -ForegroundColor Yellow + Write-Host "`nDrsRulesMenu" -BackgroundColor White -ForegroundColor Black + Write-Host " + A. VMAffinity + B. VMAntiAffinity + C. DrsVmGroup + D. DrsHostGroup + E. DRSVMToHostRule + " #options to choose from + + Write-Host " + X. Previous Menu + Y. Main Menu + Z. Exit" -BackgroundColor Black -ForegroundColor Green #return to main menu + + $choice = Read-Host "choose one of the above" #Get user's entry + $ok = $choice -match '^[abcdexyz]+$' + if ( -not $ok) { write-host "Invalid selection" -BackgroundColor Red } + } until ( $ok ) + switch -Regex ($choice) + { + "A" { VMAffinity } + "B" { VMAntiAffinity } + "C" { DrsVmGroup } + "D" { DrsHostGroup } + "E" { DRSVMToHostRule } + "X" { ClusterMenu } + "Y" { MainMenu } + } + } until ( $choice -match "Z" ) +} +#end of DrsRulesMenu + +#Start of ClusterMenu +function ClusterMenu +{ + do { + do { + Write-Host "Make sure you are connected to a vCenter" -ForegroundColor Yellow + Write-Host "`nClusterMenu" -BackgroundColor White -ForegroundColor Black + Write-Host " + A. Create Cluster + B. Add Hosts + C. Configure HA + D. Configure DRS + E. DRS rules + F. Create vApp + G. Add Datastores" #options to choose from + + Write-Host " + X. Previous Menu + Y. Main Menu + Z. Exit" -BackgroundColor Black -ForegroundColor Green #return to main menu + + $choice = Read-Host "choose one of the above" #Get user's entry + $ok = $choice -match '^[abcdefgxyz]+$' + if ( -not $ok) { write-host "Invalid selection" -BackgroundColor Red } + } until ( $ok ) + switch -Regex ($choice) + { + "A" { CreateCluster } + "B" { AddHosts } + "C" { ConfigHA } + "D" { ConfigDrs } + "E" { DrsRulesMenu } + "F" { CreateVapp } + "G" { AddDatastores } + "X" { vCenterMenu } + "Y" { MainMenu } + } + } until ( $choice -match "Z" ) +} +#end of ClusterMenu + +#Start of HostServicesMenu +function HostServicesMenu +{ + do { + do { + Write-Host "Make sure you are connected to a vCenter" -ForegroundColor Yellow + Write-Host "`nHostServicesMenu" -BackgroundColor White -ForegroundColor Black + Write-Host " + A. DCUI [Direct Console UI] + B. TSM [ESXi Shell] + C. TSM-SSH [SSH] + D. lbtd [Load-Based Teaming Daemon] + E. lwsmd [Active Directory Service] + F. ntpd [NTP Daemon] + G. pcscd [PC/SC Smart Card Daemon] + H. sfcbd-watchdog [CIM Server] + I. snmpd [SNMP Server] + J. vmsyslogd [Syslog Server] + K. vprobed [VProbe Daemon] + L. vpxa [VMware vCenter Agent] + M. xorg [X.Org Server] + " #options to choose from + + Write-Host " + X. Previous Menu + Y. Main Menu + Z. Exit" -BackgroundColor Black -ForegroundColor Green #return to main menu + + $choice = Read-Host "choose one of the above" #Get user's entry + $ok = $choice -match '^[abcdefghijklmxyz]+$' + if ( -not $ok) { write-host "Invalid selection" -BackgroundColor Red } + } until ( $ok ) + switch -Regex ($choice) + { + "A" { SetDCUI } + "B" { SetTSM } + "C" { SetSSH } + "D" { SetLbtd } + "E" { Setlwsmd } + "F" { Setntpd } + "G" { Setpcscd } + "H" { Setsfcbd } + "I" { Setsnmpd } + "J" { Setvmsyslogd } + "K" { Setvprobed } + "L" { Setvpxa } + "M" { Setxorg } + "X" { HostMenu } + "Y" { MainMenu } + } + } until ( $choice -match "Z" ) +} +#end of HostServicesMenu + +#Start of HostMenu +function HostMenu +{ + do { + do { + Write-Host "Make sure you are connected to a vCenter" -ForegroundColor Yellow + Write-Host "`nHostMenu" -BackgroundColor White -ForegroundColor Black + Write-Host " + A. SNMP + B. Syslog settings + C. DNS settings + D. NTP settings + E. Any Advanced setting + F. Firewall Settings + G. Scratch partition + H. Performance settings + I. Core dump settings + J. Power Management (shutdown, reboot, maintenance) + k. Enable/disable services + L. IPv6 + M. VMKernel Services + N. WinSSH (Run SSH commands on esxi from directly from windows) + + W. Others" #[Others menu is to include miscellaneous settings as per business needs] #options to choose from + + Write-Host " + X. Previous Menu + Y. Main Menu + Z. Exit" -BackgroundColor Black -ForegroundColor Green #return to main menu + + $choice = Read-Host "choose one of the above" #Get user's entry + $ok = $choice -match '^[abcdefghijklmnwxyz]+$' + if ( -not $ok) { write-host "Invalid selection" -BackgroundColor Red } + } until ( $ok ) + switch -Regex ($choice) + { + "A" { SetSnmp } + "B" { SetSyslog } + "C" { SetDNS } + "D" { SetNTP } + "E" { EsxiAdvanced } + "F" { SetFirewall } + "G" { SetScratch } + "H" { HostPerf } + "I" { CoreDump } + "J" { PowerMgmt } + "K" { HostServicesMenu } + "L" { SetIpv6 } + "M" { VMKservicesMenu } + "N" { WinSSH } + "W" { Write-Host you chose others. This is not implemented yet } + "X" { vCenterMenu } + "Y" { MainMenu } + } + } until ( $choice -match "Z" ) +} +#end of HostMenu + +#Start of vCenterMenu +function vCenterMenu +{ + do { + do { + Write-Host "Make sure you are connected to a vCenter" -ForegroundColor Yellow + Write-Host "`nvCenterMenu" -BackgroundColor White -ForegroundColor Black + Write-Host " + A. Cluster + B. Host + C. vSwitch + D. dvSwitch" #options to choose from + + Write-Host " + Y. Main Menu + Z. Exit" -BackgroundColor Black -ForegroundColor Green #return to main menu + + $choice = Read-Host "choose one of the above" #Get user's entry + $ok = $choice -match '^[abcdyz]+$' + if ( -not $ok) { write-host "Invalid selection" -BackgroundColor Red } + } until ( $ok ) + switch -Regex ($choice) + { + "A" { ClusterMenu } + "B" { HostMenu } + "C" { VssMenu } + "D" { vdsMenu } + "Y" { HostMenu } + } + } until ( $choice -match "Z" ) +} +#end of vCenterMenu + +#------------------------------End of Collection of Menu Functions-------------------------------# + +PcliPshell +MainMenu +##End of Script## From f301e6c05848161ac6f9015d3ea3d8f3433314fa Mon Sep 17 00:00:00 2001 From: mycloudrevolution Date: Sun, 25 Sep 2016 22:51:24 +0200 Subject: [PATCH 2/8] MaxIOPS and SCSI-UNMAP Two new Functions: - Report VM Disk IOPS of VMs - Process SCSI UNMAP on VMware Datastores --- Modules/Get-VMmaxIOPS.psm1 | 85 ++++++++++++++++++++++++++++++++ Modules/Start-UNMAP.psm1 | 99 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 184 insertions(+) create mode 100644 Modules/Get-VMmaxIOPS.psm1 create mode 100644 Modules/Start-UNMAP.psm1 diff --git a/Modules/Get-VMmaxIOPS.psm1 b/Modules/Get-VMmaxIOPS.psm1 new file mode 100644 index 0000000..8ef86e3 --- /dev/null +++ b/Modules/Get-VMmaxIOPS.psm1 @@ -0,0 +1,85 @@ +function Get-VMmaxIOPS { +<# + + .SYNOPSIS + Report VM Disk IOPS of VMs + + .DESCRIPTION + This Function will Create a VM Disk IOPS Report + + .Example + Get-VM TST* | Get-VMmaxIOPS -Minutes 60 | FT -Autosize + + .Example + $SampleVMs = Get-VM "TST*" + Get-VMmaxIOPS -VMs $SampleVMs -Minutes 60 + + .PARAMETER VMs + Specify the VMs + + .PARAMETER Minutes + Specify the Minutes to report (10080 is one Week) + + .Notes + NAME: Get-VMmaxIOPS.ps1 + LASTEDIT: 08/23/2016 + VERSION: 1.1 + KEYWORDS: VMware, vSphere, ESXi, IOPS + + .Link + http://mycloudrevolution.com/ + +#Requires PS -Version 4.0 +#Requires -Modules VMware.VimAutomation.Core, @{ModuleName="VMware.VimAutomation.Core";ModuleVersion="6.3.0.0"} +#> + +[CmdletBinding()] +param( + [Parameter(Mandatory=$true, ValueFromPipeline=$True, Position=0)] + [VMware.VimAutomation.ViCore.Impl.V1.Inventory.InventoryItemImpl[]] + $VMs, + [Parameter(Mandatory=$false, Position=1)] + [int] $Minutes = 30 +) + +Process { + + #region: Global Definitions + [int]$TimeRange = "-" + $Minutes + #endregion + + #region: Creating Metrics + Write-Debug "Starting to Create Metrics..." + $metrics = "virtualDisk.numberReadAveraged.average","virtualDisk.numberWriteAveraged.average" + $start = (Get-Date).AddMinutes($TimeRange) + $stats = Get-Stat -Stat $metrics -Entity $VMs -Start $start + #endregion + + #region: Creating HD-Tab + Write-Debug "Starting to Create HD-Tab..." + $hdTab = @{} + foreach($hd in (Get-Harddisk -VM $VMs)){ + $controllerKey = $hd.Extensiondata.ControllerKey + $controller = $hd.Parent.Extensiondata.Config.Hardware.Device | where{$_.Key -eq $controllerKey} + $hdTab[$hd.Parent.Name + "/scsi" + $controller.BusNumber + ":" + $hd.Extensiondata.UnitNumber] = $hd.FileName.Split(']')[0].TrimStart('[') + } + #endregion + + #region: Creating Reports + Write-Debug "Starting to Process IOPS Report..." + $reportPerf = @() + $reportPerf = $stats | Group-Object -Property {$_.Entity.Name},Instance | %{ + New-Object PSObject -Property @{ + VM = $_.Values[0] + Disk = $_.Values[1] + IOPSMax = ($_.Group | ` + Group-Object -Property Timestamp | ` + %{$_.Group[0].Value + $_.Group[1].Value} | ` + Measure-Object -Maximum).Maximum + Datastore = $hdTab[$_.Values[0] + "/"+ $_.Values[1]] + } + } + $reportPerf | Select-Object VM, Disk, Datastore, IOPSMax + #endregion + } +} \ No newline at end of file diff --git a/Modules/Start-UNMAP.psm1 b/Modules/Start-UNMAP.psm1 new file mode 100644 index 0000000..a8e9896 --- /dev/null +++ b/Modules/Start-UNMAP.psm1 @@ -0,0 +1,99 @@ +function Start-UNMAP { +<# + .SYNOPSIS + Process SCSI UNMAP on VMware Datastores + + .DESCRIPTION + This Function will process SCSI UNMAP on VMware Datastores via ESXCLI -V2 + + .Example + Start-UNMAP -ClusterName myCluster -DSWildcard *RAID5* + + .Example + Start-UNMAP -ClusterName myCluster -DSWildcard *RAID5* -Verbose -WhatIf + + .Notes + NAME: Start-UNMAP.psm1 + AUTHOR: Markus Kraus + LASTEDIT: 23.09.2016 + VERSION: 1.0 + KEYWORDS: VMware, vSphere, ESXi, SCSI, VAAI, UNMAP + + .Link + http://mycloudrevolution.com/ + + #Requires PS -Version 4.0 + #Requires -Modules VMware.VimAutomation.Core, @{ModuleName="VMware.VimAutomation.Core";ModuleVersion="6.3.0.0"} + #> + + [CmdletBinding(SupportsShouldProcess = $true,ConfirmImpact='High')] + param( + [Parameter(Mandatory=$true, Position=0)] + [String]$ClusterName, + [Parameter(Mandatory=$true, Position=1)] + [String]$DSWildcard + ) + Process { + $Validate = $true + #region: PowerCLI Session Timeout + Write-Verbose "Set Session Timeout ..." + $initialTimeout = (Get-PowerCLIConfiguration -Scope Session).WebOperationTimeoutSeconds + Set-PowerCLIConfiguration -Scope Session -WebOperationTimeoutSeconds -1 -Confirm:$False | Out-Null + #endregion + + #region: Get Cluster + $Cluster = Get-Cluster -Name $ClusterName -ErrorAction SilentlyContinue + Write-Verbose "vSphere Cluster: $Cluster" + if (!$Cluster){Write-Error "No Cluster found!"; $Validate = $false} + #endregion + + #region: Get Hosts + $ClusterHosts = $Cluster | Get-VMHost -ErrorAction SilentlyContinue | where {$_.ConnectionState -eq "Connected" -and $_.PowerState -eq "PoweredOn"} + Write-Verbose "vSphere Cluster Hosts: $ClusterHosts" + if (!$ClusterHosts){Write-Error "No Hosts found!"; $Validate = $false} + #endregion + + #region: Get Datastores + $ClusterDataStores = $Cluster | Get-Datastore -ErrorAction SilentlyContinue | where {$_.Name -like $DSWildcard -and $_.State -eq "Available" -and $_.Accessible -eq "True"} + Write-Verbose "vSphere Cluster Datastores: $ClusterDataStores" + if (!$ClusterDataStores){Write-Error "No Datastores found!"; $Validate = $false} + #endregion + + #region: Process Datastores + if ($Validate -eq $true) { + Write-Verbose "Starting Loop..." + foreach ($ClusterDataStore in $ClusterDataStores) { + Write-Verbose "vSphere Datastore to Process: $ClusterDataStore" + $myHost = $ClusterHosts[(Get-Random -Maximum ($ClusterHosts).count)] + Write-Verbose "vSphere Host to Process: $myHost" + $esxcli2 = $myHost | Get-ESXCLI -V2 + $arguments = $esxcli2.storage.vmfs.unmap.CreateArgs() + $arguments.volumelabel = $ClusterDataStore + $arguments.reclaimunit = "256" + if ($PSCmdlet.ShouldProcess( $ClusterDataStore,"Starting UNMAP on $myHost")) { + $stopwatch = [System.Diagnostics.Stopwatch]::StartNew() + try { + Write-Output "Starting UNMAP for $ClusterDataStore on $myHost..." + $esxcli2.storage.vmfs.unmap.Invoke($arguments) + } + catch { + Write-Output "A Error occured: " "" $error[0] "" + } + $stopwatch.Stop() + Write-Output "UNMAP duration: $($stopwatch.Elapsed.Minutes)" + } + + } + } + else { + Write-Error "Validation Failed. Processing Loop Skipped!" + } + #endregion + + #region: Revert PowerCLI Session Timeout + Write-Verbose "Revert Session Timeout ..." + Set-PowerCLIConfiguration -Scope Session -WebOperationTimeoutSeconds $initialTimeout -Confirm:$False | Out-Null + #endregion + } + +} From 15484d0af58f738fb4708209208c052e16d95499 Mon Sep 17 00:00:00 2001 From: mycloudrevolution Date: Tue, 22 Nov 2016 09:39:28 +0100 Subject: [PATCH 3/8] Base Version of VM Hardening Fuction Applys a set of Hardening options to your VMs --- Modules/apply-hardening.psm1 | 93 ++++++++++++++++++++++++++++++++++++ 1 file changed, 93 insertions(+) create mode 100644 Modules/apply-hardening.psm1 diff --git a/Modules/apply-hardening.psm1 b/Modules/apply-hardening.psm1 new file mode 100644 index 0000000..94b1279 --- /dev/null +++ b/Modules/apply-hardening.psm1 @@ -0,0 +1,93 @@ +function Apply-Hardening { +<# + .NOTES + =========================================================================== + Created by: Markus Kraus + Twitter: @VMarkus_K + Private Blog: mycloudrevolution.com + =========================================================================== + Changelog: + 2016.11 ver 2.0 Base Release + =========================================================================== + External Code Sources: + + =========================================================================== + Tested Against Environment: + vSphere Version: 5.5 U2 + PowerCLI Version: PowerCLI 6.3 R1, PowerCLI 6.5 R1 + PowerShell Version: 4.0, 5.0 + OS Version: Windows 8.1, Server 2012 R2 + Keyword: VM, Hardening, Security + =========================================================================== + + .DESCRIPTION + Applys a set of Hardening options to your VMs + + .Example + Get-VM TST* | Apply-Hardening + + .Example + $SampleVMs = Get-VM "TST*" + Apply-Hardening -VMs $SampleVMs + + .PARAMETER VMs + Specify the VMs + + +#Requires PS -Version 4.0 +#Requires -Modules VMware.VimAutomation.Core, @{ModuleName="VMware.VimAutomation.Core";ModuleVersion="6.3.0.0"} +#> + +[CmdletBinding()] +param( + [Parameter(Mandatory=$true, + ValueFromPipeline=$True, + Position=0)] + [VMware.VimAutomation.ViCore.Impl.V1.Inventory.InventoryItemImpl[]] + $VMs +) + +Process { +#region: Create Options + $ExtraOptions = @{ + "isolation.tools.diskShrink.disable"="true"; + "isolation.tools.diskWiper.disable"="true"; + "isolation.tools.copy.disable"="true"; + "isolation.tools.paste.disable"="true"; + "isolation.tools.dnd.disable"="true"; + "isolation.tools.setGUIOptions.enable"="false"; + "log.keepOld"="10"; + "log.rotateSize"="100000" + "RemoteDisplay.maxConnections"="2"; + "RemoteDisplay.vnc.enabled"="false"; + + } + if ($DebugPreference -eq "Inquire") { + Write-Output "VM Hardening Options:" + $ExtraOptions | Format-Table -AutoSize + } + + $VMConfigSpec = New-Object VMware.Vim.VirtualMachineConfigSpec + + Foreach ($Option in $ExtraOptions.GetEnumerator()) { + $OptionValue = New-Object VMware.Vim.optionvalue + $OptionValue.Key = $Option.Key + $OptionValue.Value = $Option.Value + $VMConfigSpec.extraconfig += $OptionValue + } +#endregion + +#region: Apply Options + ForEach ($VM in $VMs){ + $VMv = Get-VM $VM | Get-View + $state = $VMv.Summary.Runtime.PowerState + Write-Output "...Starting Reconfiguring VM: $VM " + $TaskConf = ($VMv).ReconfigVM_Task($VMConfigSpec) + if ($state -eq "poweredOn") { + Write-Output "...Migrating VM: $VM " + $TaskMig = $VMv.MigrateVM_Task($null, $_.Runtime.Host, 'highPriority', $null) + } + } + } +#endregion +} \ No newline at end of file From 99b1c6bb1ec4d6f288dbb95113df3dbbbc2493f8 Mon Sep 17 00:00:00 2001 From: mycloudrevolution Date: Wed, 30 Nov 2016 14:36:09 +0100 Subject: [PATCH 4/8] Set-CBT This Function enables or disables CBT. --- Modules/Set-CBT.psm1 | 111 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 111 insertions(+) create mode 100644 Modules/Set-CBT.psm1 diff --git a/Modules/Set-CBT.psm1 b/Modules/Set-CBT.psm1 new file mode 100644 index 0000000..784aebb --- /dev/null +++ b/Modules/Set-CBT.psm1 @@ -0,0 +1,111 @@ +function Set-CBT { +<# + .NOTES + =========================================================================== + Created by: Markus Kraus + Twitter: @VMarkus_K + Private Blog: mycloudrevolution.com + =========================================================================== + Changelog: + 2016.11 ver 1.0 Base Release + =========================================================================== + External Code Sources: + http://wahlnetwork.com/2015/12/01/change-block-tracking-cbt-powercli/ + =========================================================================== + Tested Against Environment: + vSphere Version: 5.5 U2 + PowerCLI Version: PowerCLI 6.3 R1 + PowerShell Version: 4.0 + OS Version: Windows Server 2012 R2 + =========================================================================== + Keywords vSphere, ESXi, VM, Storage, CBT, Backup + =========================================================================== + + .DESCRIPTION + This Function enables or disables CBT. + + .Example + Get-VN TST* | Set-CBT -DisableCBT + + .Example + Get-VN TST* | Set-CBT -EnableCBT + + .PARAMETER DisableCBT + Disables CBT for any VMs found with it enabled + + .PARAMETER EnableCBT + Enables CBT for any VMs found with it disabled + +#Requires PS -Version 4.0 +#Requires -Modules VMware.VimAutomation.Core, @{ModuleName="VMware.VimAutomation.Core";ModuleVersion="6.3.0.0"} +#> + + [CmdletBinding()] + param( + [Parameter(Mandatory=$True, ValueFromPipeline=$True, Position=0, HelpMessage = "VMs to process")] + [ValidateNotNullorEmpty()] + [VMware.VimAutomation.ViCore.Impl.V1.Inventory.InventoryItemImpl[]] $myVMs, + [Parameter(Mandatory = $False,ValueFromPipeline=$False, Position = 1, HelpMessage = "Enables CBT for any VMs found with it disabled", ParameterSetName = "EnableCBT")] + [ValidateNotNullorEmpty()] + [Switch]$EnableCBT, + [Parameter(Mandatory = $False,ValueFromPipeline=$False, Position = 1, HelpMessage = "Disables CBT for any VMs found with it enabled", ParameterSetName = "DisableCBT")] + [ValidateNotNullorEmpty()] + [Switch]$DisableCBT + ) +Process { + + $vmconfigspec = New-Object -TypeName VMware.Vim.VirtualMachineConfigSpec + Write-Verbose -Message "Walking through given VMs" + foreach($myVM in $myVMs) + { + if ($DisableCBT -and $myVM.ExtensionData.Config.ChangeTrackingEnabled -eq $true -and $myVM.ExtensionData.Snapshot -eq $null) + { + try + { + Write-Verbose -Message "Reconfiguring $($myVM.name) to disable CBT" -Verbose + $vmconfigspec.ChangeTrackingEnabled = $false + $myVM.ExtensionData.ReconfigVM($vmconfigspec) + + if ($myVM.PowerState -eq "PoweredOn" ) { + Write-Verbose -Message "Creating a snapshot on $($myVM.name) to clear CBT file" -Verbose + $SnapShot = New-Snapshot -VM $myVM -Name "CBT Cleanup" + + Write-Verbose -Message "Removing snapshot on $($myVM.name)" -Verbose + $SnapShot| Remove-Snapshot -Confirm:$false + } + + } + catch + { + throw $myVM + } + } + elseif ($EnableCBT -and $myVM.ExtensionData.Config.ChangeTrackingEnabled -eq $false -and $myVM.ExtensionData.Snapshot -eq $null) + { + Write-Verbose -Message "Reconfiguring $($myVM.name) to enable CBT" -Verbose + $vmconfigspec.ChangeTrackingEnabled = $true + $myVM.ExtensionData.ReconfigVM($vmconfigspec) + + if ($myVM.PowerState -eq "PoweredOn" ) { + Write-Verbose -Message "Creating a snapshot on $($myVM.name) to Create CBT file" -Verbose + $SnapShot = New-Snapshot -VM $myVM -Name "CBT Cleanup" + + Write-Verbose -Message "Removing snapshot on $($myVM.name)" -Verbose + $SnapShot | Remove-Snapshot -Confirm:$false + } + } + else + { + if ($myVM.ExtensionData.Snapshot -ne $null -and $EnableCBT) + { + Write-Warning -Message "Skipping $($myVM.name) - Snapshots found" + } + elseif ($myVM.ExtensionData.Snapshot -ne $null -and $DisableCBT) + { + Write-Warning -Message "Skipping $($myVM.name) - Snapshots found" + } + } + } + + } +} From 754f51326b9fae2fdfaf4f69e8e5b5f4ba1ad665 Mon Sep 17 00:00:00 2001 From: "Peter D. Jorgensen" Date: Wed, 30 Nov 2016 21:41:29 -0500 Subject: [PATCH 5/8] Add VMHost SSH management scripts Add scripts for enabling and disabling the TSM-SSH service on ESXi hosts. --- Scripts/Start-VMHostSsh.ps1 | 31 +++++++++++++++++++++++++++++++ Scripts/Stop-VMHostSsh.ps1 | 31 +++++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+) create mode 100644 Scripts/Start-VMHostSsh.ps1 create mode 100644 Scripts/Stop-VMHostSsh.ps1 diff --git a/Scripts/Start-VMHostSsh.ps1 b/Scripts/Start-VMHostSsh.ps1 new file mode 100644 index 0000000..9a0a84f --- /dev/null +++ b/Scripts/Start-VMHostSsh.ps1 @@ -0,0 +1,31 @@ +<# + .NOTES + =========================================================================== + Script name: Start-VMHostSsh.ps1 + Created on: 2016-07-01 + Author: Peter D. Jorgensen (@pjorg, pjorg.com) + Dependencies: None known + ===Tested Against Environment==== + vSphere Version: 5.5, 6.0 + PowerCLI Version: PowerCLI 6.5R1 + PowerShell Version: 5.0 + OS Version: Windows 10, Windows 7 + =========================================================================== + .DESCRIPTION + Starts the TSM-SSH service on VMHosts. + .Example + .\Start-VMHostSsh -VMHost (Get-VMHost -Name 'esxi-001.lab.local') + .Example + $OddHosts = Get-VMHost | ?{ $_.Name -match 'esxi-\d*[13579]+.\lab\.local' } + .\Start-VMHost -VMHost $OddHosts +#> +[CmdletBinding()] +Param( + [Parameter(ValueFromPipeline=$True,Mandatory=$True,Position=0)] + [VMware.VimAutomation.ViCore.Impl.V1.Inventory.VMHostImpl[]]$VMHost +) + +Process { + $svcSys = Get-View $VMHost.ExtensionData.ConfigManager.ServiceSystem + $svcSys.StartService('TSM-SSH') +} diff --git a/Scripts/Stop-VMHostSsh.ps1 b/Scripts/Stop-VMHostSsh.ps1 new file mode 100644 index 0000000..57541aa --- /dev/null +++ b/Scripts/Stop-VMHostSsh.ps1 @@ -0,0 +1,31 @@ +<# + .NOTES + =========================================================================== + Script name: Stop-VMHostSsh.ps1 + Created on: 2016-07-01 + Author: Peter D. Jorgensen (@pjorg, pjorg.com) + Dependencies: None known + ===Tested Against Environment==== + vSphere Version: 5.5, 6.0 + PowerCLI Version: PowerCLI 6.5R1 + PowerShell Version: 5.0 + OS Version: Windows 10, Windows 7 + =========================================================================== + .DESCRIPTION + Stops the TSM-SSH service on VMHosts. + .Example + .\Stop-VMHostSsh -VMHost (Get-VMHost -Name 'esxi-001.lab.local') + .Example + $EvenHosts = Get-VMHost | ?{ $_.Name -match 'esxi-\d*[02468]+.\lab\.local' } + .\Stop-VMHost -VMHost $EvenHosts +#> +[CmdletBinding()] +Param( + [Parameter(ValueFromPipeline=$True,Mandatory=$True,Position=0)] + [VMware.VimAutomation.ViCore.Impl.V1.Inventory.VMHostImpl[]]$VMHost +) + +Process { + $svcSys = Get-View $VMHost.ExtensionData.ConfigManager.ServiceSystem + $svcSys.StopService('TSM-SSH') +} From 147f97d0fa0861aa7961a08c4d117c95cb9a6db8 Mon Sep 17 00:00:00 2001 From: praveenmathamsetty Date: Fri, 2 Dec 2016 01:35:25 +0530 Subject: [PATCH 6/8] Kyle, Alan Review Comments Implementation Implemented below Items: 1) Formatting DesktopSummaryData/MachineNamesView 2) Example typo correction 3) Start,Stop, Enable and Disable tasks moved from Start to Set for both (Pool/Farm) 4) Internal functions Renaming 5) Start-HVPool --> Start-HVPool + Start-HVPoolSummary 6) Start-HVFarm --> Start-HVFarm + Start-HVFarmSummary 7) Plural function names to singular Not implemented review comment get-hvevent output to be (get-hvevents).Events To pipe events to CSV file via Export-Csv cmdlet, events should be PSCutomObject/PSObject. if we return only events, it will be hard user to export events to CSV. I will Implement rest of comments in next pull request. --- .../VMware.HV.Helper.format.ps1xml | 228 ++++++ .../VMware.Hv.Helper/VMware.HV.Helper.psd1 | 2 +- .../VMware.Hv.Helper/VMware.HV.Helper.psm1 | 747 +++++++++++------- 3 files changed, 704 insertions(+), 273 deletions(-) create mode 100644 Modules/VMware.Hv.Helper/VMware.HV.Helper.format.ps1xml diff --git a/Modules/VMware.Hv.Helper/VMware.HV.Helper.format.ps1xml b/Modules/VMware.Hv.Helper/VMware.HV.Helper.format.ps1xml new file mode 100644 index 0000000..dc4cca4 --- /dev/null +++ b/Modules/VMware.Hv.Helper/VMware.HV.Helper.format.ps1xml @@ -0,0 +1,228 @@ + + + + + VMware.HV.DesktopSummaryView + + VMware.HV.DesktopSummaryView + + + + + 12 + + + + 16 + + + + 12 + + + + 18 + + + + 16 + + + + 8 + + + + 10 + + Right + + + + + + + $_.desktopSummaryData.name + + + $_.desktopSummaryData.displayName + + + $_.desktopSummaryData.type + + + $_.desktopSummaryData.source + + + $_.desktopSummaryData.userAssignment + + + $_.desktopSummaryData.enabled + + + $_.desktopSummaryData.numSessions + + + + + + + + VMware.HV.DesktopSummaryViewList + + VMware.HV.DesktopSummaryView + + + + + + + + $_.desktopSummaryData.name + + + + $_.desktopSummaryData.displayName + + + + $_.desktopSummaryData.type + + + + $_.desktopSummaryData.source + + + + $_.desktopSummaryData.userAssignment + + + + $_.desktopSummaryData.enabled + + + + $_.desktopSummaryData.numSessions + + + + + + + + VMware.HV.MachineNamesView + + VMware.HV.MachineNamesView + + + + + 16 + + + + 16 + + + + 16 + + + + 16 + + + + 16 + + + + 8 + + + + 10 + + + + 10 + + Right + + + + + + + $_.Base.Name + + + $_.NamesData.desktopName + + + $_.Base.DnsName + + + $_.NamesData.UserName + + + $_.ManagedMachineNamesData.HostName + + + $_.Data.AgentVersion + + + $_.ManagedMachineNamesData.DatastorePaths + + + $_.Data.BasicState + + + + + + + + VMware.HV.MachineNamesViewList + + VMware.HV.MachineNamesView + + + + + + + + $_.Base.Name + + + + $_.NamesData.desktopName + + + + $_.Base.DnsName + + + + $_.NamesData.UserName + + + + $_.ManagedMachineNamesData.HostName + + + + $_.ManagedMachineNamesData.DatastorePaths + + + + $_.Data.BasicState + + + + + + + + \ No newline at end of file diff --git a/Modules/VMware.Hv.Helper/VMware.HV.Helper.psd1 b/Modules/VMware.Hv.Helper/VMware.HV.Helper.psd1 index 7d9e262..705cc80 100644 --- a/Modules/VMware.Hv.Helper/VMware.HV.Helper.psd1 +++ b/Modules/VMware.Hv.Helper/VMware.HV.Helper.psd1 @@ -60,7 +60,7 @@ RequiredModules = @('VMware.VimAutomation.HorizonView') # TypesToProcess = @() # Format files (.ps1xml) to be loaded when importing this module -# FormatsToProcess = @() +FormatsToProcess = @('VMware.HV.Helper.format.ps1xml') # Modules to import as nested modules of the module specified in RootModule/ModuleToProcess NestedModules = @('VMware.HV.Helper.psm1') diff --git a/Modules/VMware.Hv.Helper/VMware.HV.Helper.psm1 b/Modules/VMware.Hv.Helper/VMware.HV.Helper.psm1 index 3d533f5..c80d13f 100644 --- a/Modules/VMware.Hv.Helper/VMware.HV.Helper.psm1 +++ b/Modules/VMware.Hv.Helper/VMware.HV.Helper.psm1 @@ -21,8 +21,7 @@ #OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE #SOFTWARE. - -function Get_New_Object { +function Get-HVObject { param( [Parameter(Mandatory = $true)] [string]$TypeName, @@ -34,7 +33,7 @@ function Get_New_Object { return New-Object $objStr -Property $propertyName } -function Get_ViewAPI_Service { +function Get-ViewAPIService { param( [Parameter(Mandatory = $false)] $HvServer @@ -57,7 +56,7 @@ function Get_ViewAPI_Service { return $null } -function Get_Vcenter_ID { +function Get-VcenterID { param( [Parameter(Mandatory = $true)] $Services, @@ -86,7 +85,7 @@ function Get_Vcenter_ID { return $virtualCenterId } -function Get_Json_Object { +function Get-JsonObject { param( [Parameter(Mandatory = $true)] [string]$SpecFile @@ -98,7 +97,7 @@ function Get_Json_Object { } } -function Get_MapEntry { +function Get-MapEntry { param( [Parameter(Mandatory = $true)] $Key, @@ -113,7 +112,7 @@ function Get_MapEntry { return $update } -function Get-RegisteredPhysicalMachines ($Services,$MachinesList) { +function Get-RegisteredPhysicalMachine ($Services,$MachinesList) { [VMware.Hv.MachineId[]]$machines = $null $query_service_helper = New-Object VMware.Hv.QueryServiceService foreach ($machineName in $machinesList) { @@ -132,7 +131,7 @@ function Get-RegisteredPhysicalMachines ($Services,$MachinesList) { return $machines } -function Get-RegisteredRDSServers ($Services,$ServerList) { +function Get-RegisteredRDSServer ($Services,$ServerList) { [VMware.Hv.RDSServerId[]]$servers = $null $query_service_helper = New-Object VMware.Hv.QueryServiceService foreach ($serverName in $serverList) { @@ -153,6 +152,7 @@ function Get-RegisteredRDSServers ($Services,$ServerList) { } return $servers } + function Add-HVDesktop { <# .SYNOPSIS @@ -231,7 +231,7 @@ The Add-HVDesktop adds virtual machines to already exiting pools by using view A ) begin { - $services = Get_ViewAPI_Service -hvServer $hvServer + $services = Get-ViewAPIService -hvServer $hvServer if ($null -eq $services) { Write-Error "Could not retrieve ViewApi services from connection object" break @@ -240,7 +240,7 @@ The Add-HVDesktop adds virtual machines to already exiting pools by using view A process { try { - $desktopPool = Get-HVPool -poolName $poolName -hvServer $hvServer + $desktopPool = Get-HVPoolSummary -poolName $poolName -hvServer $hvServer } catch { Write-Error "Make sure Get-HVPool advanced function is loaded, $_" break @@ -270,7 +270,7 @@ The Add-HVDesktop adds virtual machines to already exiting pools by using view A $specifiedNames.vmName = $machine if ($userAssignment -eq $user_assignement_helper.USER_ASSIGNMENT_DEDICATED -and $users) { try { - $specifiedNames.user = Get_UserId -user $users[$cnt] + $specifiedNames.user = Get-UserId -user $users[$cnt] } catch { Write-Error "Unable to retrieve UserOrGroupId for user: [$users[$cnt]], $_" return @@ -283,13 +283,13 @@ The Add-HVDesktop adds virtual machines to already exiting pools by using view A } 'MANUAL' { if ($source -eq 'UNMANAGED') { - $machineList = Get-RegisteredPhysicalMachines -services $services -machinesList $machines + $machineList = Get-RegisteredPhysicalMachine -services $services -machinesList $machines if ($machineList.Length -eq 0) { Write-Error "Failed to retrieve registerd physical machines with the given machines parameter" return } } else { - $vcId = Get_Vcenter_ID -services $services -vCenter $vCenter + $vcId = Get-VcenterID -services $services -vCenter $vCenter $machineList = Get-MachinesByVCenter -machineList $machines -vcId $vcId if ($machineList.Length -eq 0) { Write-Error "Failed to get any Virtual Center machines with the given machines parameter" @@ -310,7 +310,7 @@ The Add-HVDesktop adds virtual machines to already exiting pools by using view A } } -function Get_UserId ($User) { +function Get-UserId ($User) { $defn = New-Object VMware.Hv.QueryDefinition $defn.queryEntityType = 'ADUserOrGroupSummaryView' @@ -399,7 +399,7 @@ function Add-HVRDSServer { ) begin { - $services = Get_ViewAPI_Service -hvServer $hvServer + $services = Get-ViewAPIService -hvServer $hvServer if ($null -eq $services) { Write-Error "Could not retrieve ViewApi services from connection object" break @@ -408,7 +408,7 @@ function Add-HVRDSServer { process { try { - $farmSpecObj = Get-HVFarm -farmName $farmName -hvServer $hvServer + $farmSpecObj = Get-HVFarmSummary -farmName $farmName -hvServer $hvServer } catch { Write-Error "Make sure Get-HVFarm advanced function is loaded, $_" break @@ -429,7 +429,7 @@ function Add-HVRDSServer { } 'MANUAL' { try { - $serverList = Get-RegisteredRDSServers -services $services -serverList $rdsServers + $serverList = Get-RegisteredRDSServer -services $services -serverList $rdsServers $farm_service_helper.Farm_AddRDSServers($services, $id, $serverList) } catch { Write-Error "Failed to Add RDS Server to Farm with error: $_" @@ -507,7 +507,7 @@ function Connect-HVEvent { begin { # Connect to Connection Server and call the View API service - $services = Get_ViewAPI_Service -hvServer $hvServer + $services = Get-ViewAPIService -hvServer $hvServer if ($null -eq $services) { Write-Error "Could not retrieve ViewApi services from connection object" break @@ -864,7 +864,7 @@ function Get-HVEvent { $adapter.SelectCommand = $command $DataTable = New-Object System.Data.DataTable - $adapter.Fill($DataTable) + $adapter.Fill($DataTable) | Out-Null Write-Host "Number of records found : " $DataTable.Rows.Count @@ -874,7 +874,6 @@ function Get-HVEvent { Foreach($row in $DataTable.Rows) { Write-Host $row[0] " " $row[1] " " $row[2] " " $row[3] " " $row[4] " " }#> - return New-Object pscustomobject -Property @{ Events = $DataTable; } } @@ -924,7 +923,7 @@ function Get-HVFarm { Get-HVFarm -FarmName 'Farm-01' -FarmType 'MANUAL' -Enabled $true .EXAMPLE - Get-HVFarm -FarmName 'Farm-01' -Full + Get-HVFarm -FarmName 'Farm-01' .OUTPUTs Returns the list of FarmSummaryView or FarmInfo object matching the query criteria. @@ -964,19 +963,121 @@ function Get-HVFarm { $Enabled, [Parameter(Mandatory = $false)] - [switch] - $Full, + $HvServer = $null + ) + + $services = Get-ViewAPIService -hvServer $hvServer + if ($null -eq $services) { + Write-Error "Could not retrieve ViewApi services from connection object" + break + } + $farmList = Find-HVFarm -Param $PSBoundParameters + $farm_service_helper = New-Object VMware.Hv.FarmService + $queryResults = @() + foreach ($id in $farmList.id) { + $info = $farm_service_helper.Farm_Get($services,$id) + $queryResults += $info + } + $farmList = $queryResults + return $farmList +} + +function Get-HVFarmSummary { +<# +.SYNOPSIS + This function is used to find farms based on the search criteria provided by the user. + +.DESCRIPTION + This function queries the specified Connection Server for farms which are configured on the server. If no farm is configured on the specified connection server or no farm matches the given search criteria, it will return null. + +.PARAMETER FarmName + farmName to be searched + +.PARAMETER FarmDisplayName + farmDisplayName to be searched + +.PARAMETER FarmType + farmType to be searched. It can take following values: + "AUTOMATED" - search for automated farms only + 'MANUAL' - search for manual farms only + +.PARAMETER Enabled + search for farms which are enabled + +.PARAMETER HvServer + Reference to Horizon View Server to query the data from. If the value is not passed or null then first element from global:DefaultHVServers would be considered inplace of hvServer. + +.EXAMPLE + Get-HVFarm -FarmName 'Farm-01' + +.EXAMPLE + Get-HVFarm -FarmName 'Farm-01' -FarmDisplayName 'Sales RDS Farm' + +.EXAMPLE + Get-HVFarm -FarmName 'Farm-01' -FarmType 'MANUAL' + +.EXAMPLE + Get-HVFarm -FarmName 'Farm-01' -FarmType 'MANUAL' -Enabled $true + +.EXAMPLE + Get-HVFarm -FarmName 'Farm-01' + +.OUTPUTs + Returns the list of FarmSummaryView or FarmInfo object matching the query criteria. + +.NOTES + Author : Praveen Mathamsetty. + Author email : pmathamsetty@vmware.com + Version : 1.0 + + ===Tested Against Environment==== + Horizon View Server Version : 7.0.2 + PowerCLI Version : PowerCLI 6.5 + PowerShell Version : 5.0 +#> + + [CmdletBinding( + SupportsShouldProcess = $true, + ConfirmImpact = 'High' + )] + + param( + [Parameter(Mandatory = $false)] + [string] + $FarmName, + + [Parameter(Mandatory = $false)] + [string] + $FarmDisplayName, + + [Parameter(Mandatory = $false)] + [ValidateSet('MANUAL','AUTOMATED')] + [string] + $FarmType, + + [Parameter(Mandatory = $false)] + [boolean] + $Enabled, [Parameter(Mandatory = $false)] $HvServer = $null ) - $services = Get_ViewAPI_Service -hvServer $hvServer + $services = Get-ViewAPIService -hvServer $hvServer if ($null -eq $services) { Write-Error "Could not retrieve ViewApi services from connection object" break } + $farmList = Find-HVFarm -Param $PSBoundParameters + return $farmList +} +function Find-HVFarm { + [CmdletBinding()] + param( + [Parameter(Mandatory = $true)] + $Param + ) # # This translates the function arguments into the View API properties that must be queried $farmSelectors = @{ @@ -986,7 +1087,7 @@ function Get-HVFarm { 'farmType' = 'data.type'; } - $parms = $psboundparameters + $parms = $Param $query_service_helper = New-Object VMware.Hv.QueryServiceService $query = New-Object VMware.Hv.QueryDefinition @@ -1011,16 +1112,8 @@ function Get-HVFarm { $queryResults = $query_service_helper.QueryService_Query($services, $query) $farmList = $queryResults.results - if ($full) { - $farm_service_helper = New-Object VMware.Hv.FarmService - $queryResults = @() - foreach ($id in $farmList.id) { - $info = $farm_service_helper.Farm_Get($services,$id) - $queryResults += $info - } - $farmList = $queryResults - } - return $farmList + + Return $farmList } function Get-HVPool { @@ -1063,10 +1156,6 @@ function Get-HVPool { If the value is true then only pools which are enabled would be returned. If the value is false then only pools which are disabled would be returned. -.PARAMETER Full - Switch to get full information about the pool. - Use this switch only when you require complete information about pool. - .PARAMETER HvServer Reference to Horizon View Server to query the pools from. If the value is not passed or null then first element from global:DefaultHVServers would be considered inplace of hvServer @@ -1075,7 +1164,7 @@ function Get-HVPool { Get-HVPool -PoolName 'mypool' -PoolType MANUAL -UserAssignment FLOATING -Enabled $true -ProvisioningEnabled $true .EXAMPLE - Get-HVPool -PoolType AUTOMATED -UserAssignment FLOATING -full + Get-HVPool -PoolType AUTOMATED -UserAssignment FLOATING .EXAMPLE Get-HVPool -PoolName 'myrds' -PoolType RDS -UserAssignment DEDICATED -Enabled $false @@ -1084,8 +1173,7 @@ function Get-HVPool { Get-HVPool -PoolName 'myrds' -PoolType RDS -UserAssignment DEDICATED -Enabled $false -HvServer $mycs .OUTPUTS - If switch -Full is used then returns list of DesktopSummaryView - else returns list of objects of type Desktop + Returns list of objects of type Desktop .NOTES Author : Praveen Mathamsetty. @@ -1131,20 +1219,147 @@ function Get-HVPool { $ProvisioningEnabled, [Parameter(Mandatory = $false)] - [switch] - $Full, + $HvServer = $null + ) + + $services = Get-ViewAPIService -hvServer $hvServer + if ($null -eq $services) { + Write-Error "Could not retrieve ViewApi services from connection object" + break + } + $poolList = Find-HVPool -Param $PSBoundParameters + $queryResults = @() + $desktop_helper = New-Object VMware.Hv.DesktopService + foreach ($id in $poolList.id) { + $info = $desktop_helper.Desktop_Get($services,$id) + $queryResults += $info + } + $poolList = $queryResults + return $poolList +} + +function Get-HVPoolSummary { +<# +.Synopsis + Gets pool summary with given search parameters. + +.DESCRIPTION + Queries and returns pools information, the pools list would be determined based on + queryable fields poolName, poolDisplayName, poolType, userAssignment, enabled, + provisioningEnabled. When more than one fields are used for query the pools which + satisfy all fields criteria would be returned. + +.PARAMETER PoolName + Pool name to query for. + If the value is null or not provided then filter will not be applied, + otherwise the pools which has name same as value will be returned. + +.PARAMETER PoolDisplayName + Pool display name to query for. + If the value is null or not provided then filter will not be applied, + otherwise the pools which has display name same as value will be returned. + +.PARAMETER PoolType + Pool type to filter with. + If the value is null or not provided then filter will not be applied. + If the value is MANUAL then only manual pools would be returned. + If the value is AUTOMATED then only automated pools would be returned + If the value is RDS then only Remote Desktop Service Pool pools would be returned + +.PARAMETER UserAssignment + User Assignment of pool to filter with. + If the value is null or not provided then filter will not be applied. + If the value is DEDICATED then only dedicated pools would be returned. + If the value is FLOATING then only floating pools would be returned + +.PARAMETER Enabled + Pool enablement to filter with. + If the value is not provided then then filter will not be applied. + If the value is true then only pools which are enabled would be returned. + If the value is false then only pools which are disabled would be returned. + +.PARAMETER HvServer + Reference to Horizon View Server to query the pools from. If the value is not passed or null then + first element from global:DefaultHVServers would be considered inplace of hvServer + +.EXAMPLE + Get-HVPoolSummary -PoolName 'mypool' -PoolType MANUAL -UserAssignment FLOATING -Enabled $true -ProvisioningEnabled $true + +.EXAMPLE + Get-HVPoolSummary -PoolType AUTOMATED -UserAssignment FLOATING + +.EXAMPLE + Get-HVPoolSummary -PoolName 'myrds' -PoolType RDS -UserAssignment DEDICATED -Enabled $false + +.EXAMPLE + Get-HVPoolSummary -PoolName 'myrds' -PoolType RDS -UserAssignment DEDICATED -Enabled $false -HvServer $mycs + +.OUTPUTS + Returns list of DesktopSummaryView + +.NOTES + Author : Praveen Mathamsetty. + Author email : pmathamsetty@vmware.com + Version : 1.0 + + ===Tested Against Environment==== + Horizon View Server Version : 7.0.2 + PowerCLI Version : PowerCLI 6.5 + PowerShell Version : 5.0 +#> + + [CmdletBinding( + SupportsShouldProcess = $true, + ConfirmImpact = 'High' + )] + + param( + [Parameter(Mandatory = $false)] + [string] + $PoolName, + + [Parameter(Mandatory = $false)] + [string] + $PoolDisplayName, + + [Parameter(Mandatory = $false)] + [ValidateSet('MANUAL','AUTOMATED','RDS')] + [string] + $PoolType, + + [Parameter(Mandatory = $false)] + [ValidateSet('FLOATING','DEDICATED')] + [string] + $UserAssignment, + + [Parameter(Mandatory = $false)] + [boolean] + $Enabled, + + [Parameter(Mandatory = $false)] + [boolean] + $ProvisioningEnabled, [Parameter(Mandatory = $false)] $HvServer = $null ) - $services = Get_ViewAPI_Service -hvServer $hvServer + $services = Get-ViewAPIService -hvServer $hvServer if ($null -eq $services) { Write-Error "Could not retrieve ViewApi services from connection object" break } + $poolList = Find-HVPool -Param $psboundparameters + Return $poolList +} + +function Find-HVPool { + [CmdletBinding()] + param( + [Parameter(Mandatory = $false)] + $Param + ) - # # This translates the function arguments into the View API properties that must be queried $poolSelectors = @{ 'poolName' = 'desktopSummaryData.name'; @@ -1155,7 +1370,7 @@ function Get-HVPool { 'provisioningEnabled' = 'desktopSummaryData.provisioningEnabled' } - $parms = $psboundparameters + $parms = $Param $query_service_helper = New-Object VMware.Hv.QueryServiceService $query = New-Object VMware.Hv.QueryDefinition @@ -1205,18 +1420,10 @@ function Get-HVPool { $scriptBlock = [Scriptblock]::Create($whereClause) $poolList = $queryResults.results | where $scriptBlock } - if ($full) { - $queryResults = @() - $desktop_helper = New-Object VMware.Hv.DesktopService - foreach ($id in $poolList.id) { - $info = $desktop_helper.Desktop_Get($services,$id) - $queryResults += $info - } - $poolList = $queryResults - } - return $poolList + Return $poolList } + function Get-HVQueryFilter { <# .Synopsis @@ -1359,7 +1566,7 @@ function Get-HVQueryFilter { } } process { - $queryFilter = Get_New_Object -typeName $switchToClassName[$PsCmdlet.ParameterSetName] + $queryFilter = Get-HVObject -typeName $switchToClassName[$PsCmdlet.ParameterSetName] switch ($PsCmdlet.ParameterSetName) { @@ -1473,7 +1680,7 @@ function Get-HVQueryResult { ) begin { - $services = Get_ViewAPI_Service -hvServer $hvServer + $services = Get-ViewAPIService -hvServer $hvServer if ($null -eq $services) { Write-Error "Could not retrieve ViewApi services from connection object" @@ -1831,7 +2038,7 @@ function New-HVFarm { # begin { - $services = Get_ViewAPI_Service -hvServer $hvServer + $services = Get-ViewAPIService -hvServer $hvServer if ($null -eq $services) { Write-Error "Could not retrieve ViewApi services from connection object" break @@ -1855,7 +2062,7 @@ function New-HVFarm { $farm_service_helper = New-Object VMware.Hv.FarmService if ($spec) { try { - $jsonObject = Get_Json_Object -specFile $spec + $jsonObject = Get-JsonObject -specFile $spec } catch { Write-Error "Json file exception, $_" break @@ -1911,7 +2118,7 @@ function New-HVFarm { $farmType = 'MANUAL' } - $script:farmSpecObj = Get_Farm_Spec -farmType $farmType -provisioningType $provisioningType -namingMethod $namingMethod + $script:farmSpecObj = Get-FarmSpec -farmType $farmType -provisioningType $provisioningType -namingMethod $namingMethod # # build out the infrastructure based on type of provisioning @@ -1921,7 +2128,7 @@ function New-HVFarm { 'MANUAL' { try { - $serverList = Get-RegisteredRDSServers -services $services -serverList $rdsServers + $serverList = Get-RegisteredRDSServer -services $services -serverList $rdsServers $farmSpecObj.ManualFarmSpec.RdsServers = $serverList } catch { $handleException = $true @@ -1941,7 +2148,7 @@ function New-HVFarm { # if (!$virtualCenterID) { - $virtualCenterID = Get_Vcenter_ID -services $services -vCenter $vCenter + $virtualCenterID = Get-VcenterID -services $services -vCenter $vCenter } if ($null -eq $virtualCenterID) { @@ -1977,11 +2184,11 @@ function New-HVFarm { # build the VM LIST # try { - $farmVirtualCenterProvisioningData = Build_VM_List_Farm -vc $virtualCenterID -vmObject $farmVirtualCenterProvisioningData + $farmVirtualCenterProvisioningData = Get-HVFarmProvisioningData -vc $virtualCenterID -vmObject $farmVirtualCenterProvisioningData $hostClusterId = $farmVirtualCenterProvisioningData.HostOrCluster - $farmVirtualCenterStorageSettings = Build_Datastore_List_Farm -hostclusterID $hostClusterId -storageObject $farmVirtualCenterStorageSettings - $farmVirtualCenterNetworkingSettings = Build_Network_List_Farm -networkObject $farmVirtualCenterNetworkingSettings - $farmCustomizationSettings = Build_Customization_Settings_Farm -vc $virtualCenterID -customObject $farmCustomizationSettings + $farmVirtualCenterStorageSettings = Get-HVFarmStorageObject -hostclusterID $hostClusterId -storageObject $farmVirtualCenterStorageSettings + $farmVirtualCenterNetworkingSettings = Get-HVFarmNetworkSetting -networkObject $farmVirtualCenterNetworkingSettings + $farmCustomizationSettings = Get-HVFarmCustomizationSetting -vc $virtualCenterID -customObject $farmCustomizationSettings } catch { $handleException = $true Write-Error "Failed to create Farm with error: $_" @@ -2051,7 +2258,7 @@ $myDebug | out-file -filepath c:\temp\copiedfarm.json } -function Build_VM_List_Farm { +function Get-HVFarmProvisioningData { param( [Parameter(Mandatory = $false)] [VMware.Hv.FarmVirtualCenterProvisioningData]$VmObject, @@ -2123,7 +2330,7 @@ function Build_VM_List_Farm { return $vmObject } -function Build_Datastore_List_Farm { +function Get-HVFarmStorageObject { param( [Parameter(Mandatory = $false)] [VMware.Hv.FarmVirtualCenterStorageSettings]$StorageObject, @@ -2167,7 +2374,7 @@ function Build_Datastore_List_Farm { return $storageObject } -function Build_Network_List_Farm { +function Get-HVFarmNetworkSetting { param( [Parameter(Mandatory = $false)] [VMware.Hv.FarmVirtualCenterNetworkingSettings]$NetworkObject @@ -2178,7 +2385,7 @@ function Build_Network_List_Farm { return $networkObject } -function Build_Customization_Settings_Farm { +function Get-HVFarmCustomizationSetting { param( [Parameter(Mandatory = $false)] [VMware.Hv.FarmCustomizationSettings]$CustomObject, @@ -2188,7 +2395,7 @@ function Build_Customization_Settings_Farm { ) if (!$customObject) { $ViewComposerDomainAdministrator_service_helper = New-Object VMware.Hv.ViewComposerDomainAdministratorService - $ViewComposerDomainAdministratorID = ($ViewComposerDomainAdministrator_service_helper.ViewComposerDomainAdministrator_List($services, $vcID) | Where-Object { $_.base.domain -cmatch $netBiosName }) + $ViewComposerDomainAdministratorID = ($ViewComposerDomainAdministrator_service_helper.ViewComposerDomainAdministrator_List($services, $vcID) | Where-Object { $_.base.domain -match $netBiosName }) if (! [string]::IsNullOrWhitespace($domainAdmin)) { $ViewComposerDomainAdministratorID = ($ViewComposerDomainAdministratorID | Where-Object { $_.base.userName -ieq $domainAdmin }).id } else { @@ -2229,7 +2436,7 @@ function Build_Customization_Settings_Farm { return $customObject } -function Get_Farm_Spec { +function Get-FarmSpec { param( [Parameter(Mandatory = $true)] [string]$FarmType, @@ -2842,7 +3049,7 @@ function New-HVPool { # begin { - $services = Get_ViewAPI_Service -hvServer $hvServer + $services = Get-ViewAPIService -hvServer $hvServer if ($null -eq $services) { Write-Error "Could not retrieve ViewApi services from connection object" break @@ -2853,7 +3060,7 @@ function New-HVPool { if ($poolName) { try { - $sourcePool = Get-HVPool -poolName $poolName -hvServer $hvServer + $sourcePool = Get-HVPoolSummary -poolName $poolName -hvServer $hvServer } catch { Write-Error "Make sure Get-HVPool advanced function is loaded, $_" break @@ -2866,7 +3073,7 @@ function New-HVPool { if ($spec) { try { - $jsonObject = Get_Json_Object -specFile $spec + $jsonObject = Get-JsonObject -specFile $spec } catch { Write-Error "Json file exception, $_" break @@ -2948,9 +3155,9 @@ function New-HVPool { if ($PSCmdlet.MyInvocation.ExpectingInput -or $clonePool) { if ($clonePool -and ($clonePool.GetType().name -eq 'DesktopSummaryView')) { - $clonePool = Get-HVPool -poolName $clonePool.desktopsummarydata.name -Full - } else { - Write-Error "In pipeline did not get object of expected type DesktopSummaryView" + $clonePool = Get-HVPool -poolName $clonePool.desktopsummarydata.name + } elseif (!($clonePool -and ($clonePool.GetType().name -eq 'DesktopInfo'))) { + Write-Error "In pipeline did not get object of expected type DesktopSummaryView/DesktopInfo" return } $poolType = $clonePool.type @@ -2991,7 +3198,7 @@ function New-HVPool { elseif ($RDS) { $poolType = 'RDS' } } - $script:desktopSpecObj = Get_Desktop_Spec -poolType $poolType -provisioningType $provisioningType -namingMethod $namingMethod + $script:desktopSpecObj = Get-HVDesktopSpec -poolType $poolType -provisioningType $provisioningType -namingMethod $namingMethod # # accumulate properties that are shared among various type @@ -3007,7 +3214,7 @@ function New-HVPool { if (! (($poolType -eq 'MANUAL') -and ($source -eq 'UNMANAGED'))) { if (!$virtualCenterID) { - $virtualCenterID = Get_Vcenter_ID -services $services -vCenter $vCenter + $virtualCenterID = Get-VcenterID -services $services -vCenter $vCenter } if ($null -eq $virtualCenterID) { $handleException = $true @@ -3079,7 +3286,7 @@ function New-HVPool { $desktopSpecObj.ManualDesktopSpec.VirtualCenter = $virtualCenterID } else { # Get Physical Regstered VMs - $machineList = Get-RegisteredPhysicalMachines -services $services -machinesList $VM + $machineList = Get-RegisteredPhysicalMachine -services $services -machinesList $VM } $desktopSpecObj.ManualDesktopSpec.Machines = $machineList } @@ -3123,11 +3330,11 @@ function New-HVPool { # $handleException = $false try { - $desktopVirtualCenterProvisioningData = Build_VM_List -vc $virtualCenterID -vmObject $desktopVirtualCenterProvisioningData + $desktopVirtualCenterProvisioningData = Get-HVPoolProvisioningData -vc $virtualCenterID -vmObject $desktopVirtualCenterProvisioningData $hostClusterId = $desktopVirtualCenterProvisioningData.HostOrCluster - $desktopVirtualCenterStorageSettings = Build_Datastore_List -hostclusterID $hostClusterId -storageObject $desktopVirtualCenterStorageSettings - $DesktopVirtualCenterNetworkingSettings = Build_Network_List -networkObject $DesktopVirtualCenterNetworkingSettings - $desktopCustomizationSettings = Build_Customization_Settings -vc $virtualCenterID -customObject $desktopCustomizationSettings + $desktopVirtualCenterStorageSettings = Get-HVPoolStorageObject -hostclusterID $hostClusterId -storageObject $desktopVirtualCenterStorageSettings + $DesktopVirtualCenterNetworkingSettings = Get-HVPoolNetworkSetting -networkObject $DesktopVirtualCenterNetworkingSettings + $desktopCustomizationSettings = Get-HVPoolCustomizationSetting -vc $virtualCenterID -customObject $desktopCustomizationSettings } catch { $handleException = $true Write-Error "Failed to create Pool with error: $_" @@ -3203,7 +3410,7 @@ function New-HVPool { } -function Build_VM_List { +function Get-HVPoolProvisioningData { param( [Parameter(Mandatory = $false)] [VMware.Hv.DesktopVirtualCenterProvisioningData]$VmObject, @@ -3284,7 +3491,7 @@ function Build_VM_List { return $vmObject } -function Build_Datastore_List { +function Get-HVPoolStorageObject { param( [Parameter(Mandatory = $false)] [VMware.Hv.DesktopVirtualCenterStorageSettings]$StorageObject, @@ -3335,7 +3542,7 @@ function Build_Datastore_List { return $storageObject } -function Build_Network_List { +function Get-HVPoolNetworkSetting { param( [Parameter(Mandatory = $false)] [VMware.Hv.DesktopVirtualCenterNetworkingSettings]$NetworkObject @@ -3346,7 +3553,7 @@ function Build_Network_List { return $networkObject } -function Build_Customization_Settings { +function Get-HVPoolCustomizationSetting { param( [Parameter(Mandatory = $false)] [VMware.Hv.DesktopCustomizationSettings]$CustomObject, @@ -3381,7 +3588,7 @@ function Build_Customization_Settings { if ($null -eq $instantCloneEngineDomainAdministrator) { throw "No Instant Clone Engine Domain Administrator found with netBiosName: [$netBiosName]" } - $desktopSpecObj.AutomatedDesktopSpec.CustomizationSettings.CloneprepCustomizationSettings = Get_CustomizationSettings_Objects + $desktopSpecObj.AutomatedDesktopSpec.CustomizationSettings.CloneprepCustomizationSettings = Get-CustomizationObject $desktopSpecObj.AutomatedDesktopSpec.CustomizationSettings.CloneprepCustomizationSettings.InstantCloneEngineDomainAdministrator = $instantCloneEngineDomainAdministrator } else { @@ -3398,7 +3605,7 @@ function Build_Customization_Settings { } if ($custType -eq 'SYS_PREP') { $desktopSpecObj.AutomatedDesktopSpec.CustomizationSettings.CustomizationType = 'SYS_PREP' - $desktopSpecObj.AutomatedDesktopSpec.CustomizationSettings.SysprepCustomizationSettings = Get_CustomizationSettings_Objects + $desktopSpecObj.AutomatedDesktopSpec.CustomizationSettings.SysprepCustomizationSettings = Get-CustomizationObject # Get SysPrep CustomizationSpec ID $customization_spec_helper = New-Object VMware.Hv.CustomizationSpecService @@ -3409,7 +3616,7 @@ function Build_Customization_Settings { $desktopSpecObj.AutomatedDesktopSpec.CustomizationSettings.SysprepCustomizationSettings.CustomizationSpec = $sysPrepIds[0].id } elseif ($custType -eq 'QUICK_PREP') { $desktopSpecObj.AutomatedDesktopSpec.CustomizationSettings.CustomizationType = 'QUICK_PREP' - $desktopSpecObj.AutomatedDesktopSpec.CustomizationSettings.QuickprepCustomizationSettings = Get_CustomizationSettings_Objects + $desktopSpecObj.AutomatedDesktopSpec.CustomizationSettings.QuickprepCustomizationSettings = Get-CustomizationObject } else { throw "The customization type: [$custType] is not supported for LinkedClone Pool" } @@ -3417,7 +3624,7 @@ function Build_Customization_Settings { } elseif ($FullClone) { if ($custType -eq 'SYS_PREP') { $desktopSpecObj.AutomatedDesktopSpec.CustomizationSettings.CustomizationType = 'SYS_PREP' - $desktopSpecObj.AutomatedDesktopSpec.CustomizationSettings.SysprepCustomizationSettings = Get_CustomizationSettings_Objects + $desktopSpecObj.AutomatedDesktopSpec.CustomizationSettings.SysprepCustomizationSettings = Get-CustomizationObject # Get SysPrep CustomizationSpec ID $customization_spec_helper = New-Object VMware.Hv.CustomizationSpecService $sysPrepIds = $customization_spec_helper.CustomizationSpec_List($services,$vcID) | Where-Object { $_.customizationSpecData.name -eq $sysPrepName } | Select-Object -Property id @@ -3426,7 +3633,7 @@ function Build_Customization_Settings { } $desktopSpecObj.AutomatedDesktopSpec.CustomizationSettings.SysprepCustomizationSettings.CustomizationSpec = $sysPrepIds[0].id } elseif ($custType -eq 'NONE') { - $desktopSpecObj.AutomatedDesktopSpec.CustomizationSettings.NoCustomizationSettings = Get_CustomizationSettings_Objects + $desktopSpecObj.AutomatedDesktopSpec.CustomizationSettings.NoCustomizationSettings = Get-CustomizationObject $desktopSpecObj.AutomatedDesktopSpec.CustomizationSettings.NoCustomizationSettings.DoNotPowerOnVMsAfterCreation = $false $desktopSpecObj.AutomatedDesktopSpec.CustomizationSettings.CustomizationType = "NONE" } else { @@ -3439,7 +3646,7 @@ function Build_Customization_Settings { return $customObject } -function Get_CustomizationSettings_Objects { +function Get-CustomizationObject { if ($InstantClone) { return New-Object VMware.Hv.DesktopCloneprepCustomizationSettings } elseif ($LinkedClone) { @@ -3457,7 +3664,7 @@ function Get_CustomizationSettings_Objects { } } -function Get_Desktop_Spec { +function Get-HVDesktopSpec { param( [Parameter(Mandatory = $true)] @@ -3551,7 +3758,7 @@ function Remove-HVFarm { ) begin { - $services = Get_ViewAPI_Service -hvServer $hvServer + $services = Get-ViewAPIService -hvServer $hvServer if ($null -eq $services) { Write-Error "Could not retrieve ViewApi services from connection object" break @@ -3668,7 +3875,7 @@ function Remove-HVPool { ) begin { - $services = Get_ViewAPI_Service -hvServer $hvServer + $services = Get-ViewAPIService -hvServer $hvServer if ($null -eq $services) { Write-Error "Could not retrieve ViewApi services from connection object" break @@ -3679,7 +3886,7 @@ function Remove-HVPool { $poolList = @() if ($poolName) { try { - $myPools = get-hvpool -poolName $poolName -hvServer $hvServer + $myPools = Get-HVPoolSummary -poolName $poolName -hvServer $hvServer } catch { Write-Error "Make sure Get-HVPool advanced function is loaded, $_" break @@ -3749,6 +3956,18 @@ function Set-HVFarm { .PARAMETER Farm Object(s) of the farm to edit. Object(s) should be of type FarmSummaryView/FarmInfo. +.PARAMETER Enable + Switch to enable the farm(s). + +.PARAMETER Disable + Switch to disable the farm(s). + +.PARAMETER Start + Switch to enable provisioning immediately for the farm(s). It's applicable only for 'AUTOMATED' farm type. + +.PARAMETER Stop + Switch to disable provisioning immediately for the farm(s). It's applicable only for 'AUTOMATED' farm type. + .PARAMETER Key Property names path separated by . (dot) from the root of desktop spec. @@ -3770,6 +3989,12 @@ function Set-HVFarm { .EXAMPLE $farm_array | Set-HVFarm -Key 'base.description' -Value 'updated description' +.EXAMPLE + Set-HVFarm -farm 'Farm2' -Start + +.EXAMPLE + Set-HVFarm -farm 'Farm2' -Enable + .OUTPUTS None @@ -3789,12 +4014,24 @@ function Set-HVFarm { ConfirmImpact = 'High' )] param( - [Parameter(Mandatory = $false,ParameterSetName = 'option')] + [Parameter(Mandatory = $true,ParameterSetName = 'option')] [string]$FarmName, [Parameter(ValueFromPipeline = $true,ParameterSetName = 'pipeline')] $Farm, + [Parameter(Mandatory = $false)] + [switch]$Enable, + + [Parameter(Mandatory = $false)] + [switch]$Disable, + + [Parameter(Mandatory = $false)] + [switch]$Start, + + [Parameter(Mandatory = $false)] + [switch]$Stop, + [Parameter(Mandatory = $false)] [string]$Key, @@ -3809,7 +4046,7 @@ function Set-HVFarm { ) begin { - $services = Get_ViewAPI_Service -hvServer $hvServer + $services = Get-ViewAPIService -hvServer $hvServer if ($null -eq $services) { Write-Error "Could not retrieve ViewApi services from connection object" break @@ -3820,13 +4057,17 @@ function Set-HVFarm { $farmList = @() if ($farmName) { try { - $farmSpecObj = Get-HVFarm -farmName $farmName -hvServer $hvServer + $farmSpecObj = Get-HVFarmSummary -farmName $farmName -hvServer $hvServer } catch { Write-Error "Make sure Get-HVFarm advanced function is loaded, $_" break } if ($farmSpecObj) { foreach ($farmObj in $farmSpecObj) { + if (($Start -or $Stop) -and ("AUTOMATED" -ne $farmObj.Data.Type)) { + Write-Error "Start/Stop operation is not supported for farm with name : [$farmObj.Data.Name]" + return + } $farmList += $farmObj.id } } else { @@ -3835,7 +4076,18 @@ function Set-HVFarm { } } elseif ($PSCmdlet.MyInvocation.ExpectingInput) { foreach ($item in $farm) { - if ($item.GetType().name -eq 'FarmInfo' -or $item.GetType().name -eq 'FarmSummaryView') { + if ($item.GetType().name -eq 'FarmSummaryView') { + if (($Start -or $Stop) -and ("AUTOMATED" -ne $item.Data.Type)) { + Write-Error "Start/Stop operation is not supported for farm with name : [$item.Data.Name]" + return + } + $farmList += $item.id + } + elseif ($item.GetType().name -eq 'FarmInfo') { + if (($Start -or $Stop) -and ("AUTOMATED" -ne $item.Type)) { + Write-Error "Start/Stop operation is not supported for farm with name : [$item.Data.Name]" + return + } $farmList += $item.id } else { @@ -3848,16 +4100,30 @@ function Set-HVFarm { $updates = @() if ($key -and $value) { - $updates += Get_MapEntry -key $key -value $value + $updates += Get-MapEntry -key $key -value $value } elseif ($key -or $value) { Write-Error "Both key:[$key] and value:[$value] need to be specified" } if ($spec) { - $specObject = Get_Json_Object -specFile $spec + $specObject = Get-JsonObject -specFile $spec foreach ($member in ($specObject.PSObject.Members | Where-Object { $_.MemberType -eq 'NoteProperty' })) { - $updates += Get_MapEntry -key $member.name -value $member.value + $updates += Get-MapEntry -key $member.name -value $member.value } } + if ($Enable) { + $updates += Get-MapEntry -key 'data.enabled' -value $true + } + elseif ($Disable) { + $updates += Get-MapEntry -key 'data.enabled' -value $false + } + elseif ($Start) { + $updates += Get-MapEntry -key 'automatedFarmData.virtualCenterProvisioningSettings.enableProvisioning' ` + -value $true + } + elseif ($Stop) { + $updates += Get-MapEntry -key 'automatedFarmData.virtualCenterProvisioningSettings.enableProvisioning' ` + -value $false + } $farm_service_helper = New-Object VMware.Hv.FarmService foreach ($item in $farmList) { $farm_service_helper.Farm_Update($services,$item,$updates) @@ -3884,6 +4150,18 @@ function Set-HVPool { .PARAMETER Pool Object(s) of the pool to edit. +.PARAMETER Enable + Switch parameter to enable the pool. + +.PARAMETER Disable + Switch parameter to disable the pool. + +.PARAMETER Start + Switch parameter to start the pool. + +.PARAMETER Stop + Switch parameter to stop the pool. + .PARAMETER Key Property names path separated by . (dot) from the root of desktop spec. @@ -3902,6 +4180,18 @@ function Set-HVPool { .EXAMPLE Set-HVPool -PoolName 'RDSPool' -Key 'base.description' -Value 'update description' +.Example + Set-HVPool -PoolName 'LnkClone' -Disable + +.Example + Set-HVPool -PoolName 'LnkClone' -Enable + +.Example + Set-HVPool -PoolName 'LnkClone' -Start + +.Example + Set-HVPool -PoolName 'LnkClone' -Stop + .OUTPUTS None @@ -3922,13 +4212,25 @@ function Set-HVPool { )] param( - [Parameter(Mandatory = $false,ParameterSetName = 'option')] + [Parameter(Mandatory = $true,ParameterSetName = 'option')] [string]$PoolName, #pool object [Parameter(ValueFromPipeline = $true,ParameterSetName = 'pipeline')] $Pool, + [Parameter(Mandatory = $false)] + [switch]$Enable, + + [Parameter(Mandatory = $false)] + [switch]$Disable, + + [Parameter(Mandatory = $false)] + [switch]$Start, + + [Parameter(Mandatory = $false)] + [switch]$Stop, + [Parameter(Mandatory = $false)] [string]$Key, @@ -3943,7 +4245,7 @@ function Set-HVPool { ) begin { - $services = Get_ViewAPI_Service -hvServer $hvServer + $services = Get-ViewAPIService -hvServer $hvServer if ($null -eq $services) { Write-Error "Could not retrieve ViewApi services from connection object" break @@ -3954,15 +4256,34 @@ function Set-HVPool { $poolList = @() if ($poolName) { try { - $desktopPools = Get-HVPool -poolName $poolName -hvServer $hvServer + $desktopPools = Get-HVPoolSummary -poolName $poolName -hvServer $hvServer } catch { Write-Error "Make sure Get-HVPool advanced function is loaded, $_" break } - if ($desktopPools) { $poolList += $desktopPools.id } + if ($desktopPools) { + foreach ($desktopObj in $desktopPools) { + if (($Start -or $Stop) -and ("AUTOMATED" -ne $item.DesktopSummaryData.Type)) { + Write-Error "Start/Stop operation is not supported for Poll with name : [$item.DesktopSummaryData.Name]" + return + } + $poolList += $desktopObj.id + } + } } elseif ($PSCmdlet.MyInvocation.ExpectingInput) { foreach ($item in $pool) { - if (($item.GetType().name -eq 'DesktopInfo') -or ($item.GetType().name -eq 'DesktopSummaryView')) { + if ($item.GetType().name -eq 'DesktopInfo') { + if (($Start -or $Stop) -and ("AUTOMATED" -ne $item.Type)) { + Write-Error "Start/Stop operation is not supported for Pool with name : [$item.Base.Name]" + return + } + $poolList += $item.id + } + elseif ($item.GetType().name -eq 'DesktopSummaryView') { + if (($Start -or $Stop) -and ("AUTOMATED" -ne $item.DesktopSummaryData.Type)) { + Write-Error "Start/Stop operation is not supported for Poll with name : [$item.DesktopSummaryData.Name]" + return + } $poolList += $item.id } else { @@ -3974,22 +4295,35 @@ function Set-HVPool { } $updates = @() if ($key -and $value) { - $updates += Get_MapEntry -key $key -value $value + $updates += Get-MapEntry -key $key -value $value } elseif ($key -or $value) { Write-Error "Both key:[$key] and value:[$value] needs to be specified" } if ($spec) { try { - $specObject = Get_Json_Object -specFile $spec + $specObject = Get-JsonObject -specFile $spec } catch { Write-Error "Json file exception, $_" return } foreach ($member in ($specObject.PSObject.Members | Where-Object { $_.MemberType -eq 'NoteProperty' })) { - $updates += Get_MapEntry -key $member.name -value $member.value + $updates += Get-MapEntry -key $member.name -value $member.value } } - + if ($Enable) { + $updates += Get-MapEntry -key 'desktopSettings.enabled' -value $true + } + elseif ($Disable) { + $updates += Get-MapEntry -key 'desktopSettings.enabled' -value $false + } + elseif ($Start) { + $updates += Get-MapEntry -key 'automatedDesktopData.virtualCenterProvisioningSettings.enableProvisioning' ` + -value $true + } + elseif ($Stop) { + $updates += Get-MapEntry -key 'automatedDesktopData.virtualCenterProvisioningSettings.enableProvisioning' ` + -value $false + } $desktop_helper = New-Object VMware.Hv.DesktopService foreach ($item in $poolList) { $desktop_helper.Desktop_Update($services,$item,$updates) @@ -4012,18 +4346,6 @@ function Start-HVFarm { .PARAMETER Farm Name/Object(s) of the farm. Object(s) should be of type FarmSummaryView/FarmInfo. -.PARAMETER Enable - Switch to enable the farm(s). - -.PARAMETER Disable - Switch to disable the farm(s). - -.PARAMETER Start - Switch to enable provisioning immediately for the farm(s). It's applicable only for 'AUTOMATED' farm type. - -.PARAMETER Stop - Switch to disable provisioning immediately for the farm(s). It's applicable only for 'AUTOMATED' farm type. - .PARAMETER Recompose Switch for recompose operation. Requests a recompose of RDS Servers in the specified 'AUTOMATED' farm. This marks the RDS Servers for recompose, which is performed asynchronously. @@ -4056,18 +4378,6 @@ function Start-HVFarm { .EXAMPLE Start-HVFarm -Recompose -Farm 'Farm-01' -LogoffSetting FORCE_LOGOFF -ParentVM 'View-Agent-Win8' -SnapshotVM 'Snap_USB' -.EXAMPLE - Start-HVFarm -Farm 'Farm-01' -Enable - -.EXAMPLE - Start-HVFarm -Farm 'Farm-01' -Disable - -.EXAMPLE - Start-HVFarm -Farm 'Farm-01' -Start - -.EXAMPLE - Start-HVFarm -Farm 'Farm-01' -Stop - .EXAMPLE $myTime = Get-Date '10/03/2016 12:30:00' Start-HVFarm -Farm 'Farm-01' -Recompose -LogoffSetting 'FORCE_LOGOFF' -ParentVM 'ParentVM' -SnapshotVM 'SnapshotVM' -StartTime $myTime @@ -4094,18 +4404,6 @@ function Start-HVFarm { [Parameter(Mandatory = $true,ValueFromPipeline = $true)] $Farm, - [Parameter(Mandatory = $false,ParameterSetName = 'ENABLE')] - [switch]$Enable, - - [Parameter(Mandatory = $false,ParameterSetName = 'DISABLE')] - [switch]$Disable, - - [Parameter(Mandatory = $false,ParameterSetName = 'START')] - [switch]$Start, - - [Parameter(Mandatory = $false,ParameterSetName = 'STOP')] - [switch]$Stop, - [Parameter(Mandatory = $false,ParameterSetName = 'RECOMPOSE')] [switch]$Recompose, @@ -4136,7 +4434,7 @@ function Start-HVFarm { ) begin { - $services = Get_ViewAPI_Service -hvServer $hvServer + $services = Get-ViewAPIService -hvServer $hvServer if ($null -eq $services) { Write-Error "Could not retrieve ViewApi services from connection object" break @@ -4198,7 +4496,7 @@ function Start-HVFarm { Write-Error "RECOMPOSE operation is not supported for farm with name [$farmList.$item]" break } else { - $vcId = Get_Vcenter_ID -services $services -vCenter $vCenter + $vcId = Get-VcenterID -services $services -vCenter $vCenter if ($null -eq $vcId) { break } @@ -4211,7 +4509,7 @@ function Start-HVFarm { $spec.StopOnFirstError = $stopOnFirstError $spec.RdsServers = $serverList try { - $spec = Set_Spec_Vms_Farm -vcId $vcId -spec $spec + $spec = Set-HVFarmSpec -vcId $vcId -spec $spec } catch { Write-Error "RECOMPOSE task failed with error: $_" break @@ -4219,47 +4517,13 @@ function Start-HVFarm { if ($startTime) { $spec.startTime = $startTime } # Update Base Image VM and Snapshot in Farm $updates = @() - $updates += Get_MapEntry -key 'automatedFarmData.virtualCenterProvisioningSettings.virtualCenterProvisioningData.parentVm' -value $spec.ParentVM - $updates += Get_MapEntry -key 'automatedFarmData.virtualCenterProvisioningSettings.virtualCenterProvisioningData.snapshot' -value $spec.Snapshot + $updates += Get-MapEntry -key 'automatedFarmData.virtualCenterProvisioningSettings.virtualCenterProvisioningData.parentVm' -value $spec.ParentVM + $updates += Get-MapEntry -key 'automatedFarmData.virtualCenterProvisioningSettings.virtualCenterProvisioningData.snapshot' -value $spec.Snapshot $farm_service_helper.Farm_Update($services,$item,$updates) $farm_service_helper.Farm_Recompose($services,$item,$spec) } } - 'ENABLE' { - $map = New-Object VMware.Hv.MapEntry - $map.key = 'data.enabled' - $map.value = $true - $farm_service_helper.Farm_Update($services,$item,$map) - } - 'DISABLE' { - $map = New-Object VMware.Hv.MapEntry - $map.key = 'data.enabled' - $map.value = $false - $farm_service_helper.Farm_Update($services,$item,$map) - } - 'START' { - if ($farmType.$item -ne 'AUTOMATED') { - Write-Error "Start operation is not supported for farm with name [$farmList.$item]" - break - } else { - $map = New-Object VMware.Hv.MapEntry - $map.key = 'automatedFarmData.virtualCenterProvisioningSettings.enableProvisioning' - $map.value = $true - $farm_service_helper.Farm_Update($services,$item,$map) - } - } - 'STOP' { - if ($farmType.$item -ne 'AUTOMATED') { - Write-Error "STOP operation is not supported for farm with name [$farmList.$item]" - break - } else { - $map = New-Object VMware.Hv.MapEntry - $map.key = 'automatedFarmData.virtualCenterProvisioningSettings.enableProvisioning' - $map.value = $false - $farm_service_helper.Farm_Update($services,$item,$map) - } - } } return } @@ -4297,7 +4561,7 @@ function Get-AllRDSServersInFarm ($Services,$Farm,$ServerList) { return $servers } -function Set_Spec_Vms_Farm { +function Set-HVFarmSpec { param( [Parameter(Mandatory = $true)] [VMware.Hv.VirtualCenterId]$VcID, @@ -4338,18 +4602,6 @@ function Start-HVPool { .PARAMETER Pool Name/Object(s) of the pool. -.PARAMETER Enable - Switch parameter to enable the pool. - -.PARAMETER Disable - Switch parameter to disable the pool. - -.PARAMETER Start - Switch parameter to start the pool. - -.PARAMETER Stop - Switch parameter to stop the pool. - .PARAMETER Refresh Switch parameter to refresh operation. @@ -4399,7 +4651,7 @@ function Start-HVPool { .EXAMPLE $myTime = Get-Date '10/03/2016 12:30:00' - Start-HVPool -Eebalance -Pool 'LCPool3' -LogoffSetting FORCE_LOGOFF -StartTime $myTime + Start-HVPool -Rebalance -Pool 'LCPool3' -LogoffSetting FORCE_LOGOFF -StartTime $myTime .EXAMPLE Start-HVPool -SchedulePushImage -Pool 'InstantPool' -LogoffSetting FORCE_LOGOFF -ParentVM 'InsParentVM' -SnapshotVM 'InsSnapshotVM' @@ -4407,9 +4659,6 @@ function Start-HVPool { .EXAMPLE Start-HVPool -CancelPushImage -Pool 'InstantPool' -.EXAMPLE - Start-HVPool -Pool 'TestPool' -Enable - .OUTPUTS None @@ -4433,18 +4682,6 @@ function Start-HVPool { [Parameter(Mandatory = $true,ValueFromPipeline = $true)] $Pool, - [Parameter(Mandatory = $false,ParameterSetName = 'ENABLE')] - [switch]$Enable, - - [Parameter(Mandatory = $false,ParameterSetName = 'DISABLE')] - [switch]$Disable, - - [Parameter(Mandatory = $false,ParameterSetName = 'START')] - [switch]$Start, - - [Parameter(Mandatory = $false,ParameterSetName = 'STOP')] - [switch]$Stop, - [Parameter(Mandatory = $false,ParameterSetName = 'REFRESH')] [switch]$Refresh, @@ -4502,7 +4739,7 @@ function Start-HVPool { begin { - $services = Get_ViewAPI_Service -hvServer $hvServer + $services = Get-ViewAPIService -hvServer $hvServer if ($null -eq $services) { Write-Error "Could not retrieve ViewApi services from connection object" break @@ -4528,7 +4765,7 @@ function Start-HVPool { $type = $item.desktopsummarydata.type } elseif ($item.GetType().name -eq 'String') { try { - $poolObj = Get-HVPool -poolName $item -hvServer $hvServer + $poolObj = Get-HVPoolSummary -poolName $item -hvServer $hvServer } catch { Write-Error "Make sure Get-HVPool advanced function is loaded, $_" break @@ -4560,32 +4797,32 @@ function Start-HVPool { $desktop_helper = New-Object VMware.Hv.DesktopService switch ($operation) { 'REBALANCE' { - $spec = Get_TaskSpec -Source $poolSource.$item -poolName $poolList.$item -operation $operation -taskSpecName 'DesktopRebalanceSpec' -desktopId $item + $spec = Get-HVTaskSpec -Source $poolSource.$item -poolName $poolList.$item -operation $operation -taskSpecName 'DesktopRebalanceSpec' -desktopId $item if ($null -ne $spec) { # make sure current task on VMs, must be None $desktop_helper.Desktop_Rebalance($services,$item,$spec) } } 'REFRESH' { - $spec = Get_TaskSpec -Source $poolSource.$item -poolName $poolList.$item -operation $operation -taskSpecName 'DesktopRefreshSpec' -desktopId $item + $spec = Get-HVTaskSpec -Source $poolSource.$item -poolName $poolList.$item -operation $operation -taskSpecName 'DesktopRefreshSpec' -desktopId $item if ($null -ne $spec) { # make sure current task on VMs, must be None $desktop_helper.Desktop_Refresh($services,$item,$spec) } } 'RECOMPOSE' { - $spec = Get_TaskSpec -Source $poolSource.$item -poolName $poolList.$item -operation $operation -taskSpecName 'DesktopRecomposeSpec' -desktopId $item + $spec = Get-HVTaskSpec -Source $poolSource.$item -poolName $poolList.$item -operation $operation -taskSpecName 'DesktopRecomposeSpec' -desktopId $item if ($null -ne $spec) { - $vcId = Get_Vcenter_ID -services $services -vCenter $vCenter - $spec = Set_Spec_Vms -vcId $vcId -spec $spec + $vcId = Get-VcenterID -services $services -vCenter $vCenter + $spec = Set-HVPoolSpec -vcId $vcId -spec $spec # make sure current task on VMs, must be None $desktop_helper.Desktop_Recompose($services,$item,$spec) # Update Base Image VM and Snapshot in Pool $updates = @() - $updates += Get_MapEntry -key 'automatedDesktopData.virtualCenterProvisioningSettings.virtualCenterProvisioningData.parentVm' -value $spec.ParentVM - $updates += Get_MapEntry -key 'automatedDesktopData.virtualCenterProvisioningSettings.virtualCenterProvisioningData.snapshot' -value $spec.Snapshot + $updates += Get-MapEntry -key 'automatedDesktopData.virtualCenterProvisioningSettings.virtualCenterProvisioningData.parentVm' -value $spec.ParentVM + $updates += Get-MapEntry -key 'automatedDesktopData.virtualCenterProvisioningSettings.virtualCenterProvisioningData.snapshot' -value $spec.Snapshot $desktop_helper.Desktop_Update($services,$item,$updates) } @@ -4596,8 +4833,8 @@ function Start-HVPool { break } else { $spec = New-Object VMware.Hv.DesktopPushImageSpec - $vcId = Get_Vcenter_ID -services $services -vCenter $vCenter - $spec = Set_Spec_Vms -vcId $vcId -spec $spec + $vcId = Get-VcenterID -services $services -vCenter $vCenter + $spec = Set-HVPoolSpec -vcId $vcId -spec $spec $spec.Settings = New-Object VMware.Hv.DesktopPushImageSettings $spec.Settings.LogoffSetting = $logoffSetting $spec.Settings.StopOnFirstError = $stopOnFirstError @@ -4613,46 +4850,12 @@ function Start-HVPool { $desktop_helper.Desktop_CancelScheduledPushImage($services,$item) } } - 'ENABLE' { - $map = New-Object VMware.Hv.MapEntry - $map.key = 'desktopSettings.enabled' - $map.value = $true - $desktop_helper.Desktop_Update($services,$item,$map) - } - 'DISABLE' { - $map = New-Object VMware.Hv.MapEntry - $map.key = 'desktopSettings.enabled' - $map.value = $false - $desktop_helper.Desktop_Update($services,$item,$map) - } - 'START' { - if ($poolType.$item -ne 'Automated') { - Write-Error "$poolList.$item is not a Automated pool" - break - } else { - $map = New-Object VMware.Hv.MapEntry - $map.key = 'automatedDesktopData.virtualCenterProvisioningSettings.enableProvisioning' - $map.value = $true - $desktop_helper.Desktop_Update($services,$item,$map) - } - } - 'STOP' { - if ($poolType.$item -ne 'Automated') { - Write-Error "$poolList.$item is not a Automated pool" - break - } else { - $map = New-Object VMware.Hv.MapEntry - $map.key = 'automatedDesktopData.virtualCenterProvisioningSettings.enableProvisioning' - $map.value = $false - $desktop_helper.Desktop_Update($services,$item,$map) - } - } } } } } -function Get-Machines ($Pool,$MachineList) { +function Get-Machine ($Pool,$MachineList) { [VMware.Hv.MachineId[]]$machines = @() $remainingCount = 1 # run through loop at least once $query = New-Object VMware.Hv.QueryDefinition @@ -4682,7 +4885,7 @@ function Get-Machines ($Pool,$MachineList) { return $machines } -function Set_Spec_Vms { +function Set-HVPoolSpec { param( [Parameter(Mandatory = $true)] [VMware.Hv.VirtualCenterId]$VcID, @@ -4705,7 +4908,7 @@ function Set_Spec_Vms { return $spec } -function Get_TaskSpec { +function Get-HVTaskSpec { param( [Parameter(Mandatory = $true)] [string]$Source, @@ -4727,12 +4930,12 @@ function Get_TaskSpec { Write-Error "$operation task is not supported for pool type: [$source]" return $null } - $machineList = Get-Machines $desktopId $machines + $machineList = Get-Machine $desktopId $machines if ($machineList.Length -eq 0) { Write-Error "Failed to get any Virtual Center machines with the given pool name: [$poolName]" return $null } - $spec = Get_New_Object -TypeName $taskSpecName + $spec = Get-HVObject -TypeName $taskSpecName $spec.LogoffSetting = $logoffSetting $spec.StopOnFirstError = $stopOnFirstError $spec.Machines = $machineList @@ -4740,4 +4943,4 @@ function Get_TaskSpec { return $spec } -Export-ModuleMember Add-HVDesktop,Add-HVRDSServer,Connect-HVEvent,Disconnect-HVEvent,Get-HVEvent,Get-HVFarm,Get-HVPool,Get-HVQueryResult,Get-HVQueryFilter,New-HVFarm,New-HVPool,Remove-HVFarm,Remove-HVPool,Set-HVFarm,Set-HVPool,Start-HVFarm,Start-HVPool +Export-ModuleMember Add-HVDesktop,Add-HVRDSServer,Connect-HVEvent,Disconnect-HVEvent,Get-HVEvent,Get-HVFarm,Get-HVFarmSummary,Get-HVPool,Get-HVPoolSummary,Get-HVQueryResult,Get-HVQueryFilter,New-HVFarm,New-HVPool,Remove-HVFarm,Remove-HVPool,Set-HVFarm,Set-HVPool,Start-HVFarm,Start-HVPool From 5dd7449b0eef09fdee9bfedbec49c4fd7cfff938 Mon Sep 17 00:00:00 2001 From: mycloudrevolution Date: Fri, 2 Dec 2016 00:20:05 +0100 Subject: [PATCH 7/8] Recommend-Sizing version 1.2 VM Stats from Realtime - new VM Counters - vSphere 6.5 support - Parameter enhancements --- Modules/Recommend-Sizing.psm1 | 63 ++++++++++++++++++++--------------- 1 file changed, 37 insertions(+), 26 deletions(-) diff --git a/Modules/Recommend-Sizing.psm1 b/Modules/Recommend-Sizing.psm1 index db01181..0075e43 100644 --- a/Modules/Recommend-Sizing.psm1 +++ b/Modules/Recommend-Sizing.psm1 @@ -8,14 +8,15 @@ function Recommend-Sizing { =========================================================================== Changelog: 2016.11 ver 1.0 Base Release - 2016.11 ver 1.1 Optional Stats Collection. + 2016.11 ver 1.1 Optional Stats Collection + 2016.11 ver 1.2 VM Stats from Realtime Data and new Counters =========================================================================== External Code Sources: http://www.lucd.info/2011/04/22/get-the-maximum-iops/ https://communities.vmware.com/thread/485386 =========================================================================== Tested Against Environment: - vSphere Version: 5.5 U2 + vSphere Version: 5.5 U2, 6.0 PowerCLI Version: PowerCLI 6.3 R1, PowerCLI 6.5 R1 PowerShell Version: 4.0, 5.0 OS Version: Windows 8.1, Server 2012 R2 @@ -24,7 +25,7 @@ function Recommend-Sizing { =========================================================================== .DESCRIPTION - This Function collects Basic vSphere Informations for a Hardware Sizing Recomamndation. Focus is in Compute Ressources. + This Function collects Basic vSphere Informations for a Hardware Sizing Recommandation. Focus is in Compute Ressources. .Example Recommend-Sizing -ClusterNames Cluster01, Cluster02 -Stats -StatsRange 60 -Verbose @@ -41,7 +42,7 @@ function Recommend-Sizing { .PARAMETER Stats Enables Stats Collection. - Warning: At the moment this is only tested and supported with vSphere 5.5! + Warning: At the moment this is only fully tested with vSphere 5.5 and vSphere 6.5! .PARAMETER StatsRange Time Range in Minutes for the Stats Collection. @@ -55,15 +56,15 @@ function Recommend-Sizing { param( [Parameter(Mandatory=$True, ValueFromPipeline=$False, Position=0)] [Array] $ClusterNames, - [Parameter(Mandatory=$False, ValueFromPipeline=$False, Position=2)] + [Parameter(Mandatory=$False, ValueFromPipeline=$False, Position=1, ParameterSetName = "Stats")] [switch] $Stats, - [Parameter(Mandatory=$False, ValueFromPipeline=$False, Position=2)] + [Parameter(Mandatory=$False, ValueFromPipeline=$False, Position=2, ParameterSetName = "Stats")] [int] $StatsRange = 1440 ) Begin { if ($Stats) { - Write-Warning "Stats Collection enabled.`nAt the moment this is only tested and supported with vSphere 5.5" + Write-Warning "Stats Collection requested.`nAt the moment this is only fully tested with vSphere 5.5 and vSphere 6.5" [int]$TimeRange = "-" + $StatsRange } @@ -121,30 +122,38 @@ Process { #endregion if ($Stats) { - #region: Creating Disk Metrics - Write-Verbose "$(Get-Date -Format G) Create $($Cluster.name) IOPS Metrics..." - $DiskMetrics = "virtualDisk.numberReadAveraged.average","virtualDisk.numberWriteAveraged.average" - $start = (Get-Date).AddMinutes($TimeRange) - $DiskStats = Get-Stat -Stat $DiskMetrics -Entity $ClusterVMsPoweredOn -Start $start -Verbose:$False - Write-Verbose "$(Get-Date -Format G) Create $($Cluster.name) IOPS Metrics completed" + #region: Creating VM Stats + Write-Verbose "$(Get-Date -Format G) Create $($Cluster.name) VM Stats..." + $VMMetrics = "disk.numberwrite.summation","disk.numberread.summation","cpu.usage.average", "mem.usage.average" + $Start = (Get-Date).AddMinutes($TimeRange) + $VMStats = Get-Stat -Realtime -Stat $VMMetrics -Entity $ClusterVMsPoweredOn -Start $Start -Verbose:$False + Write-Verbose "$(Get-Date -Format G) Create $($Cluster.name) VM Stats completed" #endregion - #region: Creating IOPS Reports - Write-Verbose "$(Get-Date -Format G) Process $($Cluster.name) IOPS Report..." - $reportDiskPerf = @() - $reportDiskPerf = $DiskStats | Group-Object -Property {$_.Entity.Name},Instance | %{ - New-Object PSObject -Property @{ - IOPSMax = ($_.Group | ` - Group-Object -Property Timestamp | ` - %{$_.Group[0].Value + $_.Group[1].Value} | ` - Measure-Object -Maximum).Maximum + #region: Creating VM Stats Report + Write-Verbose "$(Get-Date -Format G) Process $($Cluster.name) VM Stats Report..." + $ReportVMPerf = @() + $ReportVMPerf = $VMStats | Group-Object -Property {$_.Entity.Name},Instance | %{ + New-Object PSObject -Property @{ + IOPSWriteAvg = ($_.Group | ` + where{$_.MetricId -eq "disk.numberwrite.summation"} | ` + Measure-Object -Property Value -Average).Average + IOPSReadAvg = ($_.Group | ` + where{$_.MetricId -eq "disk.numberread.summation"} | ` + Measure-Object -Property Value -Average).Average + CPUUsageAvg = ($_.Group | ` + where{$_.MetricId -eq "cpu.usage.average"} | ` + Measure-Object -Property Value -Average).Average + MEMUsageAvg = ($_.Group | ` + where{$_.MetricId -eq "mem.usage.average"} | ` + Measure-Object -Property Value -Average).Average } } - Write-Verbose "$(Get-Date -Format G) Process $($Cluster.name) IOPS Report completed" + Write-Verbose "$(Get-Date -Format G) Process $($Cluster.name) VM Stats Report completed" #endregion } else { - Write-Verbose "$(Get-Date -Format G) Stats Cellocetion skipped..." + Write-Verbose "$(Get-Date -Format G) Stats Collection skipped..." } #region: Create VM Disk Space Report @@ -194,8 +203,10 @@ Process { SumVMDiskSpaceGB = [math]::round( ($reportDiskSpace | Measure-Object -Sum -Property CapacityGB).sum, 1 ) SumDatastoreSpaceGB = [math]::round( ($DatastoreReport | Measure-Object -Sum -Property CapacityGB).sum, 1 ) SumDatastoreUsedSpaceGB = [math]::round( ($DatastoreReport | Measure-Object -Sum -Property UsedSpaceGB).sum, 1 ) - SumMaxVMIOPS = [math]::round( ($reportDiskPerf | Measure-Object -Sum -Property IOPSMax).sum, 1 ) - AverageMaxVMIOPs = [math]::round( ($reportDiskPerf | Measure-Object -Average -Property IOPSMax).Average,1 ) + AverageVMIOPSWriteAvg = [math]::round( ($ReportVMPerf | Measure-Object -Average -Property IOPSWriteAvg).Average,1 ) + AverageVMIOPSReadAvg = [math]::round( ($ReportVMPerf | Measure-Object -Average -Property IOPSReadAvg).Average,1 ) + AverageVMCPUUsageAvg = "$([math]::round( ($ReportVMPerf | Measure-Object -Average -Property CPUUsageAvg).Average,1 )) %" + AverageVMMEMUsageAvg = "$([math]::round( ($ReportVMPerf | Measure-Object -Average -Property MEMUsageAvg).Average,1 )) %" } $MyView += $SizingReport Write-Verbose "$(Get-Date -Format G) Process Global Report completed" From 02c66242f196e066d009cabda92bab08a63bf63a Mon Sep 17 00:00:00 2001 From: praveenmathamsetty Date: Fri, 2 Dec 2016 08:31:01 +0530 Subject: [PATCH 8/8] Find-HVPool parameter Making Find-HVPool parameter as mandatory --- Modules/VMware.Hv.Helper/VMware.HV.Helper.psm1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Modules/VMware.Hv.Helper/VMware.HV.Helper.psm1 b/Modules/VMware.Hv.Helper/VMware.HV.Helper.psm1 index c80d13f..6884703 100644 --- a/Modules/VMware.Hv.Helper/VMware.HV.Helper.psm1 +++ b/Modules/VMware.Hv.Helper/VMware.HV.Helper.psm1 @@ -1356,7 +1356,7 @@ function Get-HVPoolSummary { function Find-HVPool { [CmdletBinding()] param( - [Parameter(Mandatory = $false)] + [Parameter(Mandatory = $true)] $Param )