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
}