?
Solved

Need help with powershell script

Posted on 2011-03-09
7
Medium Priority
?
667 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
[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
  • 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 1500 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

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

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

My attempt to use PowerShell and other great resources found online to simplify the deployment of Office 365 ProPlus client components to any workstation that needs it, regardless of existing Office components that may be needing attention.
In this article I discuss my selections of the Top Four free Outlook OST File Viewers available. Open, view and read even damaged OST files by using these tools. They all provide a clear preview of all data such as emails, notes, tasks, calendars, e…
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…
CodeTwo Sync for iCloud (http://www.codetwo.com/sync-for-icloud?sts=6554) automatically synchronizes your Outlook 2016, 2013, 2010 or 2007 folders with iCloud folders available via iCloud Control Panel. This lets you automatically sync them with…
Suggested Courses

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