Solved

Powershell Error Handling to txt file

Posted on 2013-10-22
2
541 Views
Last Modified: 2013-10-23
Hi I am running a script to add multiple users to a distribution group:

Get-Content 'C:\users.txt' | Add-DistributionGroupMember 'groupname'

What I would like is that if the user cannot be found or if the user is already a member of the group that the script will list the username and save it to a text file, in an easy to read way.

Any help would be greatly appreciated.
0
Comment
Question by:ECS-ITUK
2 Comments
 
LVL 40

Accepted Solution

by:
Subsun earned 500 total points
ID: 39592467
Try this.. the error messages will be captures in C:\Temp\log.txt
Get-Content 'C:\users.txt' | %{
	$User = $_
	Try {
		Add-DistributionGroupMember 'groupname' -Member $User -EA STOP
	}
	Catch{
		Echo $User $_.exception.Message
	}
} | Out-File C:\Temp\log.txt

Open in new window

0
 

Author Closing Comment

by:ECS-ITUK
ID: 39593383
Worked a treat thanks :)
0

Featured Post

Want to promote your upcoming event?

Attending an event? Speaking at a conference? Or exhibiting at a tradeshow? Easily inform your contacts by using a promotional banner in your email signature. This will ensure your organization’s most important contacts are in the know.

Join & Write a Comment

Suggested Solutions

Exchange server is not supported in any cloud-hosted platform (other than Azure with Azure Premium Storage).
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 …
In this video we show how to create a Distribution Group 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 Recipients >>…
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…

707 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