How to add additional commandline switch
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-22-2025 02:57 PM
We are trying to create a remote mailbox and has the following
We have no problem adding variable with value i.e. $accountDisabled= true
However when it comes to just commandline switch i.e. -Archive, which doesn't not need a cross bonding value, it doesn't work.
We tried to add -Archive in the following line in different places, without much luck
if ($parameters) {
$returnObj = Process-Params -cmd New-RemoteMailbox -params $parameters -cmdSwitches $switchParams -cmdSecurity $securityParams -internalParams $microsoftOnly -inputParams $myParams;
Please assist
# Import Exchange module
Import-Module -DisableNameChecking "$executingScriptDirectory\ExchangeSpoke\ExchangeSpoke.psm1";
# Copy the environment variables to their parameters
if (test-path env:\SNC_exchangeServer) {
$exchangeServer=$env:SNC_exchangeServer;
$authType=$env:SNC_authentication;
$accountPassword=$env:SNC_password;
$name=$env:SNC_name;
#$shared=$env:SNC_shared;
$accountDisabled=$env:SNC_account_disabled;
$userPrincipalName=$env:SNC_user_principal_name;
# $publicFolder=$env:SNC_public_folder;
$displayName=$env:SNC_display_name;
$firstName=$env:SNC_first_name;
# $middleInitial=$env:SNC_middle_name;
$lastName=$env:SNC_last_name;
$alias=$env:SNC_alias;
$OnPremisesOrganizationalUnit=$env:SNC_orgunit;
$ResetPasswordOnNextLogon=$env:SNC_resetpasswordonnextlogon;
$parameters=$env:SNC_parameters;
};
$hiddenPwd = SNCObfuscate-Value -theString $accountPassword
$session = Create-PSSession -exchangeServerName $exchangeServer -credential $cred -authType $authType;
Import-PSSession $session -DisableNameChecking | out-null
# New-Mailbox switch parameters
# This parameters do NOT require a value...
# Parameter name is the key and the value is just the version that supports the parameter
$switchParams = @{"AccountDisabled" = "2010,2013";
"Arbitration" = "2010,2013";
"Discovery" = "2010,2013";
"Equipment" = "2010,2013";
"ImportLiveId" = "2010,2013";
"PublicFolder" = "2013";
"Room" = "2010,2013";
"Shared" = "2010,2013";
"UseExistingLiveId" = "2010,2013";
"Archive" = "2010,2013";
"BypassLiveId" = "2010,2013";
"Confirm" = "2010,2013";
"EvictLiveId" = "2010,2013";
"Force" = "2010,2013";
"HoldForMigration" = "2013";
"ManagedFolderMailboxPolicyAllowed" = "2010,2013";
"OverrideRecipientQuotas" = "2010,2013";
"RemoteArchive" = "2010,2013";
"WhatIf" = "2010,2013"
};
# MultiValued parameters
# Parameter name is the key and the value is just the version that supports the parameter
$multiValued = @{"AddOnSKUCapability" = "2013";
"ModeratedBy" = "2010,2013"
};
# These parameters are security string type
$securityParams = @{"RoomMailboxPassword" = "2010,2013"
};
# These parameters are for Microsoft internal use only
# Parameter name is the key and the value is just the version that supports the parameter
$microsoftOnly = @{"AddOnSKUCapability" = "2013";
"BypassLiveId" = "2010,2013";
"ExternalDirectoryObjectId" = "2010,2013";
"Location" = "2013";
"NetID" = "2010,2013";
"Organization" = "2013";
"OriginalNetID" = "2013";
"OverrideRecipientQuotas" = "2013";
"PartnerObjectId" = "2010";
"QueryBaseDNRestrictionEnabled" = "2013";
"RemoteAccountPolicy" = "2010,2013";
"RemovedMailbox" = "2010,2013";
"SKUAssigned" = "2010,2013";
"SKUCapability" = "2010,2013";
"TargetAllMDBs" = "2013";
"UsageLocation" = "2010,2013"
};
# Define hash table
$myParams = @{};
try {
$theName = $null;
$thePassword = $null;
if ($accountPassword) {
$thePassword = $accountPassword | ConvertTo-SecureString -AsPlainText -Force;
if ($thePassword) {
$myParams.Add("Password", $thePassword);
}
};
if ($displayName) {
$myParams.Add("DisplayName", $displayName);
};
if ($shared -ieq "True") {
# $value = [System.Convert]::ToBoolean($shared);
$myParams.Add("Shared", $value);
};
if ($accountDisabled -ieq "True") {
$value = [System.Convert]::ToBoolean($accountDisabled);
$myParams.Add("accountDisabled", $value);
};
if ($userPrincipalName) {
$myParams.Add("UserPrincipalName", $userPrincipalName);
};
if ($alias) {
$myParams.Add("Alias", $alias);
};
if ($OnPremisesOrganizationalUnit) {
$myParams.Add("OnPremisesOrganizationalUnit", $OnPremisesOrganizationalUnit);
};
if ($ResetPasswordOnNextLogon -ieq "True") {
$value = [System.Convert]::ToBoolean($ResetPasswordOnNextLogon);
$myParams.Add("ResetPasswordOnNextLogon", $value);
};
if ($firstName) {
$myParams.Add("FirstName", $firstName);
};
if ($lastName) {
$myParams.Add("LastName", $lastName);
};
if ($middleInitial) {
$theName = $firstName + ' ' + $middleInitial + '. ' + $lastName;
$myParams.Add("Initials", $middleInitial);
} else {
$theName = $firstName + ' ' + $lastName;
};
if ($publicFolder -ieq "True") {
$myParams = @{};
$value = [System.Convert]::ToBoolean($publicFolder);
$myParams.Add("publicFolder", $value);
$parameters = $null;
};
if ($name) {
$myParams.Add("Name", $name);
};
if ($parameters) {
$returnObj = Process-Params -cmd New-RemoteMailbox -params $parameters -cmdSwitches $switchParams -cmdSecurity $securityParams -internalParams $microsoftOnly -inputParams $myParams;
# retrieve the returned data
$myParams = $returnObj;
};
if ($myParams) {
# User did not specified 'Name', generate one;
if (! $myParams.ContainsKey("Name")) {
$myParams.Add("Name", $theName);
};
};
# Call Cmdlet with our defined parameters
# e.g.: New-Mailbox -UserPrincipalName $principalName -Alias $alias -Name $name -FirstName $firstName -LastName $lastName -Password $thePassword -ResetPasswordOnNextLogon $true;
$Private:cmdParams = SNCGet-CmdParams $myParams
New-RemoteMailbox @myParams | Convertto-JSON -compress
}
catch
{
Write-Error -Exception $PSItem;
}
finally {
# Disconnect the session
Remove-PSSession $session;
}
0 REPLIES 0