Tuesday, 4 June 2013

Adding user from txt in AD group

<#   The input file is User.txt havig the samaccount of the user, try and catch is used to verify if the user is already added to the group, Here we can use variable to out the result in logs for the user which are already added in group #>

Import-module ActiveDirectory
Import-CSV "C:\Users\administrator\Desktop\User.txt" | % {
try {$x=$_.UserName
Add-ADGroupMember -Identity allit -Member $x }
catch [system.exception] {
write-host "the user $x is alreday a member of the group"}


No comments:

Post a Comment


Born as Mathematician, Found love in Scripting and want to have an affair with C#

Total Pageviews