ParameterSetName does not workwith Invoke-Command and ArgumentList? RRS feed

  • Question

  • I am writing scripts to monitor disk usage based on scripts from msdn code gallery:


    I need to execute the script on multiple servers with PowerShell remote session. One of the problem I got is that it looks like ParameterSetName does not work with ArgumentList.

    What follows is the simple test script I used. it's based on the parameter definition of Get-DirStats.ps1, I just added positions for Switch parameters because I don't know how to pass named parameter with ArgumentList.

        [String[]] $LiteralPath,
        [Switch] $Only,
        [Switch] $Every,
        [Switch] $FormatNumbers,
        [Switch] $Total
    Write-host "ParameterSetName:" $PSCmdlet.ParameterSetName
    Write-host "Path:" $Path
    Write-host "LiteralPaht:" $LiteralPath
    Write-host "Only:" $Only

    What follows in the screenshot for test result:

    Another related issue is I use Get-ChildItem2 to overcome the 260 character limit in path. It does not work in powershell remote session for me. I asked the question https://gallery.technet.microsoft.com/scriptcenter/Get-ChildItemV2-to-list-29291aae/view/Discussions
    • Edited by GuYuming Monday, October 15, 2018 7:50 AM
    • Moved by Bill_Stewart Thursday, December 20, 2018 9:14 PM This is not "debug/fix/rewrite my script for me" forum
    Monday, October 15, 2018 6:35 AM

All replies

  • Hey,

    I copied your test script and ran it against a few servers and it correctly returned the ParameterSetName each time.

    What happens if you run that directly on the target machine you are testing against rather than through invoke?

    Tuesday, October 16, 2018 2:29 AM
  • it works without PowerShell remote session of cause. But if it cannot work with remote session, I have to configure schedule to run it on every machine.
    Tuesday, October 16, 2018 7:48 AM
  • Hmmm, something else strange is happening though. I just ran that code remotely (*exactly* as you are) against 50 servers and they all returned Parameter set "Path". In your screen shot above your invoke is returning a value for both path and literalpath. That should not be possible.
    Tuesday, October 16, 2018 8:51 PM