Author Posts

December 30, 2016 at 10:25 pm

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
        }

December 30, 2016 at 10:38 pm

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