Solved

Need help with powershell script

Posted on 2011-03-09
7
647 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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Outlook Free & Paid Tools
This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
Learn the basics of strings in Python: declaration, operations, indices, and slicing. Strings are declared with quotations; for example: s = "string": Strings are immutable.: Strings may be concatenated or multiplied using the addition and multiplic…
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

760 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

16 Experts available now in Live!

Get 1:1 Help Now