VMware Cloud Community
Haribcs
Contributor
Contributor

Powershell Array

Hi Luc,

Need your help in redcuing the script run time. I've created the below script to combine powernsx and powercli to get the report that i wanted, But it is taking hours to complete the report. Can this be tweaked by changing anything?

I have 8 Nsx server so it is taking 9hrs to complete. 😞

$report =@()
$cred = get-credential
Get-Module -ListAvailable | where{$_.Name -match "vmware*"} | Import-Module
Import-Module PowerNSX

foreach ($test in $nsx){
Connect-NsxServer $test -Username admin -Password xxxxxx -VICred $cred
$sectags = Get-NsxSecurityTag |where {$_.vmcount -ne "0"} | foreach{$_.name}
foreach ($tag in $sectags){
$data = Get-NsxSecurityTag -Name $tag | Get-NsxSecurityTagAssignment | select Virtualmachine
$data | Add-Member -Name "Security Tag" -Value $tag -MemberType NoteProperty
$data | Add-Member -Name "Server" -Value $test -MemberType NoteProperty
$report += $data
}
Disconnect-NsxServer
}

0 Kudos
1 Reply
LucD
Leadership
Leadership

I'm afraid that I don't know the PowerNSX module that well.

But I think you could save on a number of Get-NsxSecurityTag calls like this.

Don't know how much difference that makes in total execution time.

$report =@()

$cred = Get-Credential

Get-Module -Name VMware* -ListAvailable | Import-Module

Import-Module PowerNSX

foreach ($test in $nsx){

    Connect-NsxServer $test -Username admin -Password xxxxxx -VICred $cred

    foreach($tag in (Get-NsxSecurityTag | Where{$_.VMCount -ne 0})){

        $data = $tag | Get-NsxSecurityTagAssignment | select Virtualmachine

        $data | Add-Member -Name "Security Tag" -Value $tag -MemberType NoteProperty

        $data | Add-Member -Name "Server" -Value $test -MemberType NoteProperty

        $report += $data

    }

    Disconnect-NsxServer

}


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

0 Kudos