I hate to ask yet another question involving Powershell parametersets but I can't figure out why something is breaking my code. Take a look at this code:
Write-Output "Delete: $Delete"
Write-Output "Add: $Add"
This is a shorter piece of code to help figure out the problem with a much longer powershell script. Anyway the code works IF I don't pass anything in the pipeline just to the "delete" parameter. So the following all work:
.\TestExchange.ps1 -add testUser
.\TestExchange.ps1 -delete testUser
Get-Content .\ComputerList.txt | .\TestExchange.ps1 -add testUser
Get-Content .\ComputerList.txt | .\TestExchange.ps1 -add testUser -delete testUser2
However the following causes a problem:
Get-Content .\ComputerList.txt | .\TestExchange.ps1 -delete testUser
When I do this I am inexplicably prompted for both the "password" parameter and the "add" parameter. When I simply pass the "delete" parameter I should NOT be prompted for the "password" and "add" parameters (the "password" parameter should only prompt if I pass the "Add" parameter). "ComputerList.txt" simply contains a string of a single computer BTW.
Can anyone explain why this is happening? I don't understand why passing the "delete" parameter works by itself, but if I use the pipeline in front of it it suddenly thinks I want to use the "add" parameterset instead of the "delete" parameterset.
Any help is much appreciated.