VMware Cloud Community
pamiller21
Enthusiast
Enthusiast
Jump to solution

Report For specific NSXT Tag Phrase

Hey all,
I have a script that shows me any VM that has a NSXT Tag containing the phrase 'locked' in it, but I need to exclude 1 VM from the report.

#############################
# Connect to vCenter #
#############################
Import-Module -Name VMware.PowerCLI
Set-PowerCLIConfiguration -DisplayDeprecationWarnings $false -InvalidCertificateAction ignore -confirm:$false
$vc = 'URL'
$Cred = Import-Clixml /home/scripts/creds/creds.xml

Connect-VIServer $VC -Credential $Cred

#############################
# Connect to NSX-T #
#############################
Import-Module -Name VMware.PowerCLI
Import-Module PowerNSX
Set-PowerCLIConfiguration -DisplayDeprecationWarnings $false -InvalidCertificateAction ignore -confirm:$false
$NSXCred = Import-Clixml /home/scripts/creds/nsxt.xml
$skipcertcheck = $true
$AuthMethod = “Basic”
$NSXMgr = ”URL”
$policyapi = "/policy/api/v1"
$base_url = ( "https://" + $NSXMgr + $policyapi )

$endpoint = "/infra/realized-state/virtual-machines"
$report = Invoke-restmethod -Uri ( $base_url + $EndPoint ) -Method GET -Credential $NSXCred -SkipCertificateCheck: $skipcertcheck -Authentication: $AuthMethod

#############################
# Variables #
#############################
$date=Get-Date -format "yyyy-MMM-d"
$datetime=Get-Date
$filelocation="\var\www\Test-VMs\TEST-$date.htm"

#############################
# Content #
#############################
$report = $Report.Results | where-object {$_.tags -like '*Locked*' -Notlike 'vmware-ioinsight'} | Select-Object display_name

#############################
# Add Text to the HTML file #
#############################
$report | ConvertTo-Html –title "Testing VMs" –body "<H1>Testing VMs</H1>" -head "<link rel='stylesheet' href='style.css' type='text/css' />" | Out-File $filelocation
ConvertTo-Html –title "Testing VMs" –body "<H4>Date and time</H4>",$datetime -head "<link rel='stylesheet' href='style.css' type='text/css' />" | Out-File -Append $filelocation
ConvertTo-Html –title "Testing VMs" –body "<H4>VM Count</H4>",$report.Count -head "<link rel='stylesheet' href='style.css' type='text/css' />" | Out-File -Append $filelocation

##############################
# Disconnect session from VC #
##############################
disconnect-viserver -confirm:$false

0 Kudos
1 Solution

Accepted Solutions
Zsoldier
Expert
Expert
Jump to solution

$report = $Report.Results | where-object {$_.tags -like '*Locked*' -and $_.display_name -notmatch 'vmware-ioinsight'} | Select-Object display_name

 

Try this.  Also, still planning on answering your other question, but more involved.

Chris Nakagaki (中垣浩一)
Blog: https://tech.zsoldier.com
Twitter: @zsoldier

View solution in original post

0 Kudos
1 Reply
Zsoldier
Expert
Expert
Jump to solution

$report = $Report.Results | where-object {$_.tags -like '*Locked*' -and $_.display_name -notmatch 'vmware-ioinsight'} | Select-Object display_name

 

Try this.  Also, still planning on answering your other question, but more involved.

Chris Nakagaki (中垣浩一)
Blog: https://tech.zsoldier.com
Twitter: @zsoldier
0 Kudos