VMware Cloud Community
Al_
Enthusiast
Enthusiast

Attempt to process VM rightsizing based on VMware Tools status fails

Set-Location -Path C:\Users\*********\AppData\Roaming\VMware\credstore\

Get-VICredentialStoreItem -File C:\Users\******\AppData\Roaming\VMware\credstore\vicredentials.xml | %{
Connect-VIServer -Server $_.host -User $_.User -Password $_.Password
}

Get-VICredentialStoreItem -File C:\Users\******\AppData\Roaming\VMware\credstore\custom\vicredentials.xml | %{
Connect-OMServer -Server $_.host -User $_.User -Password $_.Password
}

Set-Location -Path D:\***\***********\ | git pull

[array]$sourcefiles=Get-ChildItem D:\****\*************\*.csv | select -expand fullname

ForEach ($csv in $sourcefiles)

{

Write-Host $csv

$AgencyDBInfo = Import-CSV $csv

ForEach ($item in $AgencyDBInfo)

{

$Name = $item.Name

[array]$ToolsStatus = Get-VM -Name $Name | Select Name,@{N="Tools Status";E={$_.ExtensionData.Guest.ToolsStatus}}

ForEach ($object in $ToolsStatus)

{

$srv = $object.name

$tools = $object."Tools Status"

if ($tools -contains "toolsOk" -or "toolsOld")

{

Write-Host "Rightsizing " $srv, $tools
#Get-VM -Name $Name | Get-OMResource | Apply-OMRightsizing -ViewOnly

}

else {Write-Host "Skipping " $srv, $tools}

}

}

}

Set-Location -Path D:\*****\**********\ | git add .;git commit -m "rightsize reports";git pull;git push

results in this output:

2021-05-20T15:30:20.5643902Z D:\ECE\ece-vcenter-vrops-rightsizing-source-files\****-group-1&2.csv
2021-05-20T15:30:21.6765147Z Rightsizing ****apd001 toolsOk
2021-05-20T15:30:22.3906796Z Rightsizing ****apd002 toolsOk
2021-05-20T15:30:23.1178918Z Rightsizing ****apd003 toolsNotInstalled
2021-05-20T15:30:23.8433633Z Rightsizing ****apd005 toolsOk
2021-05-20T15:30:24.4787689Z Rightsizing ****apd006 toolsNotRunning
2021-05-20T15:30:25.1173274Z Rightsizing ****apd007 toolsNotRunning
2021-05-20T15:30:25.7684386Z Rightsizing ****apd008 toolsNotRunning
2021-05-20T15:30:26.4195042Z Rightsizing ****APD02 toolsOld
2021-05-20T15:30:27.0892736Z Rightsizing ****APD03 toolsOk
2021-05-20T15:30:27.7404714Z Rightsizing ****apt002 toolsOk
2021-05-20T15:30:28.3749351Z Rightsizing ****apt003 toolsOk
2021-05-20T15:30:29.0336762Z Rightsizing ****apt004 toolsOk
2021-05-20T15:30:29.6671475Z Rightsizing ****apt005 toolsOk
2021-05-20T15:30:30.3591811Z Rightsizing ****apt006 toolsOk
2021-05-20T15:30:31.0146126Z Rightsizing ****apt007 toolsNotRunning
2021-05-20T15:30:31.7198241Z Rightsizing ****apt008 toolsNotInstalled
2021-05-20T15:30:32.3585491Z Rightsizing ****APT01 toolsOk
2021-05-20T15:30:33.0551995Z Rightsizing ****apt010 toolsOk
2021-05-20T15:30:33.7226811Z Rightsizing ****APT02 toolsOk
 
Should be "Skipping" on tools not installed or tools not running...
0 Kudos
2 Replies
LucD
Leadership
Leadership

Try with

if ("toolsOk","toolsOld" -contains $tools)


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
Al_
Enthusiast
Enthusiast

Yes, that solved it. Thank you!

Skipping ****sapp3 toolsNotRunning
Skipping ****sapp4 toolsNotRunning
Skipping ****sweb3 toolsNotRunning
Skipping ****sweb4 toolsNotRunning
Rightsizing ****dwcapp00 toolsOk
Rightsizing ****dwcapp01 toolsOk
Rightsizing ****dwcsql00 toolsOk
Rightsizing ****dwcsql01 toolsOk
Rightsizing ****dwcweb00 toolsOk
Rightsizing ****dwcweb01 toolsOk
Rightsizing ****dwcweb02 toolsOk
Rightsizing ****ISSADMIN01 toolsOld
Rightsizing ****ISSAPP1 toolsOk
Rightsizing ****isssql01 toolsOk
Rightsizing ****SQL20 toolsOk
Rightsizing ****SQL25 toolsOk
Rightsizing ****sql26 toolsOk
Rightsizing ****SQL4 toolsOk
Rightsizing ****SQL5 toolsOk

0 Kudos