Share This: Unfortunately there isn’t any official supported way to Automate PSC AD Integrated identity source in VCSA 6.5u1 In the past in v5.5 / 6.0 or 6.5 that was possible using sso-add-native-ad-idp.sh and sso_import.sh however for some reason those utilities are no longer present in 6.5u1 image. VCSA 5.5 PSC AD integrated identity source automation example using […]
Continue reading…
Posts by cann0nF0dder
Create / Import host profile from existing config – PS PowerCLI
Share This: https://github.com/cann0nf0dder/PS_PowerCLI.git <# NAME: Import_Host_Profile.ps1 AUTHOR: Chris Danielewski DATE : 8/22/2017 PURPOSE: This script will import host profile from config location OUTPUT: N/A REQUIRED UTILITIES: PowerCLI, ========================================================================== CHANGE HISTORY: GE HISTORY: v1.0 8/23/2017 CD New script! #> param( [Parameter(Mandatory=$true)][String]$location ) #environemt $profile_name = “Imported_profile” $pathTOprofile = $location + “profile.vpf” $obj = Get-View ServiceInstance $hpobj […]
Continue reading…
Export last host profile – PS Powercli script
Share This: Quick script to export last host profile: https://github.com/cann0nf0dder/PS_PowerCLI.git <# NAME: Export_HostProfile.ps1 AUTHOR: Chris Danielewski DATE : 8/22/2017 PURPOSE: This script will export host profile to new pod config location. OUTPUT: N/A REQUIRED UTILITIES: PowerCLI, ========================================================================== CHANGE HISTORY: GE HISTORY: v1.0 8/22/2017 CD New script! #> param( [Parameter(Mandatory=$true)][String]$location ) #environemt $lastprof = @() $lastprof = […]
Continue reading…
Quick powercli search for information on recently deleted VMs
Share This:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
PS /Users/cannon> Get-VIEvent -MaxSamples 1000 | where {$_.Gettype().Name -eq "VmRemovedEvent"} Template : False Key : 194263 ChainId : 194261 CreatedTime : 19/03/2017 10:17:03 UserName : VSPHERE.LOCAL\Administrator Datacenter : VMware.Vim.DatacenterEventArgument ComputeResource : VMware.Vim.ComputeResourceEventArgument Host : VMware.Vim.HostEventArgument Vm : VMware.Vim.VmEventArgument Ds : Net : Dvs : FullFormattedMessage : Removed TestVM01 on vhostb.vsphere.local from Pod1 ChangeTag : |
Above is quick and dirty syntax that’s quite easy to remember! More syntax options can be found here: http://www.virtu-al.net/2009/08/27/powercli-one-liners-last-10-vms-created-and-removed/
Continue reading…
vSphere 6.x Enable & Disable iSCSI Jumbo Frames on vmk & vswitches powershell script
Share This:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
<# NAME: Configure_iSCSI_MTU.ps1 AUTHOR: Chris Danielewski DATE : 2/2/2016 PURPOSE: This script will display current MTU value for each vmk and vSwitch within specified cluster It can set MTU at either 1500 or 9000 for iSCSI vmks (vmk1,2) - modify to match your environment It can set MTU on vSwitches. OUTPUT: N/A REQUIRED UTILITIES: PowerCLI ========================================================================== CHANGE HISTORY: GE HISTORY: v1.0 2/2/2016 CD New Script. #> function clusterselector { #Get all Clusters $cluster = Get-Cluster #Create Cluster Menu and Prompt user to Select Desired Cluster if ($cluster -is [System.Array]) { $cmenu = @{} Write-Host "`nCluster selection for $($DefaultVIServers[0]):" for ($i=1;$i -le $cluster.count; $i++) { Write-Host "$i. $($cluster[$i-1].name)" $cmenu.Add($i,($cluster[$i-1].name)) } [int]$cans = Read-Host 'Enter desired cluster' if ($cans -eq '0' -or $cans -gt $i) {Write-Host -ForegroundColor Red -Object "Invalid selection.`n";Exit} #Set Cluster Variable to User's choice $cluster = get-cluster ($cmenu.Item($cans)) } #Return the chosen Cluster via variable! return $cluster } function setVMKmtu { $cluster = clusterselector Get-Cluster $cluster | Get-VMHost | Get-VMHostNetworkAdapter -Name 'vmk1' | Set-VMHostNetworkAdapter -Mtu $MTU -Confirm:$false Get-Cluster $cluster | Get-VMHost | Get-VMHostNetworkAdapter -Name 'vmk2' | Set-VMHostNetworkAdapter -Mtu $MTU -Confirm:$false } function setvSSmtu { $cluster = clusterselector $vswitches = Get-Cluster $cluster| Get-VMHost | Get-VirtualSwitch -Standard foreach($vswitch in $vswitches) { Set-VirtualSwitch $vswitch -Mtu $MTU -Confirm:$False } } do{ Write-Host -ForegroundColor Green "iSCSI MTU configuration" Write-Host "1) Display cluster vmkernel port MTU values" Write-Host "2) Disaplay cluster standard vSwitch MTU values " Write-Host "3) Enable cluster Jumbo frames on iSCSI vmkernel ports (MTU 9000)" Write-Host "4) Disable cluster Jumbo frames on iSCSI vmkernel ports (MTU 1500)" Write-Host "5) Enable cluster Jumbo frames on standard vSwitches (MTU 9000)" Write-Host "6) Disable cluster Jumbo frames on standard vSwitches (MTU 1500)" Write-Host "6) Exit" $Input = Read-Host "Please select 1-7?" Write-Host "" if ($Input -eq "1") { $cluster = clusterselector Get-Cluster $cluster | Get-VMHost | Get-VMHostNetworkAdapter | Where { $_.GetType().Name -eq "HostVMKernelVirtualNicImpl" } | Select VMHost, Name, MTU } elseif ($Input -eq "2") { $cluster = clusterselector $switches = Get-Cluster $cluster | Get-VMHost | Get-VirtualSwitch -Standard $switches } elseif ($Input -eq "3") { $MTU = 9000 setVMKmtu } elseif ($Input -eq "4") { $MTU = 1500 setVMKmtu } elseif ($Input -eq "5") { $MTU = 9000 setvSSmtu } elseif ($Input -eq "6") { $MTU = 1500 setvSSmtu } }until($Input -eq "7") |
PowerCLI Core on Mac OS Sierra setup guide
Share This: “PowerCLI Core uses Microsoft PowerShell Core and .Net Core to enable users of Linux, Mac and Docker to now use the same cmdlets which were previously only available on windows.” This will allow you to use PowerCLI and connect to vCenter Server / Hosts directly from your Mac Terminal! 1.Download the fling from: […]
Continue reading…
vSphere ESXi Rolling reboots Safe powershell script – Calculate Cluster load / Safe MM
Share This:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 |
<# NAME: ESXi_Rolling_Reboots_Safe.ps1 AUTHOR: Chris Danielewski DATE : 12/21/2016 PURPOSE: This script will loop though each host in the cluster and safely reboot it. It will calculate if the host can be placed in MM so that the cluster is to never exceed 94% CPU/RAM utilisation. Also disabled/re-enables alarms for each host. Perfect for upgrades if not using VUM. OUTPUT: N/A REQUIRED UTILITIES: PowerCLI ========================================================================== CHANGE HISTORY: GE HISTORY: v1.0 12/21/2016 CD New Script!. #> $cluster = Read-Host "Please enter cluster Name" $vmhosts = $cluster | Get-VMHost -State Connected | sort Name foreach ($vmh in $vmhosts) { $vmhname = $vmh.Name Write-Host -ForegroundColor Blue "(1/8) Analysing cluster $cluster" $calc = CalculateClusterLoadMinusOneHost($cluster) if($calc-eq $True){ ###Enter MM### Write-Host -ForegroundColor Yellow "(2/8) Cluster utilisation within thresholds" Write-Host -ForegroundColor Yellow "(3/8) $vmhname MM initiated" Set-VMHost -VMHost $vmh -State Maintenance | Out-Null ###Wait until host is in MM### do { $vmh = Get-VMhost -Name $vmhname $state = $vmh.ConnectionState sleep 10 }until ($state -eq "Maintenance") $state = "" #Disable alerts SetHostAlertsDisabled($vmhname) Write-Host -ForegroundColor Yellow "(4/8) $vmhname alerts are now disabled" ###Reboot### Write-Host -ForegroundColor Yellow "(5/8) $vmhname reboot initiated" Restart-VMHost -VMHost $vmh -Confirm:$false | Out-Null sleep 10 ###Wait for reconnect### do { sleep 60 $vmh = Get-VMhost -Name $vmhname $state = $vmh.ConnectionState Write-Host "Waiting for $vmhname reboot to complete" # if ($state -eq "Maintenance"){ # Write-Host -ForegroundColor Yellow "$vmhname exit MM initiated" # Set-VMhost -VMHost $vmh -State Connected | Out-Null # } }until ($state -eq "Connected") Write-Host -ForegroundColor Yellow "(6/8) $vmhname reconnected to $cluster" ###Enable Alerts### Write-Host -ForegroundColor Yellow "(7/8) $vmhname alerts are now enabled" SetHostAlertsEnabled($vmhname) #Output success Write-Host -ForegroundColor Blue "(8/8) $vmhname operations completed" ###Continue the loop - move onto another host } Else {exit Write-Host -ForegroundColor Red "Cluster utilisation too high" } } Function CalculateClusterLoadMinusOneHost([string]$cluster) { #Set variables $clu = Get-Cluster $cluster $VMHs = $clu | Get-VMHost -State Connected | sort Name $report = @() $memlvl = 0 $cpulvl = 0 $counter = 0 #Define CPU/Memory thresholds $memthres = 94 $cputhres = 94 #Loop through cluster and pull CPU/MEM Stats foreach ($vmh in $VMHs) { $row = "" | select-Object Name, CpuUtil, MemUtil $row.Name = $hosts.Name $row.CpuUtil = (Get-Stat -Entity $vmh -Stat cpu.usage.average -Realtime -MaxSamples 1 | where {$_.Instance -eq ""}).Value $row.MemUtil = (Get-Stat -Entity $vmh -Stat mem.usage.average -Realtime -MaxSamples 1).Value $report += $row $memlvl = $memlvl + $row.MemUtil $cpulvl = $cpulvl + $row.CpuUtil $counter ++ } $counter -- #Calculate Total and average memory and CPU $memtotal = [System.Math]::Round($memlvl) $cputotal = [System.Math]::Round($cpulvl) [double]$memavg = $memtotal / $counter Write-Host -ForegroundColor Yellow "Cluster $cluster memory utilisation after taking out this node will be $memavg %" [double]$cpuavg = $cputotal / $counter Write-Host -ForegroundColor Yellow "Cluster $cluster CPU utilisation after taking out this node will be $cpuavg %" #Return True or False if ($memavg -lt $memthres -and $cpuavg -lt $cputhres){return $true}Else{return $false} } Function SetHostAlertsDisabled($node) { $alarmMgr = Get-View AlarmManager $svr = Get-VMHost $node $alarmMgr.EnableAlarmActions($svr.Extensiondata.MoRef,$false) } Function SetHostAlertsEnabled($node) { $alarmMgr = Get-View AlarmManager $svr = Get-VMHost $node $alarmMgr.EnableAlarmActions($svr.Extensiondata.MoRef,$true) } |
Calculate Cluster Load vSphere powershell script / function
Share This: I was surprised I couldn’t find this script/function when looking across WWW. Here it is!
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
<# NAME: CalculateClusterLoad.ps1 AUTHOR: Chris Danielewski DATE : 12/16/2016 PURPOSE: This function will calculate the average cluster CPU and RAM. OUTPUT: Cluster MEM/CPU utilisation in percentage REQUIRED UTILITIES: PowerCLI ========================================================================== CHANGE HISTORY: GE HISTORY: v1.0 12/16/2016 CD New Function. #> Function CalculateClusterLoad([string]$cluster) { #Set variables $clu = Get-Cluster $cluster $VMHs = $clu | Get-VMHost -State Connected | sort Name $report = @() $memlvl = 0 $cpulvl = 0 $counter = 0 #Loop through cluster and pull CPU/MEM Stats foreach ($vmh in $VMHs) { $hosts = Get-VMHost $vmh.Name | %{Get-View $_.ID} $row = "" | select-Object Name, CpuUtil, MemUtil $row.Name = $hosts.Name $row.CpuUtil = (Get-Stat -Entity $vmh -Stat cpu.usage.average -Realtime -MaxSamples 1 | where {$_.Instance -eq ""}).Value $row.MemUtil = (Get-Stat -Entity $vmh -Stat mem.usage.average -Realtime -MaxSamples 1).Value $report += $row $memlvl = $memlvl + $row.MemUtil $cpulvl = $cpulvl + $row.CpuUtil $counter ++ } #Calculate Total and average memory and CPU $memtotal = [System.Math]::Round($memlvl) $cputotal = [System.Math]::Round($cpulvl) [double]$memavg = $memtotal / $counter Write-Host -ForegroundColor Yellow "Cluster $cluster memory utilisation is $memavg %" [double]$cpuavg = $cputotal / $counter Write-Host -ForegroundColor Yellow "Cluster $cluster CPU utilisation is $cpuavg %" |
HPE Stackato 3.4.2 / 3.6.2 cloud deployment automated for vSphere – Powershell
Share This: Build template: In order to run the Invoke-VMscript cmdlet, we need to spin up stackato VM from ovf, install VMware tools, run some recent updates/patches and save this VM as template. Deploy stackato VM from OVF Open VM Console and configure OS: Login with stackato/stackato Reset stackato password to stackato123 using passwd Change […]
Continue reading…
Update all Host profiles from reference host script
Share This:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
################################################################ # NAME: UpdateALLHostProfiles_from_ref_host.ps1 # # AUTHOR: Chris Danielewski # DATE : 10/27/2016 # # PURPOSE: This script is designed to update all host from reference host once we do mass changes # # INPUT: N/a # # OUTPUT: Onscreen # # REQUIRED UTILITIES: none # #========================================================================== #CHANGE HISTORY: # Version DATE Initials Description of Change # v1.0 10/27/2016 CD New Script ################################################################ #Define Functions ######################################### #Get Existing Host Profile $Profiles = @() $Profiles = Get-VMHostProfile foreach($Profile in $Profiles){ Write-Host -ForegroundColor Blue "Updating profile: $Profile" #Create the update Spec $Spec = New-Object VMware.Vim.HostProfileHostBasedConfigSpec $Spec.Host = New-Object VMware.Vim.ManagedObjectReference $Spec.Host = $Profile.ReferenceHost.ExtensionData.MoRef $Spec.useHostProfileEngine = $true #Update the host Profile $Profile.ExtensionData.UpdateHostProfile($Spec) } |