VMware Cloud Community
uswbnc53
Enthusiast
Enthusiast

vDS Report Generation

I'm trying to populate vDS settings in a health check script and am receiving the below error. It seems to be failing on joining the values into the object for the report. Just seems to be failing on this portion of the script. All the other sections are working fine.

$GetDS = get-virtualswitch -Distributed 
$GetDS | % {$_.Name} | ForEach-Object { 
$GetDS1 = $_
get-virtualswitch -Distributed -Name $GetDS1 | Get-View | % {$_.PortGroup} | ForEach-Object {
$GetDvSSecPol1 = $_
$GetDvSName = $GetDvSSecPol1 | % {Get-View -Id $_} | %{$_.Name} 
$DvSallowPromSec = $GetDvSSecPol1 | % {Get-View -Id $_} | `
Select Name, `
@{N="AllowPromiscuous";E={$_.Config.DefaultPortConfig.SecurityPolicy.AllowPromiscuous.Value}}
$DvSallowPromiscuous = $DvSallowPromSec | where-object {$_.Name -NotLike "*DVUplinks"} 
$DvSallowPromiscuous1 =  $DvSallowPromiscuous | % {$_.AllowPromiscuous} 

$SecVal= "DvS Promiscuous Mode"

    if ($DvSallowPromiscuous1 -eq ""){
        $text = "Compliant"
    }
    else{ 
        $text = "Not Compliant"
    }
    New-Object PSObject -Property @{
        "Date/Time" = $Date
    Hostname = $GetVMHost
    "ISeC Section" = $Num
    Setting = [string]::Join(',',"$GetDvSName $SecVal")
    Value = [string]::Join(',',$DvSallowPromiscuous1)
    Compliancy = $text
    } } }

Transcript started, output file is healthcheck_Log_01162013.txt
Exception calling "Join" with "2" argument(s): "Value cannot be null.
Parameter name: value"
At C:\scripts\HC_Execution_Function.ps1:201 char:24
+     Value = [string]::Join <<<< (',',$DvSallowPromiscuous1)
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : DotNetMethodException

Exception calling "Join" with "2" argument(s): "Value cannot be null.
Parameter name: value"
At C:\scripts\HC_Execution_Function.ps1:224 char:24
+     Value = [string]::Join <<<< (',',$DvSallowForged1)
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : DotNetMethodException

Reply
0 Kudos
3 Replies
LucD
Leadership
Leadership

It looks as if $DvSallowPromiscuous1 equals $null for a specific dvSwitch.

The Join function doesn't accept that.

Check how you populate that variable or build in a test where you first check for a $null value before calling the Join function


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

Reply
0 Kudos
uswbnc53
Enthusiast
Enthusiast

Hey Luc,

I see how the $null value is being generated now. I'm trying to bypass the DVUplinks and only display the DvPort Group policies.

I was attempting to use $DvSallowPromSec | where-object {$_.Name -NotLike "*DVUplinks"} so the DVUplinks are not looped through when checking the policy setting, but it appears the $null value is still being seen.

Any suggestions on how to change this bit of code? I tried changing it to a IF ELSE statement, but its not working.

$DvSallowPromSec = $GetDvSSecPol1 | % {Get-View -Id $_} | `
Select Name, `
@{N="AllowPromiscuous";E={$_.Config.DefaultPortConfig.SecurityPolicy.AllowPromiscuous.Value}}
$DvSallowPromiscuous = $DvSallowPromSec | where-object {$_.Name -NotLike "*DVUplinks"}
$DvSallowPromiscuous1 =  $DvSallowPromSec | % {$_.AllowPromiscuous}

Reply
0 Kudos
LucD
Leadership
Leadership

The variable $DvSallowPromiscuous will be $null when the Where-clause is not successfull

$DvSallowPromiscuous = $DvSallowPromSec | where-object {$_.Name -NotLike "*DVUplinks"}

In that case you should use an If-statement in the New-Object sequence.

Something like this

     New-Object PSObject -Property @{
            "Date/Time" = $Date
            Hostname = $GetVMHost
            "ISeC Section" = $Num
            Setting = [string]::Join(',',"$GetDvSName $SecVal")
            Value = &{
                if($DvSallowPromiscuous){
                [string]::Join(',',$DvSallowPromiscuous1)
                } else {"na"}}
            Compliancy = $text
        }

When $DvSallowPromiscuous is $null, the Value property will now contain the text "na", and the code will not try to execute the Join function


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

Reply
0 Kudos