piercj2's Posts

Thanks Luc, that worked as expected. After your first suggestion i got a lot of blank information back but quickly spotted the typo and once corrected it worked perfectly, thanks. To anyone w... See more...
Thanks Luc, that worked as expected. After your first suggestion i got a lot of blank information back but quickly spotted the typo and once corrected it worked perfectly, thanks. To anyone who wants to use this, run it first to get back the server model details as, this information is detailed on the Host, e.g. you may be using Cisco UCS C210's but, this report identifies these as R210-2121605W . When you have all your Server models, google the EOL date and edit the  $vmHostModelEolMapping hash table to match your servers.
Hi All, I've created the below to generate a report containing End of Life / End of Support information for approx 2000 ESXi Hosts, spread across multiple vCenters. The report works to a poin... See more...
Hi All, I've created the below to generate a report containing End of Life / End of Support information for approx 2000 ESXi Hosts, spread across multiple vCenters. The report works to a point. I've just noticed that it's returning the same Serial numbers for a lot of the ESXi Hosts, these should all be unique. I've also noticed that the model numbers are not always correct either. If i run the script against individual ESXi Hosts, the data returned is correct. The script runs without error so i don't understand why duplicate/incorrect information is being returned for some of the Servers. Could it be that i don't have enough memory/cpu on the server that's running the script ? Should i be using Get-View instead of Get-Esxcli to optimize the data collection ? Should i be setting each variable to null before moving to the next ESXi Host (seems wasteful) $cred = Get-Credential 'username@company.com' $vCenters = @(     "vc1.company.com"     "vc2.company.com"     "vc3.company.com"     "vc4.company.com"     ) Connect-VIServer -Server $vCenters -Credential $cred -ErrorAction SilentlyContinue # Server model to EOL date mappings, edit to add/correct dates $vmHostModelEolMapping = @{     "UCS-C210" = "2020/Jun"     "UCS-C220" = "2020/Jun"     "UCS-C240" = "2018/Aug"     "UCS-C420" = "2017/Jan"     "PowerEdge R630" = "2018/May"     "PowerEdge R710" = "2016/May"     "PowerEdge R730xd" = "2018/May"     "PowerEdge R900"  = "2015/Jul"     "PowerEdge R910" = "2015/Mar"     } # Collect Server details $results = @() foreach ($vmHost in Get-VMHost) {     $esxcli = Get-EsxCli -vmhost $vmHost.name -V2 -ErrorAction SilentlyContinue     $vcName = [System.Net.Dns]::GetHostEntry((get-view $vmHost -ErrorAction SilentlyContinue).summary.managementserverip).HostName     $vmHostName = $vmHost.Name     $vmHostVendor = $esxcli.hardware.platform.get.invoke().VendorName     $vmHostModel = $esxcli.hardware.platform.get.invoke().ProductName     $vmHostSerial = $esxcli.hardware.platform.get.invoke().SerialNumber     $EolDate = "Unknown"     if ($vmHostModelEolMapping.ContainsKey($vmHostModel)){         $EolDate = $vmHostModelEolMapping[$vmHostModel]         }     $prop = [pscustomobject] @{             vCenter = $vcName             "ESXi Host Name" = $vmHostName             Vendor = $vmHostVendor             Model = $vmHostModel             Serial = $vmHostSerial             EOL = $EolDate     }     $results+=$prop } $results | Sort-Object vCenter,"ESXi Host Name" | Export-Csv -path c:\Temp\EOLreport.csv
That worked perfectly Luc, Thanks ! As an FYI, i'm running VCSA 6.5U3 to it looks like this issue/bug existed prior to 6.7. The finished Code looks as follows for anyone who may need it $c... See more...
That worked perfectly Luc, Thanks ! As an FYI, i'm running VCSA 6.5U3 to it looks like this issue/bug existed prior to 6.7. The finished Code looks as follows for anyone who may need it $clusterName = Read-Host "Enter the name of the target Cluster" $targetCluster = Get-Cluster -Name $clusterName $RPname = Read-Host "Enter the name of the destination Resource Pool" $targetRP = $targetCluster | Get-ResourcePool -Name $RPname # Move-VM not working due to known issues in version(s) VCSA # use vSphere API Method as workaround $spec = New-Object VMware.Vim.VirtualMachineRelocateSpec $spec.Pool = $targetRP.ExtensionData.MoRef $targetVMs = $null $targetVMs = $targetCluster | Get-VM $targetVMs | select Name, PowerState, ResourcePool, ResourcePoolId | Export-Excel foreach ($t in $targetVMs) {     if ($t.ResourcePool -Like "Resources") {         Write-Host $t.Name "is currently in Resource Pool " -NoNewline         Write-Host -ForegroundColor Red $t.ResourcePool - $t.ResourcePoolId         Write-Host Moving $t.name "from " -NoNewline         Write-Host -ForegroundColor Red $t.ResourcePool -NoNewline         Write-Host " to " -NoNewline         write-host -ForegroundColor Green $targetRP.Name - $targetRP.Id         # Move-VM not working due to known issues in version(s) of PowerCLI         # use vSphere API Method as workaround         # Move-VM -vm $t -Destination $targetRP                 $t.ExtensionData.RelocateVM($spec, [VMware.Vim.VirtualMachineMovePriority]::defaultPriority)         write-host     } }
i'm afraid i did. i've even tried just running the following to keep things simple PS C:\WINDOWS\system32> Get-ResourcePool | where {$_.Id -like $targetRP.Id} Name                 CpuSha... See more...
i'm afraid i did. i've even tried just running the following to keep things simple PS C:\WINDOWS\system32> Get-ResourcePool | where {$_.Id -like $targetRP.Id} Name                 CpuSharesL CpuReserva CpuLimitMH MemSharesL MemReservationG MemLimitGB                         evel       tionMHz    z          evel       B                             ----                 ---------- ---------- ---------- ---------- --------------- ----------    RP-Low              Low        0          -1         Low        0.000           -1.000 PS C:\WINDOWS\system32> get-vm MyTestVM | Move-VM -destination (Get-ResourcePool | where {$_.Id -like $targetRP.Id}) Move-VM : 13/01/2020 17:10:17    Move-VM        Object reference not set to an instance of an object.   At line:1 char:23 + ... MyTestVM | Move-VM -destination (Get-ResourcePool | where {$_.Id -li ... +                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~     + CategoryInfo          : NotSpecified: (:) [Move-VM], VimException     + FullyQualifiedErrorId : Core_BaseCmdlet_UnknownError,VMware.VimAutomation.ViCore.Cmdlets.Commands.MoveVM The original script worked for approx 50% of the VM's in the Cluster, makes me now think it's something specific to these VM's and, not the Resource Pool. Is there any reason why a VM couldn't be moved out of the default "Resources" pool ? from the Web Client i just dragged one of the offending VM's into the RP-Low resource pool and it worked
sorry, that was a typo on my part, i'd already spotted that and corrected it in my script but, same error on run. $clusterName = Read-Host "Enter the name of the target Cluster" $targetCluste... See more...
sorry, that was a typo on my part, i'd already spotted that and corrected it in my script but, same error on run. $clusterName = Read-Host "Enter the name of the target Cluster" $targetCluster = Get-Cluster -Name $clusterName $RPname = Read-Host "Enter the name of the destination Resource Pool" $targetRP = $targetCluster | Get-ResourcePool -Name $RPname $targetVMs = $null $targetVMs = $targetCluster | Get-VM coir1sccmdp1 $targetVMs | select Name, PowerState, ResourcePool, ResourcePoolId | Export-Excel foreach ($t in $targetVMs) {     if ($t.ResourcePool -Like "Resources") {         Write-Host $t.Name "is currently in Resource Pool " -NoNewline         Write-Host -ForegroundColor Red $t.ResourcePool - $t.ResourcePoolId         Write-Host Moving $t.name "from " -NoNewline         Write-Host -ForegroundColor Red $t.ResourcePool -NoNewline         Write-Host " to " -NoNewline         write-host -ForegroundColor Green $targetRP.Name - $targetRP.Id         Move-VM -vm $t -Destination $targetRP         write-host     } } the error returned is MyTestVM is currently in Resource Pool Resources - ResourcePool-resgroup-53 Moving MyTestVM from Resources to RP-Low - ResourcePool-resgroup-2663 Move-VM : 13/01/2020 16:38:28    Move-VM        Object reference not set to an instance of an object.    At line:9 char:9 +         Move-VM -vm $t -Destination $targetRP +         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~     + CategoryInfo          : NotSpecified: (:) [Move-VM], VimException     + FullyQualifiedErrorId : Core_BaseCmdlet_UnknownError,VMware.VimAutomation.ViCore.Cmdlets.Commands.MoveVM I've looked at the main variables and they seem correct PS C:\WINDOWS\system32> $t Name                 PowerState Num CPUs MemoryGB       ----                 ---------- -------- --------       MyTestVM         PoweredOn  4        8.000 PS C:\WINDOWS\system32> $t | gm    TypeName: VMware.VimAutomation.ViCore.Impl.V1.Inventory.VirtualMachineImpl PS C:\WINDOWS\system32> $targetRP Name                 CpuSharesL CpuReserva CpuLimitMH MemSharesL MemReservationG MemLimitGB                          evel       tionMHz    z          evel       B                              ----                 ---------- ---------- ---------- ---------- --------------- ----------     RP-Low              Low        0          -1         Low        0.000           -1.000 PS C:\WINDOWS\system32> $targetRP | gm    TypeName: VMware.VimAutomation.ViCore.Impl.V1.Inventory.ResourcePoolImpl
Hi Luc, i didn't know that selecting an object changed the returned type. Thanks ! I've made the suggested changes and, using "-whatIf" appears to work, i'e. the output is PS C:\WINDOWS\sys... See more...
Hi Luc, i didn't know that selecting an object changed the returned type. Thanks ! I've made the suggested changes and, using "-whatIf" appears to work, i'e. the output is PS C:\WINDOWS\system32> foreach ($t in $targetVMs) {     if ($t.ResourcePool -Like "Resources") {         Write-Host $t.Name "is currently in Resource Pool " -NoNewline         Write-Host -ForegroundColor Red $t.ResourcePool - $t.ResourcePoolId         Write-Host Moving $t.name "from " -NoNewline         Write-Host -ForegroundColor Red $t.ResourcePool -NoNewline         Write-Host " to " -NoNewline         write-host -ForegroundColor Green $targetRP.Name - $targetRP.Id         Move-VM -vm $t -Destination $finalRP -WhatIf         write-host     } } MyTestVM is currently in Resource Pool Resources - ResourcePool-resgroup-53 Moving MyTestMv from Resources to RP-Low - ResourcePool-resgroup-2663 What if: Performing the operation "Move-VM" on target "Moving VM 'MyTestVM'". However, if i # out the "-WhatIf", i get the following error MyTestVM is currently in Resource Pool Resources - ResourcePool-resgroup-53 Moving MyTestMv from Resources to RP-Low - ResourcePool-resgroup-2663 Move-VM : 13/01/2020 15:16:53    Move-VM        Object reference not set to an instance of an object.    At line:9 char:9 +         Move-VM -vm $t -Destination $finalRP #-WhatIf +         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~     + CategoryInfo          : NotSpecified: (:) [Move-VM], VimException     + FullyQualifiedErrorId : Core_BaseCmdlet_UnknownError,VMware.VimAutomation.ViCore.Cmdlets.Commands.MoveVM below is the amended code $clusterName = Read-Host "Enter the name of the target Cluster" $targetCluster = Get-Cluster -Name $clusterName $RPname = Read-Host "Enter the name of the destination Resource Pool" $targetRP = $targetCluster | Get-ResourcePool -Name $RPname $targetVMs = $null $targetVMs = $targetCluster | Get-VM MyTestVM $targetVMs | select Name, PowerState, ResourcePool, ResourcePoolId | Export-Excel foreach ($t in $targetVMs) {     if ($t.ResourcePool -Like "Resources") {         Write-Host $t.Name "is currently in Resource Pool " -NoNewline         Write-Host -ForegroundColor Red $t.ResourcePool - $t.ResourcePoolId         Write-Host Moving $t.name "from " -NoNewline         Write-Host -ForegroundColor Red $t.ResourcePool -NoNewline         Write-Host " to " -NoNewline         write-host -ForegroundColor Green $targetRP.Name - $targetRP.Id         Move-VM -vm $t -Destination $finalRP #-WhatIf         write-host     } }
Trying to prioritize VM's in a large Cluster using Resource Pools. Currently all VM's are in the default "Resources" pool. Additional Resource Pools have been created and priorities set to low, ... See more...
Trying to prioritize VM's in a large Cluster using Resource Pools. Currently all VM's are in the default "Resources" pool. Additional Resource Pools have been created and priorities set to low, medium and high. I've come up with the below script and it worked for approx 50% of the VM's but, i'm getting the following error on all remaining VM's Move-VM : Cannot bind parameter 'VM'. Cannot convert the "" value of type "System.Management.Automation.PSCustomObject" to type "VMware.VimAutomation.ViCore.Types.V1.Inventory.VirtualMachine". At line:9 char:17 +         Move-VM $t -Destination $finalRP +                 ~~     + CategoryInfo          : InvalidArgument: (:) [Move-VM], ParameterBindingException     + FullyQualifiedErrorId : CannotConvertArgumentNoMessage,VMware.VimAutomation.ViCore.Cmdlets.Commands.MoveVM Any help with the below would be appreciated. It's just me using this for now so i'm not too worried about checking for correct Cluster/ResourcePool names at this point but, i will be adding that in once the move-vm piece is working. $clusterName = Read-Host "Enter the name of the target Cluster" $targetCluster = Get-Cluster -Name $clusterName $RPname = Read-Host "Enter the name of the destination Resource Pool" $targetRP = $targetCluster | Get-ResourcePool -Name $RPname | select name, Id $finalRP = Get-ResourcePool | where {$_.Id -like $targetRP.Id} $targetVMs = $null $targetVMs = $targetCluster | Get-VM | select Name, ResourcePool, ResourcePoolId | sort Name $targetVMs | Export-Excel foreach ($t in $targetVMs) {     if ($t.ResourcePool -Like "Resources") {         Write-Host $t.Name "is currently in Resource Pool " -NoNewline         Write-Host -ForegroundColor Red $t.ResourcePool - $t.ResourcePoolid         Write-Host Moving $t.name "from " -NoNewline         Write-Host -ForegroundColor Red $t.ResourcePool -NoNewline         Write-Host " to " -NoNewline         write-host -ForegroundColor Green $targetRP.Name - $targetRP.Id         Move-VM $t -Destination $finalRP         write-host     } }
Thanks Luc, can't believe i didn't try that :smileyblush: :smileyconfused: I'm off to get a coffee
Hi All, I've an issue at the moment where, when you select a Host within the VC, go to Configure/Hardware/Processors the Service Tag / Serial Number field displays "To be filled by O.E.M." I ... See more...
Hi All, I've an issue at the moment where, when you select a Host within the VC, go to Configure/Hardware/Processors the Service Tag / Serial Number field displays "To be filled by O.E.M." I need to capture Serial Number / Service Tag information for Asset Management. I can get the Serial Number by connecting directly to a Host and issuing Get-VMHost HostName.MyDomain.com | Select-Object Name,Manufacturer, Model, @{N="Serial Number";E={(Get-EsxCli -VMHost $_.Name).hardware.platform.get().SerialNumber}}, PowerState | Format-Table -AutoSize With Thousands of Hosts though, i'd prefer to get this from a single login to the VC. From a connection to the VC, I've searched all the Get-VMhost properties and can't find the Serial Number / Service Tag. I've also piped get-VMhost into get-view, there are more properties available here but for me it's like searching for a needle in a haystack. Any help would be appreciated Thanks
That worked perfectly Luc, thanks. below is the working code for anyone who wants it. thanks also to the original poster for starting this off function Check-Credentials {    <#    .SYNO... See more...
That worked perfectly Luc, thanks. below is the working code for anyone who wants it. thanks also to the original poster for starting this off function Check-Credentials {    <#    .SYNOPSIS   Checks ESXi Host Credentials    .DESCRIPTION   Accepts Username,Password & Hostname parameters, attempts to login to the Host using provided credentials,   If only Username and Password are passed, attempts to login to all ESXi Hosts in the VC. Creates logfile with results    .EXAMPLE   Check-Credentials root password    .EXAMPLE   Check-Credentials root password1,password2    .EXAMPLE   Check-Credentials root password MyESXiHost.mycorp.com    .EXAMPLE   Check-Credentials root password3,password4 MyESXiHost.mycorp.com   #>   [CmdletBinding()]    param (   [Parameter(Mandatory=$true, Position=0)]   [string] $user,   [Parameter(Mandatory=$true, Position=1)]   [string[]] $passwds,   [Parameter(Mandatory=$false, Position=2)]   [string[]] $ESXiHost   )    $Logfile = "C:\Temp\CredentialLog-" + (Get-Date -Format yyyy-MMM-dd-HHmm) + ".log"    Function LogWrite {    Param (   [string]$logstring   )    Add-content $Logfile -value $logstring   }    Get-VMHost -PipelineVariable esx | where { ($ESXiHost -and $ESXiHost -contains $_.Name) -or -not $ESXiHost } | ForEach-Object -Process {    foreach ($passwd in $passwds){    try {    Connect-VIServer -Server $esx.Name -User $user -Password $passwd -ErrorAction Stop | Out-Null   LogWrite "Host $($esx.Name) password $passwd is correct"    Disconnect-VIServer -Server $esx.Name -Confirm:$false   }    catch {   LogWrite "Host $($esx.Name) password $passwd failed"   }   }   } Invoke-Item $Logfile }
Thanks Luc, I don't understand the syntax you've given but, on the commute home today i think i may have thought of a different approach. I'm going to try checking if the $ESXiHost variable i... See more...
Thanks Luc, I don't understand the syntax you've given but, on the commute home today i think i may have thought of a different approach. I'm going to try checking if the $ESXiHost variable is empty, if empty, proceed with "Get-VMHost -PipelineVariable esx" if not empty, try using "foreach ($h in $ESXiHost){...} To check for an empty/null variable i think "if (!$ESXiHOST)..." should work. I'll try it when i get to the office in the morning Thanks again
HI Guys, sorry to be revisiting a thread that's been marked as correct already but, this looks like a really handy bit of code and i was trying (without success) to modify it so that you can... See more...
HI Guys, sorry to be revisiting a thread that's been marked as correct already but, this looks like a really handy bit of code and i was trying (without success) to modify it so that you can give two parameters (username + password) and it will check all Hosts in a VC - you have this working already you can give 3 parameters (username, Password + Hostname) and it will check only that host (or list of hosts) I haven't been able to figure out how to change the "Get-VMHost -PipelineVariable esx | ForEach-Object" line so that it checks for the $ESXiHost variable. If the variable has been passed, only check those hosts, if it has not been passed, check all Hosts. I've written a second function what works for the 3 variable option but, having two functions to do basically the same thing seems redundant and i suspect PowerCLI should be able to do this in one ? function Check-Credentials {     <#     .SYNOPSIS     Checks ESXi Host Credentials     .DESCRIPTION     Accepts Username,Password & Hostname parameters, attempts to login to the Host using provided credentials,     If only Username and Password are passed, attempts to login to all ESXi Hosts in the VC. Creates logfile with results     .EXAMPLE     Check-Credentials root password 'MyEsxiHost.mycorp.com'      .EXAMPLE      Check-Credentials root password     #>     [CmdletBinding()]     param (         [Parameter(Mandatory=$true, Position=0)]         [string] $user,         [Parameter(Mandatory=$true, Position=1)]         [string[]] $passwds,         [Parameter(Mandatory=$false, Position=2)]         [string[]] $ESXiHost     )     $Logfile = "C:\Temp\CredentialLog-" + (Get-Date -Format yyyy-MMM-dd-HHmm) + ".log"     Function LogWrite {         Param (             [string]$logstring         )         Add-content $Logfile -value $logstring     }     Get-VMHost -PipelineVariable esx | ForEach-Object -Process {         foreach ($passwd in $passwds){             try {                 Connect-VIServer -Server $esx.Name -User $user -Password $passwd -ErrorAction Stop | Out-Null                 LogWrite "Host $($esx.Name) password $passwd is correct"                 Disconnect-VIServer -Server $esx.Name -Confirm:$false             }             catch {                 LogWrite "Host $($esx.Name) password $passwd failed"             }         }     } Invoke-Item $Logfile } Thanks in advance !
Thanks Luc, That fixed that issue for me. Below is the code if anyone wants it <#     Requirement: ImportExcel module     Verify that ImportExcel is installed with 'Get-Module -ListAvailabl... See more...
Thanks Luc, That fixed that issue for me. Below is the code if anyone wants it <#     Requirement: ImportExcel module     Verify that ImportExcel is installed with 'Get-Module -ListAvailable ImportExcel'     If not installed, install with 'Find-Module ImportExcel | Install-Module'     Get available commands with 'Get-Command -Module ImportExcel' #> $hash = @{     Path = "C:\Temp\VersionReport.xlsx"     Show = $true;     AutoSize = $true;     AutoFilter = $true;     HideSheet = "Sheet1"     ShowPercent = $true;     PivotTableName = "ESXi Version Detail";     IncludePivotTable = $true;     PivotRows = 'ESXi Version';     PivotData = @{'Count' = 'Sum'};     IncludePivotChart = $true;     ChartType = "PieExploded";     } Remove-Item $hash.Path -ErrorAction Ignore Get-VMHost | Group-Object -Property Version, Build |     select @{N='ESXi Version';E={$_.Name.Split(",")[0]}},     @{N='ESXi Build #';E={$_.Name.Split(",")[1]}},     Count,     @{N='ESXi Name';E={$_.Group.Name -join '|'}} |     Sort-Object 'ESXi Version' |     Export-Excel @hash The above works but, made it difficult to retrieve the Host names. The below is a simplier version that makes it easier to get the Host names from the Pivot Table <#     Requirement: ImportExcel module     Verify that ImportExcel is installed with 'Get-Module -ListAvailable ImportExcel'     If not installed, install with 'Find-Module ImportExcel | Install-Module'     Get available commands with 'Get-Command -Module ImportExcel' #> $ContainsBlanks = New-ConditionalText -ConditionalType ContainsBlanks $hash = @{     Path = "C:\Temp\VersionReport.xlsx"     Show = $true;     AutoSize = $true;     AutoFilter = $true;     ConditionalText = $ContainsBlanks     ShowPercent = $true;     PivotTableName = "ESXi Version Detail";     HideSheet = "Sheet1";     IncludePivotTable = $true;     PivotRows = 'Version';     PivotData = @{'Version' = 'Count'};     IncludePivotChart = $true;     ChartType = "PieExploded";     } Remove-Item $hash.Path -ErrorAction Ignore Get-VMHost |     Select Name, Version, Build |     Sort-Object Name |     Export-Excel @hash
I've had similar issues in te past, for me it was due to how AD was designed /implimented. I was adding Identity Sources for example ACME.COM, EXAMPLE.COM, ... unfortunately, ACME.COM has child... See more...
I've had similar issues in te past, for me it was due to how AD was designed /implimented. I was adding Identity Sources for example ACME.COM, EXAMPLE.COM, ... unfortunately, ACME.COM has child domains that i was unable to see so, couldn't see/add AD Users/Groups. For me, the solution was to create a Machine Account in AD for the vCenter and join it to the domain (then remove the ACME.COM Identity source as it will complain about having more than one source for the same domain) After this, i could add Users/Groups from child.ACME.COM (and search for them). Hope this helps
Hi All, I came across the following discussion and thought it really useful. Script to count host build numbers Is there anyway of adding to the above so that when it exports to Excel, it ... See more...
Hi All, I came across the following discussion and thought it really useful. Script to count host build numbers Is there anyway of adding to the above so that when it exports to Excel, it includes the Version Number (not overly concerned with Build Number) and, the Name of each ESXi Host running that version ? By doing this, if you selected a particular Build Number within Excel, you would see a list of all the Hosts running that version. Here's what i was able to come up with Get-VMHost | Group-Object -Property Build,Version | select @{N='ESXi Version';E={$_.Name.Split(",")[1]}}, @{N='ESXi Name';E={$_.Group.Name}},Count | Export-Excel -now The above works when there's only a single ESXi Host running a particulat version but, if there are more than one host running a version it displays "System.Object[]" in Excel. Without exporting it to Excel, i see the Host Names listed against the Version Number Thanks
thanks, that worked perfectly
Thanks Luc, with your    while ($esx.connectionState -ne "Connected")    {    $esx = Get-VMHost -Name $esx.Name    } would i be ok to remove the Start-Sleep -Seconds 900 Am i corre... See more...
Thanks Luc, with your    while ($esx.connectionState -ne "Connected")    {    $esx = Get-VMHost -Name $esx.Name    } would i be ok to remove the Start-Sleep -Seconds 900 Am i correct in assuming that the script won't move on to the next host in the for Loop until i manually take the current Host out of Maintenance Mode ?
Thanks Luc, i'm not sure i understand your 4th point "your waiting for the ESXi Node to come back will not work". Is there a way of placing a host into MM, rebooting and once it's connected t... See more...
Thanks Luc, i'm not sure i understand your 4th point "your waiting for the ESXi Node to come back will not work". Is there a way of placing a host into MM, rebooting and once it's connected to the vCenter again, exiting MM before moving on to the next host in the Cluster ? i'd prefer to limit the number of Hosts in MM or, rebooting in a Cluster at any one time Regards, Jason
Hi Guys, I need to change the scratch file location on a bunch of ESXi Hosts. A lot of Servers lately are coming with dedicated (small) hard disks for the O/S plus, disks for vSAN. The Default ... See more...
Hi Guys, I need to change the scratch file location on a bunch of ESXi Hosts. A lot of Servers lately are coming with dedicated (small) hard disks for the O/S plus, disks for vSAN. The Default location of the scratch files is, where the O/S is installed. this is causing problems so, i want to move the Scratch files to a vSAN datastore (there may not be a VMFS datastore) I've pieced the following together but would like any input on it before running it on a Production Environment # login to vCenter $table = @() $prefix = ".scratch_" $datastore = Get-Datastore | where {$_.Type -eq "VSAN"} foreach ($ds in $datastore) {     New-PSDrive -Location $ds -Name PSD -PSProvider VimDatastore -Root '' | Out-Null     foreach ($h in ($ds | Get-VMHost)){         $fqdn = $h.Name         $hostName = $fqdn.Split(".")[0].TrimStart("{")         $hostDS = $h | Get-Datastore | where {$_.Type -eq "VSAN"}         $scratchFolder = "$($prefix)$($hostName)"         $tableProp=[ordered]@{             'Host FQDN'=$fqdn             'Host Name'=$hostName             'VSAN DS'= $hostDS             }         # Check to see if a scratch folder for the Host exists on the vSAN DS and create it if needed         $scratchFolderPath = "/vmfs/volumes/$($hostDS.Name)/$scratchFolder"         $scratchFolderPathExists = Test-Path -Path $scratchFolderPath | Out-Null         if (-not ($scratchFolderPathExists)){             New-Item -Path "PSD:\$scratchFolder" -ItemType Directory | Out-Null             }                                 # identify current Scratch Folder Settings         $configuredScratch = $h | Get-AdvancedSetting -Name "ScratchConfig.ConfiguredScratchLocation"         $configuredScratchValue = $configuredScratch.Value         $currentScratch = $h | Get-AdvancedSetting -Name "ScratchConfig.CurrentScratchLocation"         $currentScratchValue = $currentScratch.Value         $tableProp.Add('Current Scratch Value', $currentScratchValue)                 # set new Scratch location         $configuredScratch | Set-AdvancedSetting -Value $scratchFolderPath -Confirm:$false | Out-Null         $tableProp.Add('New Scratch Location',$scratchFolderPath)                 # Place Host in Maintenance mode, reboot, exit Maintenance Mode, move to next Host         Set-VMHost $h -State Maintenance -Evacuate         Restart-VMHost $h         Start-Sleep -Seconds 900         $connectionState = Get-VMHost $h.ConnectionState         while ($connectionState -eq "Maintenance") {            Set-VMHost $h -state Connected            }         $table += New-Object -TypeName psobject -Property $tableProp     }         Remove-PSDrive -Name PSD -Confirm:$false } $table | Sort-Object -Property "Host FQDN" | ft -AutoSize
Thanks Luc, I did miss your 2gb explanation in your last comment. as a powerdown isn't needed with svMotion I'll remove that freom the code thank you again, Jason