Solved

Need help with powershell script

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

VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

Question has a verified solution.

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

Are you unable to connect or configure Hotmail email account in Microsoft Outlook 2010, 2007? Or Outlook.com emails are not downloading to Outlook? Lets’ see the problem and resolve Outlook Connector error syncing folder hierarchy (0x8004102A).
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.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

770 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