[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 347
  • Last Modified:

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.
0
Ben Hart
Asked:
Ben Hart
1 Solution
 
footechCommented:
You have to write your script to support parameters like -whatif.  Check out [cmdletbinding()].
The Set-Mailbox cmdlet supports the -whatif parameter by itself though.
0
 
Ben HartAuthor Commented:
Figured it out.  The -WhatIf has to be inside the last } on the last line.  Thanks, you pointed me in the right direction.
0

Featured Post

Veeam Disaster Recovery in Microsoft Azure

Veeam PN for Microsoft Azure is a FREE solution designed to simplify and automate the setup of a DR site in Microsoft Azure using lightweight software-defined networking. It reduces the complexity of VPN deployments and is designed for businesses of ALL sizes.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now