How Do you Tie Function to Ad user.

I have wrote a Script. In this Script, i want to Tie the Ad user to a function i Created. This is what i Got:

 Import-Module ActiveDirectory $ErrorActionPreference= 'silentlycontinue' $user= Read-Host 'Enter Username being terminated' $username = Get-ADUser $user $dn = $username.DistinguishedName Disable-UserMailbox -Identity $user -ForwardingAddress $Forwardto function Disable-UserMailbox { param ( [ValidatePattern('.*(Comapny.com)')][string]$Forwardto, [Parameter(Mandatory=$true,ValueFromPipeline=$true)][string] $user ) $Forwardto = Read-Host 'Enter Email Address you want to forward email to' if ($Forwardto) { Set-Mailbox -Identity $user -ForwardingAddress $Forwardto -HiddenFromAddressListsEnabled $true } else { Set-Mailbox -Identity $user -HiddenFromAddressListsEnabled $true } 

What happens is that when the Script gets to the Portion of script:

EX Step 1 – Hide from GAL

$s = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri http://Mydomain.org.local/PowerShell/ -Authentication Kerberos Import-PSSession $s -AllowClobber Disable-UserMailbox 

Is will ask me for the user name Again:

cmdlet Disable-UserMailbox at command pipeline position 1 Supply values for the following parameters: user:

What i want to have happen, is to have the the user name be asked once and then when it gets to the email forward portion, to have the aduser that exchange account is tied to and ask for a Forwarding address ( preferably using the Distinguished name instead of the whole email address.

What should I do?

submitted by /u/Tucsontime
[link] [comments]

Leave a Reply