VMware Cloud Community
piercj2
Enthusiast
Enthusiast

Delete VM's and output results - PART 2

 
Tags (2)
0 Kudos
8 Replies
LucD
Leadership
Leadership

That means that the value in that column is an array.

An easy way to convert an array to a single string is with the -join operator.

$vmProperty.Add("CI Status", (Get-CIStatus) -join '|')


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

0 Kudos
piercj2
Enthusiast
Enthusiast

deleted
0 Kudos
LucD
Leadership
Leadership

The user that established the vSphere Server connection can be found with

($global:defaultVIServer).User

The user in whose session the script is running can be found with

$env:USERNAME

Your condition should probably look like this (if I understood the intention correctly)

if (($item.'powered off for (Days)' -ge 30) -and ('Installed','Build','In Maintenance' -notcontains $item.'CI Status')) {


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

0 Kudos
piercj2
Enthusiast
Enthusiast

deleted

0 Kudos
LucD
Leadership
Leadership

Not exactly sure what exactly you mean, but if it is the output coming from Write-Output in that function, you should enclose the variables in $()

Whenever you want to substitute a property of an object in a string, you have to enclose it.

Like this

Write-Host -ForegroundColor DarkMagenta "$($item.'VM Name') can be deleted"


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

piercj2
Enthusiast
Enthusiast

deleted

0 Kudos
piercj2
Enthusiast
Enthusiast

deleted

0 Kudos
LucD
Leadership
Leadership

I'm not that versed in SQL, but isn't that Invoke-SqlCmd error caused by missing quotes around the value?

$cmdbQuery = "USE $cmdbDatabase

        SELECT * FROM [myDatabase].[dbo].CMDB_CI

        WHERE Name='$vmName'"


Since you are using the ordered hash table $vmProperty in multiple functions, you will have to make that a variable in the Script scope as well.

Replace all $vmProperty occurrences with $script:vmProperty, and give it another go.


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

0 Kudos