0 Replies Latest reply on Mar 9, 2017 8:27 AM by charlie_tech

    Error when using export-csv cmdlet

    charlie_tech Lurker

      Hello everyone,

       

      I am trying to run this script(attached) to check STIG status. I can run it fine without the export-csv cmdlet. But, I need to be able to put this information into some kind of form of documentation such as a text or csv file. But whenever try, I get an error "Cannot bind argument to Paramenter 'Input Object' because it is null. PLEASE HELP me fix this issue. Thanks everyone.

       

      #prompt for vCenter name and set variable

      $vcenter=(Read-Host "Enter the name of the VCenter server where the VM you want to check the STIG is located").ToLower()

       

       

      #prompt for Virtual Machine name

      $vmName=(Read-Host "Enter the name of the VM you want to check the STIG").ToLower()

       

       

      #connect to vCenter server

      Write-Host Connecting to vCenter Server `n

      Connect-VIServer $vcenter

       

      Write-Host `n`nConnected to vCenter Server $vcenter`n

       

      #display STIG settings

      Write-Host $ColHeader

       

              $check = $ExtraOptionsArray | ForEach-Object {

       

                  [string]$OptName = $_

       

              $OptionData = (Get-VM -Name $vmName).ExtensionData.Config.ExtraConfig | select Key,Value | where {$_.Key -eq $OptName}

       

              $DisName = $OptionData.key

              $OptValue = $OptionData.value

       

              $ReqOptValue = $ExtraOptionsReqHash[$OptName]

       

              If ($OptValue -eq $ReqOptValue)

                  {

                  $StatsFinal = " PASSED"

                  }

              Else

                  {

                  $StatsFinal = "*FAILED"

                  }

       

                #****************** Test if File exists & output data to text **************

       

              $fscrnoutput = ("{0,-25} {1,-40} {2,-10} {3,-10}" -f $vmName,": $OptName",": $OptValue",": $StatsFinal")

       

                   Write-Host $fscrnoutput

                       

                 #************************************************************************

          

              }

       

      $check | export-csv C:\STIGcheck.csv

       

      #disconnects from all VCenter servers without a prompt

      Disconnect-VIServer * -Force -confirm:$false