Solved

Need help with powershell script

Posted on 2011-03-09
7
650 Views
Last Modified: 2012-05-11
Hi I am using the following script to disable OWA for a list of users, how can I generate a result log file for actions like error warning and success while running this script?

I would like to get the following in log with respect to the result of command.

For each Successful operation print       - OWA disabled for user $username
For each Warning print             - OWA disabled for user $username with warning
For each Error print            - Not able to disable OWA for user $username

Thanks in advance.
$UserList = get-content userlist.txt

foreach ($Username in $UserList) `
{ 
set-casmailbox -identity $UserName `
-OWAEnabled $false `
-POPEnabled $false `
-ActiveSyncEnabled $false `
-ImapEnabled $false
}

Open in new window

0
Comment
Question by:Subsun
  • 3
  • 2
7 Comments
 
LVL 12

Expert Comment

by:FDiskWizard
ID: 35112047
Sorry, I can't give a solid answer. I tried to dive into error handling with one script since starting Powershell in December. Take a look at these links:

http://huddledmasses.org/trap-exception-in-powershell/
http://weblogs.asp.net/adweigert/archive/2007/10/10/powershell-try-catch-finally-comes-to-life.aspx
0
 
LVL 40

Author Comment

by:Subsun
ID: 35127408
Sorry I am a novice in powershell programming. I could not make out the correct code to print the logs. I will wait and see, if some once can help me with the codes.
0
 
LVL 12

Accepted Solution

by:
FDiskWizard earned 500 total points
ID: 35263863
Maybe rethink this...
What about just reviewing people without OWAEnabled once it completes?

I think you can do it by adding this to the end of your script:
foreach ($Username in $UserList) `
{
Get-CASMailbox $Username | where { $_.OWAEnabled } | ft DisplayName, OWAEnabled
}
0
 
LVL 40

Author Comment

by:Subsun
ID: 35419002
Sorry for the late response, I will try this and let you know the result..
0
 
LVL 40

Author Closing Comment

by:Subsun
ID: 35431650
I can use this as a work around, since i did not receive any other answer, i will close this question by accepting your response..
0

Featured Post

Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

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

Is your Office 365 signature not working the way you want it to? Are signature updates taking up too much of your time? Let's run through the most common problems that an IT administrator can encounter when dealing with Office 365 email signatures.
MS Outlook is a world-class email client application that is mainly used for e-communication globally.  In this article, we will discuss the basic idea about MS Outlook, its advanced features, and types of MS Outlook File formats.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

920 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now