Link to home
Start Free TrialLog in
Avatar of Ben Hart
Ben HartFlag for United States of America

asked on

powershell test/WhatIf question

I've written a script that will perform a get-mailbox, then add a new domain alias to each of the results.  However I want to test it.  I've seen google search results saying that this can be accomplished with a -WhatIf such as:

c:\>.\somescriptfile.ps1 -WhatIf

However that generate an error complaining about the whatif part.

Heres the code Im using:

$users = get-mailbox
foreach ($a in $users) {$a.emailaddresses.Add("smtp:$($a.alias)@new.domain.com")}
$users | %{set-mailbox $_.Identity -emailaddresses $_.emailaddresses}

Open in new window


Not sure what I could put a -whatif statement in here... I tried on a new line at the bottom but it failed.
ASKER CERTIFIED SOLUTION
Avatar of footech
footech
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Ben Hart

ASKER

Figured it out.  The -WhatIf has to be inside the last } on the last line.  Thanks, you pointed me in the right direction.