Quantcast
Channel: PowerShell
Viewing all articles
Browse latest Browse all 15370

Powershell Parameter Sets

$
0
0

It must be Monday. I am writing a new Powershell script (well updating an old one) and I wanted to use a feature I have never used before. I wanted to use Parameter sets, but for the life of me I cannot get it to work as expected.

I have a list of 2 sets I would like to use, based on if switches are enabled I would like to use whichever set is associated with that switch.

Here is what I current have, that is not working as expected

param(
	[Parameter(Position=0,
		ValueFromPipeline=$True,
		ParameterSetName="Set1")]
	[string]$sourceDir = "D:\Vodassets\_PreImport_Success", #Production Folder "D:\Vodassets\_PreImport_Success"
	[string]$Date = (Get-Date -Format MM-dd-yyyy),
	[string]$LogDate = (Get-Date -Format G),
	[string]$LogFile = "Vodasset-Cleanup.txt",
	[switch]$Title,
	[switch]$ProviderID,
	##[Parameter(Mandatory=$True)]
	[Parameter(Position=0,
		Mandatory=$True,
		ParameterSetName="Set1")]
	[string]$like,
	[Parameter(Position=0,
		ValueFromPipeline=$True,
		ParameterSetName="Set2")]
	[switch]$FromFile,
	[string]$InputFile = "Vodasset-Cleanup.csv"
)

Set2 should just be FromFile switch and $InputFile variable that holds a csv file. Everything else should be in Set1, but if set1 is active there should be a $like variable that is mandatory, for that set only.

Cany anyone help me make sense of how parameter sets should work. I'm not sure what to do with the "Position" part and if it should be 0, or some other integer.


Viewing all articles
Browse latest Browse all 15370

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>