?
Solved

How To Include Argument in PowerShell CmdLet

Posted on 2011-02-18
2
Medium Priority
?
1,590 Views
Last Modified: 2012-05-11
I believe that what I want to accomplish is probably simple, but how to do what I want elludes me. I have tried some suggestions found during a google search, but they have not done what I had hoped.

I am using the cmdlet Remove-Mailbox in Exchange PowerShell 2010. The most basic syntax for the cmdlet is:

    Remove-Mailbox -Identity <MailboxIdParameter>

Our environment supports multiple organizational units and since the Remove-Mailbox cmdlet does not support the -Organization argument, I am using the following cmdlet to specify the OU and ID, and piping the results to Remove-Mailbox:

    [PS]>Get-Mailbox -Organization MyOrg -Identity mickey@domain.com | Remove-Mailbox

The above cmdlet works, but with each ID that has to be removed, I am prompted by PowerShell to confirm my action. Powershell displays the following message with each execution of the above cmdlet:

    Are you sure you want to perform this action?
    Removing mailbox "domain.com/Microsoft Exchange Organizations/database-mailbox/Mickey" will remove the Active Directory user object and mark the mailbox and the archive (if present) in the database for removal.
    [Y] Yes  [A] Yes to All  [N] No  [L] No to All  [?] Help (default is "Y"):

The cmdlet waits for me to select one of the values in brackets. I always press Y. I want to be able to include the default Y in the above cmdlet. How do I do that?

Thanks
0
Comment
Question by:brian_appliedcpu
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 31

Accepted Solution

by:
MegaNuk3 earned 2000 total points
ID: 34928161
Add
-confirm:$false

On the end
0
 
LVL 2

Author Closing Comment

by:brian_appliedcpu
ID: 34928805
So I noticed you are inserting a colon in your argument and that seems to work. That's interesting, b/c I was trying to use the -Confirm argument earlier, but I kept getting an invalid cast type error, which I thought had something to do with the $ sign casting my boolean as a string, instead of a true/false value. But it would not work without the $ sign either. So I gave up and started doing a google search. BTW, I ran Remove-Mailbox -? and reviewed the help content a couple of times, but never found where a colon was to be included in the syntax. But hey it works, so I'm happy.
Thanks
0

Featured Post

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A quick Powershell script I wrote to find old program installations and check versions of a specific file across the network.
Check out this step-by-step guide for using the newly updated Experts Exchange mobile app—released on May 30.
To show how to create a transport rule in Exchange 2013. We show this process by using the Exchange Admin Center. Log into Exchange Admin Center.: First we need to log into the Exchange Admin Center. Navigate to the Mail Flow >> Rules tab.:  To cr…
In this Micro Video tutorial you will learn the basics about Database Availability Groups and How to configure one using a live Exchange Server Environment. The video tutorial explains the basics of the Exchange server Database Availability grou…
Suggested Courses
Course of the Month9 days, 22 hours left to enroll

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question