Piping to a cmdlet parameter which wont accept pipeline

Welcome Forums General PowerShell Q&A Piping to a cmdlet parameter which wont accept pipeline

This topic contains 4 replies, has 3 voices, and was last updated by

4 years, 8 months ago.

  • Author
  • #15902

    Points: 0
    Rank: Member

    Hi All,

    Was trying to do this..

    $TsProfilePath = \\Server\Share\'$User\TS\Profile

    import-csv $PathtoCSV | foreach-object {get-qaduser $_.Name | set-qaduser -TsProfilePath '$TsProfilePath'}

    I initially had profile path in the csv file but the cmdlet doesnot not accept pipeline for this paramater which for me as a new student to powershell I have not yet solved.

    If anyone could shine some light to resolve this currnet problem.

    BTW – I am trying to figure out how to do inception based powershell i.e. pipe to a variable within a variable
    Any deeper and I might not make it out!



  • #15904

    Points: 0
    Rank: Member

    You're not actually piping Import-Csv to anything other than ForEach-Object here, so you could put the path in the CSV file if you like. That would look something like this:

    Import-Csv $PathtoCSV |
    ForEach-Object {
        $csvRecord = $_
        Get-QADUser $csvRecord.Name |
        Set-QADUser -TsProfilePath $csvRecord.TSProfilePath

    This code assumes that the column in your CSV is named TSProfilePath; you'd need to change the argument to Set-QADUser if it's something different.

    I'm not sure what you mean by "pipe to a variable within a variable".

  • #15906

    Points: 0
    Rank: Member

    Thanks Dave –

    Please ignore all I said about variable within variables.

  • #15908

    Points: 0
    Rank: Member

    Sometimes piping data into ForEach-Object, and then piping further within the foreach will fail catastrophically. For example, doing

    Get-Mailbox | ForEach-Object {
    $_ | Get-MailboxStatistics

    will break with the following error:

    Pipeline not executed because a pipeline is already executing. Pipelines cannot be executed concurrently.
    + CategoryInfo : OperationStopped: (Microsoft.Power...tHelperRunspace:ExecutionCmdletHelperRunspace) [], PSInvalidOperationEx
    + FullyQualifiedErrorId : RemotePipelineExecutionFailed

    For this reason, and because piping is actually quite slow when dealing with larger quantities of data, and it makes code look like Perl (Perl isn't bad, it's just ugly), I've found myself using it less and less in favor of saving data in variables and then using a proper foreach($item in $list) { } structure.

  • #15956

    Points: 0
    Rank: Member

    100% agreed Martin.
    Still lots to learn, but it is $fun

The topic ‘Piping to a cmdlet parameter which wont accept pipeline’ is closed to new replies.

denizli escort samsun escort muğla escort ataşehir escort kuşadası escort