if ($mbcb1.Checked -eq $true) {$dgr = "-AutoStart"}
if ($mbcb2.Checked -eq $true) {$dgrc = "-AutoComplete"}
if ($mbcb3.Checked -eq $true) {$dgren = "-NotificationEmails"}
New-MigrationBatch -Name $mbnd -SourceEndpoint $mbcx -TargetDeliveryDomain $mbtdd -CSVData ([System.IO.File]::ReadAllBytes("$cmbcsvfile")) $dgr $dgrc $dgren [email protected]
Error :
A positional parameter cannot be found that accepts argument '-Autostart'.
+ CategoryInfo : InvalidArgument: (:) [New-MigrationBatch], ParameterBindingException
+ FullyQualifiedErrorId : PositionalParameterNotFound,New-MigrationBatch
+ PSComputerName : ps.outlook.com
if i given direct input its working but passing as variable throwing error.
If you want to optionally specify parameters, use splatting:
$OptionalParameters = @{
AutoStart = $mbcb1.Checked
AutoComplete = $mbcb2.Checked
}
if ($mbcb3.Checked) {
$OptionalParameters["NotificationEmails"] = '[email protected]'
}
New-MigrationBatch -Name $mbnd -SourceEndpoint $mbcx -TargetDeliveryDomain $mbtdd -CSVData ([System.IO.File]::ReadAllBytes("$cmbcsvfile")) @OptionalParameters
We simply build a hashtable with the parameter names and their arguments, and then supply it to the cmdlet as an argument (but like @name instead of $name), and then the parser will turn each entry in the hashtable into a named parameter in the form -key:value.
Finally, the $mbcb3.Checked -eq $true comparison is redundant, since Checked (assuming that $mbcb3 is a checkbox) is already either $true or $false
See the about_Splatting help file for more details about parameter splatting
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With