locked
out-gridview -passthru display other properties RRS feed

  • Question

  • So I've been playing around with out-gridview with the -passthru option, and it is very cool, but one of the things I'm running into is that it has the limitation that it only gives you the properties that you would get "standard".  Is there any way to choose additional properties to be listed in the view?

    For example, I can do get-service | out-gridview, and I see Status, Name, DisplayName.  But what if I want to see StartType as a column?  I can pipe to select-object prior to out-gridview, but then the type I get out is selected.system.serviceprocess.servicecontroller, rather than just system.serviceprocess.servicecontroller.

    Without the additional property, the choices for my particular selection are ambiguous.

    Anyone know if this can be done?

    Thanks!

    Thursday, January 11, 2018 11:14 PM

Answers

  • $DBInstance = Get-SCOMClas   ..... 

    Start-SCOMMaintenanceMode -Instance $DBInstances -EndTime  ....

    I hope it's just a typo or a copy error but the variable names are different in your code.

    Please use the code formatting option of the post editor when you post code here in the forum. It prevents unwanted line breaks and keeps the code readable and easier to copy.

    Try this:

    $DBName = 'Name of DB'
    $SQLDBClass = Get-SCOMClass -DisplayName 'SQL Database'
    $DBInstance = Get-SCOMClassInstance -Class $SQLDBClass |
        Where-Object {$_.DisplayName -eq $DBName} | 
            Select-Object -Property HealthState,InMaintenanceMode,DisplayName,Path,ID | 
                Out-GridView -PassThru -Title 'Select the instances to enable Maintenance Mode' | 
                    Foreach-Object{Get-SCOMClassInstance -ID $_.ID}
    Start-SCOMMaintenanceMode -Instance $DBInstance -EndTime (Get-Date).AddDays(1) -Comment 'Maintenance mode set by PowerShell script' -Reason PlannedOther -Verbose
    ... at least the TypeNames are the same before and after the Out-GridView in my environment.

    Best regards,

    (79,108,97,102|%{[char]$_})-join''


    • Edited by BOfH-666 Friday, January 12, 2018 11:54 PM typo corrected
    • Marked as answer by Torpex Tuesday, January 16, 2018 6:39 PM
    Friday, January 12, 2018 11:07 PM

All replies

  • I cannot reproduce what you describe. When I do  ...
    Get-Service |
        Select-Object -Property Status, Name, DisplayName, StartType |
            Out-GridView -PassThru
    ... I get exactly what's expected - a gridview with the specified properties.

    Best regards,

    (79,108,97,102|%{[char]$_})-join''


    • Edited by BOfH-666 Thursday, January 11, 2018 11:30 PM
    Thursday, January 11, 2018 11:28 PM
  • Yes, but if you actually look at the object which is passed, it is not the same as the original object (and therefore I can't pass it as a parameter to my next command.)  Make sense?

    (add a | get-member at the end to both your command, and without the select object - you'll find they are different types)



    • Edited by Torpex Thursday, January 11, 2018 11:39 PM
    Thursday, January 11, 2018 11:39 PM
  • Yes, but if you actually look at the object which is passed, it is not the same as the original object (and therefore I can't pass it as a parameter to my next command.)  Make sense?

    ... not necessarily. What would be your next command what does not work with almost anything what kind of fits in? If it really does not work this way you could rerun the get-service and filter for only the service you want.  ... like this:

    Get-Service |
        Select-Object -Property Status, Name, DisplayName, StartType |
            Out-GridView -PassThru |
                Get-Service | 
                    Get-Member

    This outputs on my system this:

       TypeName: System.ServiceProcess.ServiceController
    
    Name                      MemberType    Definition                                                                                                                        
    ----                      ----------    ----------                                                                                                                        
    Name                      AliasProperty Name = ServiceName                                                                                                                
    RequiredServices          AliasProperty RequiredServices = ServicesDependedOn                                                                                             
    Disposed                  Event         System.EventHandler Disposed(System.Object, System.EventArgs)                                                                     
    Close                     Method        void Close()                                                                                                                      
    Continue                  Method        void Continue()
    
    ......                                                                                                                   
    


    Best regards,

    (79,108,97,102|%{[char]$_})-join''

    • Proposed as answer by jrv Friday, January 12, 2018 1:02 AM
    Thursday, January 11, 2018 11:56 PM
  • That's a good idea, but it's not working in my instance.  Not sure how familiar you are with SCOM, but this is what I'm trying to do:

    $DBName = "Name of DB"

    $SQLDBClass = Get-SCOMClass -DisplayName "SQL Database"

    $DBInstance = Get-SCOMClassInstance -Class $SQLDBClass |

    Where {$_.DisplayName -eq $DBName} |

    Out-GridView - PassThru -Title “Select the instances to enable Maintenance Mode”

    Start-SCOMMaintenanceMode -Instance $DBInstances -EndTime (Get-Date).AddDays(1) -Comment “Maintenance mode set by PowerShell script” -Reason PlannedOther -Verbose

    But the issue is that there can be databases of the same name on multiple servers.  So the output to out-gridview ends up being identical.  But if I could add the "path" property to the view, I could pick the right one based on the server.  If I add the select statement, then the Start-SCOMMaintenanceMode command won't accept the $DBInstances variable as it is no longer the same type of object.

    I think I decided I'm just going to filter by server name first as that should work for my needs now, but it would be nice to be able to work with that through out-gridview.


    Friday, January 12, 2018 6:08 PM
  • $DBInstance = Get-SCOMClas   ..... 

    Start-SCOMMaintenanceMode -Instance $DBInstances -EndTime  ....

    I hope it's just a typo or a copy error but the variable names are different in your code.

    Please use the code formatting option of the post editor when you post code here in the forum. It prevents unwanted line breaks and keeps the code readable and easier to copy.

    Try this:

    $DBName = 'Name of DB'
    $SQLDBClass = Get-SCOMClass -DisplayName 'SQL Database'
    $DBInstance = Get-SCOMClassInstance -Class $SQLDBClass |
        Where-Object {$_.DisplayName -eq $DBName} | 
            Select-Object -Property HealthState,InMaintenanceMode,DisplayName,Path,ID | 
                Out-GridView -PassThru -Title 'Select the instances to enable Maintenance Mode' | 
                    Foreach-Object{Get-SCOMClassInstance -ID $_.ID}
    Start-SCOMMaintenanceMode -Instance $DBInstance -EndTime (Get-Date).AddDays(1) -Comment 'Maintenance mode set by PowerShell script' -Reason PlannedOther -Verbose
    ... at least the TypeNames are the same before and after the Out-GridView in my environment.

    Best regards,

    (79,108,97,102|%{[char]$_})-join''


    • Edited by BOfH-666 Friday, January 12, 2018 11:54 PM typo corrected
    • Marked as answer by Torpex Tuesday, January 16, 2018 6:39 PM
    Friday, January 12, 2018 11:07 PM
  • Thank you very much - works perfectly, and makes much more sense.

    (And yes, not exactly a typo on that variable, but sort of - was copying a couple different sources and forgot I changed the variable name in my updated area.  Good catch.)

    And I'll remember to use the code block option next time - sorry, not sure if I posted any PowerShell questions on here before.

    Appreciate all the help!

    Tuesday, January 16, 2018 6:39 PM