none
Dism /online /Get-Features with where clause

    Question

  • Is there any method of filtering a DISM statement with a where enabled clause?  I am trying to do a

    Get-ClientFeature|sortstate,name|Format-Table-AutoSize

    from https://psclientmanager.codeplex.com/ but without having to install the function on every computer that I want to run it against.  I have tried

    Dism/online/Get-Featureswhere"state -eq enabled"

    and

    I have tried Dism /online /Get-Features Where-Object {$_.State -match “True”}

    Conversely if I could run the codeplex script against multiple computers, that would also work.
    • Moved by Bill_Stewart Tuesday, November 24, 2015 3:12 PM This is not third-party software support forum
    Thursday, October 1, 2015 1:47 PM

All replies

  • Hi Pinchepooch,

    Any spefic reason for sticking to 'Dism /online /Get-Features' .

    We already have a PowerShell alternative for Windows2012 onwards.

    $Computers = "Comp1","Comp2"
    
    $computers | %{Get-WindowsFeature -Computername $_}

    If being on older versions is the reason, you can parse the info into meaning full data.

    You can't directly use $_ as the output of DISM is not a PowerShell Object but a single 'System.String' like other cmdline tools.

    For getting the data from other computers try this:

    $Computers = "Comp1","Comp2"

    Invoke-Command -ComputerName $Computers {Dism /online /Get-Features}

    #It will be tricky to find id the results though so use this:

    $Computers | %{"`n`n$_------------------"; Invoke-Command -ComputerName $_ {Dism /online /Get-Features}}


    Using the codeplex would require you need to install the module there.

    Adding or removing features with Powershell (or Dism) :

    https://swodniw.wordpress.com/2012/08/28/adding-or-removing-features-with-powershell-or-dism/

    Enable or Disable Windows Features Using DISM:

    https://technet.microsoft.com/en-in/library/hh824822.aspx

    DISM vs. Install-WindowsFeature:

    http://blogs.technet.com/b/server_core/archive/2012/11/05/using-features-on-demand-with-updated-systems-and-patched-images.aspx


    Regards,

    Satyajit

    Please “Vote As Helpful” if you find my contribution useful or “Mark As Answer” if it does answer your question. That will encourage me - and others - to take time out to help you.

    Monday, October 5, 2015 12:07 PM
  • I have a lot of Windows 7/Server 2008 R2 boxes that don't support Get-WindowsFeature, hence the reason to use DISM or the Codeplex option.  We are very picky about installing 3rd party powershell scripts on all computers when most can be run from an admin workstation.  Is there any method to run the codeplex script locally against remote computers without installing it remotely?
    Monday, October 5, 2015 12:35 PM
  • You can use PsRemoting

    Invoke-Command -file myscript.ps1 -computer remotepc


    \_(ツ)_/

    Monday, October 5, 2015 2:22 PM
  • I've written a function that wraps Dism /online /Get-Features. It'll parse the output and makes a collection (a group of objects). Since the function create objects, you'll have the option of using the Where-Object cmdlet to filter what's returned, such as Get-DismFeatures | Where-Object State -eq 'Enabled' -- what you were after to being with.

    Since you're interested in running it remotely, you'll need to get PS Remoting working, as mentioned by jrv and Mike. I'll include an example of taking the function to the remote computer, which may be helpful, as well.

    Function Get-DismFeatures {
        [CmdletBinding()]
        Param ()
    
        Begin {
            $Results = Dism /online /Get-Features
            $Results = $Results[8..($Results.Count - 3)] | Where-Object {$_ -ne ''}
    
            $Feature = $Results | Select-String 'Feature'
            $State = $Results | Select-String 'State'
            $ResultsCounter = $Results.Count/2
        } # End Begin.
    
        Process {
            for ($i = 0; $i -lt $ResultsCounter; $i++) { 
                [pscustomobject]@{
                    Feature = $Feature[$i].ToString().Split(':')[-1].Trim()
                    State = $State[$i].ToString().Split(':')[-1].Trim()
                }
            }
        } # End Process.
    
        End {
        } # End End.
    } # End Function.
    Invoke-Command -ComputerName <computername> -ScriptBlock ${function:Get-DismFeatures}







    • Edited by tommymaynard Tuesday, October 6, 2015 1:50 AM
    • Proposed as answer by tommymaynard Tuesday, December 1, 2015 8:42 PM
    Tuesday, October 6, 2015 1:19 AM
  • Hi pinchepooch,

    All these works, but invoke-command doesn't always list out the PScomputername for each output it lists. This might be a big issue if you have lots of computers to check.

    Here is some addition to my earlier post. Its similar to what Tommy had posted, but works for multiple computers as well.

    Script: Parse DISM Get-Features from Multiple Remote computers or Saved Log files:

    C:\PS>.\Get-DISMRemoteFeatures.ps1 -Computers Server1,Server2 | ?{$_.Feature -like "Tel*"} 
         
         
        State                                   ComputerName                            Feature 
        -----                                   ------------                            ------- 
        Enabled                                 Server1                              TelnetClient 
        Disabled                                Server1                              TelnetServer 
        Enabled                                 Server2                              TelnetClient 
        Disabled                                Server2                              TelnetServer 


    Regards,

    Satyajit

    Please “Vote As Helpful” if you find my contribution useful or “Mark As Answer” if it does answer your question. That will encourage me - and others - to take time out to help you.

    Tuesday, October 6, 2015 7:56 AM