Cannot convert 'System.String{}' to the type 'System.String'

This topic contains 1 reply, has 2 voices, and was last updated by Profile photo of Olaf Soyk Olaf Soyk 4 months, 3 weeks ago.

  • Author
    Posts
  • #61006
    Profile photo of rshotts
    rshotts
    Participant

    I have a script to pull back various system level information and am stuck with roles/features. I structured the syntax like other sections but this section has a conditional for just installed objects, not sure if that is messing up my overall syntax.
    I get : WARNING: Cannot convert 'System.String[]' to the type 'System.String' required by parameter 'ComputerName'. Specified method is not supported.

    I have tried various other styles and get a host of different messages, this one just seems like the easiest to figure out, but I cannot.

    
            Write-Verbose "Collecting Role/Feature information"
            
            try
            {
    #            $role = Invoke-Command -ComputerName  $ComputerName  -ErrorAction STOP $_ -Verbose -ScriptBlock{get-windowsfeature | ?{$_.installed -eq $true -and $_.featuretype -eq 'Role'} } 
    #            $role = get-windowsfeature -ComputerName  $ComputerName -ErrorAction STOP | ?{$_.installed -eq $true -and $_.featuretype -eq 'Role'}    
    #            $role =  Invoke-Command -ComputerName  $ComputerName  get-windowsfeature -ErrorAction STOP | ?{$_.installed -eq $true -and $_.featuretype -eq 'Role'} 
    #	     $role =  Invoke-Command -ComputerName  $ComputerName Get-WindowsFeature  -ErrorAction STOP 
    #         $role = Get-WindowsFeature | ? {$_.Installed -match “True” -and $_.featuretype -eq 'Role'} | Select-Object DisplayName, Installed, FeatureType
    #         $role = Get-WindowsFeature | ? {$_.Installed -match “True” } | Select-Object DisplayName, Installed, FeatureType
             $role = Get-WindowsFeature -ComputerName $ComputerName -ErrorAction STOP | where-object {$_.Installed -match “True” } | Select-Object DisplayName, Installed, FeatureType
                
                $htmlbody += $role | ConvertTo-Html -Fragment
                $htmlbody += $spacer 
            
            }
            catch
            {
                Write-Warning $_.Exception.Message
                $htmlbody += "An error was encountered. $($_.Exception.Message)"
                $htmlbody += $spacer
            }
    
  • #61008
    Profile photo of Olaf Soyk
    Olaf Soyk
    Participant

    Obviously your variable $ComputerName contains more than one computer name while the cmdlet you pass this variable to accepts only single computers.

You must be logged in to reply to this topic.