Parseing the output from a "Microsoft.Dism.Commands.AdvancedFeatureObject"

Robert Merritt 1 Reputation point
2022-08-16T17:28:08.577+00:00

I an trying to get information on a bunch of machines as to whether they have smb1 enabled

$x=Get-WindowsOptionalFeature -Online -FeatureName SMB1Protocol
$y=$x.ToString()|select-string -Pattern "State"
write-host $x.ToString()
write-host $y

$y should be what I want but instead I get Microsoft.Dism.Commands.AdvancedFeatureObject
I tried to .ToString(0 it but no luck how do I extract the 5th line of this output?

FeatureName : SMB1Protocol
DisplayName : SMB 1.0/CIFS File Sharing Support
Description : Support for the SMB 1.0/CIFS file sharing protocol, and the Computer Browser protocol.
RestartRequired : Possible
State : Disabled
CustomProperties :
ServerComponent\Description : Support for the SMB 1.0/CIFS file sharing protocol, and the Computer Browser protocol.
ServerComponent\DisplayName : SMB 1.0/CIFS File Sharing Support
ServerComponent\Id : 487
ServerComponent\Type : Feature
ServerComponent\UniqueName : FS-SMB1
ServerComponent\Deploys\Update\Name : SMB1Protocol

Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,363 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Stephen Gardiner 0 Reputation points
    2023-06-05T13:42:16.1166667+00:00

    Sorry this is old but as came up in my search for state outputs

    $x=(Get-WindowsOptionalFeature -Online -FeatureName SMB1Protocol).State

    Or

    $x=Get-WindowsOptionalFeature -Online -FeatureName SMB1Protocol | Select -ExpandProperty State

    Or

    If you want multiple selections

    $x = Get-WindowsOptionalFeature -Online -FeatureName SMB1Protocol

    $x.State

    $x.RestartRequired

    If you wanted to return more functions

    I like to use two possible ways when checking what a variable holds

    $x | GM

    $x | Select *

    Both outputs will show information on what the variable holds.

    hth

    0 comments No comments