VMware Cloud Community
ganapa2000
Hot Shot
Hot Shot
Jump to solution

Add-Member : Cannot bind argument to parameter 'InputObject' because it is null.

Hi,

I am trying to validate the esxi passwords and trying as below.

connect-viserver 10.10.10.10

Get-VMHost | select @{n='ESX_Host';e={$_.Name}} | sort ESX_Host | Export-Excel -Path ".\ESX_Host_List.xlsx" -WorkSheetname Host_List

disconnect-viserver -server * -force -confirm:$false

$user = "root"

$pswd = "password"

Import-Excel -Path ".\ESX_Host_List.xlsx" -PipelineVariable row |

ForEach-Object -Process {

   try

   {

   Connect-VIServer -Server $row.ESX_Host -User $user -Password $pswd -ErrorAction Stop | Out-Null

   Disconnect-VIServer -Server $row.ESX_Host -Confirm:$false

   $result = 'Password_Validation_Success'

   }

   catch

   {

   $result = 'Password_Validation_Failed'

   }

   $row | Add-Member -MemberType NoteProperty -Name 'Password_Validation' -Value $result -PassThru

} | Export-Excel -Path ".\ESX_Host_Pass_Validation_Result.xlsx" -WorkSheetname Host_Password_Validation

I am getting the below error

Add-Member : Cannot bind argument to parameter 'InputObject' because it is null.

At D:\Root_Password_Validation\2_validate_root_password.ps1:19 char:11

+    $row | Add-Member -MemberType NoteProperty -Name 'Password_Validat ...

+           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    + CategoryInfo          : InvalidData: (:) [Add-Member], ParameterBindingValidationException

    + FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Commands.AddMemberCo

   mmand

Please help!!!

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

Oops, I missed that.

Seems that Import-Excel doesn't play nice with the PipelineVariable parameter.

Try the old fashioned way

connect-viserver 10.10.10.10

Get-VMHost | select @{n='ESX_Host';e={$_.Name}} |

sort ESX_Host |

Export-Excel -Path ".\ESX_Host_List.xlsx" -WorkSheetname Host_List

Disconnect-VIServer -server * -force -confirm:$false

$user = "root"

$pswd = "password"

Import-Excel -Path ".\ESX_Host_List.xlsx" |

ForEach-Object -Process {

   $row = $_

   try

   {

    Connect-VIServer -Server $row.ESX_Host -User $user -Password $pswd -ErrorAction Stop | Out-Null

    Disconnect-VIServer -Server $row.ESX_Host -Confirm:$false

    $result = 'Password_Validation_Success'

   }

   catch

   {

    $result = 'Password_Validation_Failed'

   }

   $row | Add-Member -MemberType NoteProperty -Name 'Password_Validation' -Value $result -PassThru

} | Export-Excel -Path ".\ESX_Host_Pass_Validation_Result.xlsx" -WorkSheetname Host_Password_Validation


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

View solution in original post

0 Kudos
4 Replies
LucD
Leadership
Leadership
Jump to solution

That could be an empty line in your CSV file, or you PS version is to old (and doesn't accept the PipelineVariable parameter).

Check with $PSVersionTable.


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

0 Kudos
ganapa2000
Hot Shot
Hot Shot
Jump to solution

LucD,

I am not using .csv. I am using .xlsx file.

PSVersion                  5.1.18362.145
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Oops, I missed that.

Seems that Import-Excel doesn't play nice with the PipelineVariable parameter.

Try the old fashioned way

connect-viserver 10.10.10.10

Get-VMHost | select @{n='ESX_Host';e={$_.Name}} |

sort ESX_Host |

Export-Excel -Path ".\ESX_Host_List.xlsx" -WorkSheetname Host_List

Disconnect-VIServer -server * -force -confirm:$false

$user = "root"

$pswd = "password"

Import-Excel -Path ".\ESX_Host_List.xlsx" |

ForEach-Object -Process {

   $row = $_

   try

   {

    Connect-VIServer -Server $row.ESX_Host -User $user -Password $pswd -ErrorAction Stop | Out-Null

    Disconnect-VIServer -Server $row.ESX_Host -Confirm:$false

    $result = 'Password_Validation_Success'

   }

   catch

   {

    $result = 'Password_Validation_Failed'

   }

   $row | Add-Member -MemberType NoteProperty -Name 'Password_Validation' -Value $result -PassThru

} | Export-Excel -Path ".\ESX_Host_Pass_Validation_Result.xlsx" -WorkSheetname Host_Password_Validation


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

0 Kudos
ganapa2000
Hot Shot
Hot Shot
Jump to solution

That was perfect, Thank you very much Smiley Happy

0 Kudos