pipe not working

This topic contains 0 replies, has 1 voice, and was last updated by  Forums Archives 5 years, 8 months ago.

  • Author
    Posts
  • #6468

    by gsandtner at 2012-09-05 02:45:41

    I want all allowed Cmdlets for a given Rolegroup.
    So I tried:
    PS C:\> (Get-Rolegroup "help desk").roles | Get-ManagementRoleEntry $_\* | Group-Object name
    Cannot process argument transformation on parameter 'Identity'. Cannot convert value "\*" to type "Microsoft.E
    xchange.Configuration.Tasks.RoleEntryIdParameter". Error: "Das Format des in den Parameter Microsoft.Exchange.
    Configuration.Tasks.RoleEntryIdParameter eingegebenen Werts ist ungültig. Prüfen Sie den Wert, und versuchen S
    ie es erneut.
    Parameter name: identity"
    + CategoryInfo : InvalidData: (:) [Get-ManagementRoleEntry], ParameterBindin...mationException
    + FullyQualifiedErrorId : ParameterArgumentTransformationError,Get-ManagementRoleEntry

    Strange.

    Next attempt:
    PS C:\> (Get-Rolegroup "help desk").roles | ForEach-Object {Get-ManagementRoleEntry $_\*} | Group-Object name

    Count Name Group
    ----- ---- -----
    1 Set-HybridConfiguration {User Options}
    1 New-HybridConfiguration {User Options}
    2 Set-ADServerSettings {User Options, View-Only Recipients}

    This is the expected result.
    But why is the additional ForEach-Object required ?

    by Techibee.Author at 2012-09-05 03:14:38

    I believe Get-ManagementRoleEntry cmdlet is not properly coded. That means it is not having one of ValueFromPipeline, ValueFromPipelineByPropertyName parameters set for Identity arguments. Still this is just a guess. For a cmdlet to have the ability to process inputs from pipe line, it should have aforementioned properties set and on top of it, the actual code should have begin{} process {} end {} blocks.

    Wait and see what the big minds in this forum says about this. I am still a learner 🙂

    by poshoholic at 2012-09-05 05:19:33

    $_ is a special variable that is only available via script blocks used in a pipeline. Referencing that variable outside of a script block will never work. That means you either need to use ForEach-Object or you need to use something referred to as ScriptBlock parameters (which should not be confused with parameters that are of type ScriptBlock). You can read more about ScriptBlock parameters here:

    http://blogs.msdn.com/b/powershell/archive/2006/06/23/643674.aspx

    I don't have the Exchange 2010 cmdlets handy, but if the Identity parameter is configured for pipeline input you may be able to do this instead of using ForEach-Object:

    (Get-RoleGroup "help desk").roles | Get-ManagementRoleEntry {"$_\*"} | Group-Object name
    That will only work if the Identity parameter is not of type ScriptBlock and if it is configured with either the ValueFromPipeline or the ValueFromPipelineByPropertyName attribute. Otherwise the parameter doesn't "know" anything about the pipeline or what to do with it, in which case ForEach-Object comes to the rescue.

    by gsandtner at 2012-09-05 23:02:11

    Very helpfull, many thanks.

You must be logged in to reply to this topic.