Solved

Powershell Error Handling to txt file

Posted on 2013-10-22
2
586 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
[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
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

Office 365 Training for IT Pros

Learn how to provision tenants, synchronize on-premise Active Directory, implement Single Sign-On, customize Office deployment, and protect your organization with eDiscovery and DLP policies.  Only from Platform Scholar.

Question has a verified solution.

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

Auditing domain password hashes is a commonly overlooked but critical requirement to ensuring secure passwords practices are followed. Methods exist to extract hashes directly for a live domain however this article describes a process to extract u…
After hours on line I found a solution which pointed to the inherited Active Directory permissions . You have to give/allow permissions to the "Exchange trusted subsystem" for the user in the Active Directory...
In this Micro Video tutorial you will learn the basics about Database Availability Groups and How to configure one using a live Exchange Server Environment. The video tutorial explains the basics of the Exchange server Database Availability grou…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
Suggested Courses

632 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