Deactivate member from a list
Hello, I use exchange 2007. I receive list of identities (samaccount but it could be displayname or else) about users that has left the company and are deactivated. I would need from that list to remove the user from the distribution list they used to belong to as they appear in the EMC as deactivated user in the DGs. I got help from mjolinor about how to get distribution groups where the user is a member: foreach ($dl in get-distributiongroup) {if ((get-distributiongroupmember $dl |% {$_.name}) -contains"displayname"){$dl.name}} But that time I need to remove the user as member from the distribution listS and also based on a list I would be receiving (list could be samaccount, displayname or else) Thanks in advance, Graig
August 27th, 2010 11:38am

you can do something like this: import-csv users.csv | foreach { $user = get the user foreach ($group in $user.memberof){ Remove-QADGroupmember -identity $group -member $user } } thanks thiyaguThiyagu | MCTS/MCITP - Exchange 2007 | MCSE 2003[Messaging] | http://www.myExchangeWorld.com. This posting is provided "AS IS" with no warranties, and confers no rights.
Free Windows Admin Tool Kit Click here and download it now
August 27th, 2010 12:35pm

I tried with that: import-csv C:\REMOVE.csv | foreach { $user = get the user foreach ($group in $user.memberof){ Remove-QADGroupmember -identity $group -member $user } } But it did not remove the user from the DGs. The csv file should contain the SamAccountName ?
August 27th, 2010 12:47pm

[>import-csv C:\REMOVE.csv | foreach {$user = get the user foreach ($group in $user.memberof) {Remove-QADGroupmember -identity $group -member $user}} Unexpected token 'in' in expression or statement. At line:1 char:76 + import-csv C:\REMOVE.csv | foreach {$user = get the user foreach ($group in <<<< $user.memberof) {Remove-QADGroupmember -ident ity $group -member $user}}
Free Windows Admin Tool Kit Click here and download it now
August 27th, 2010 12:52pm

try this: foreach ($user in (get-content users.txt)){ (get-qaduser $user).memberof | Get-QADGroup | where {$_.name -ne "domain users"} | Remove-QADGroupMember -member $user } do you have quest installed on ur powershell env where you are runnin this? NOTE: first try this with 1 user , before running on all users. Thiyagu | MCTS/MCITP - Exchange 2007 | MCSE 2003[Messaging] | http://www.myExchangeWorld.com. This posting is provided "AS IS" with no warranties, and confers no rights.
August 27th, 2010 12:57pm

Okay I tried with one user: foreach ($user in (get-content C:\REMOVE.txt)){(get-qaduser $user).memberof | Get-QADGroup | where {$_.name -ne "domainusers"} | Remove-QADGroupMember -member $user} The term 'get-qaduser' is not recognized as a cmdlet, function, operable program, or script file. Verify the term and try again. At line:1 char:60 + foreach ($user in (get-content C:\REMOVE.txt)){(get-qaduser <<<< $user).memberof | Get-QADGroup | where {$_.name -ne "domainus ers"} | Remove-QADGroupMember -member $user} NB: I don't have quest installed.
Free Windows Admin Tool Kit Click here and download it now
August 27th, 2010 1:07pm

yeah, that is the issue, if you want you can install the quest tools. http://www.quest.com/powershell/activeroles-server.aspx Thiyagu | MCTS/MCITP - Exchange 2007 | MCSE 2003[Messaging] | http://www.myExchangeWorld.com. This posting is provided "AS IS" with no warranties, and confers no rights.
August 27th, 2010 2:27pm

Hello, I use exchange 2007. I receive list of identities (samaccount but it could be displayname or else) about users that has left the company and are deactivated. I would need from that list to remove the user from the distribution list they used to belong to as they appear in the EMC as deactivated user in the DGs. I got help from mjolinor about how to get distribution groups where the user is a member: foreach ($dl in get-distributiongroup) {if ((get-distributiongroupmember $dl |% {$_.name}) -contains"displayname"){$dl.name}} But that time I need to remove the user as member from the distribution listS and also based on a list I would be receiving (list could be samaccount, displayname or else) Thanks in advance, Graig Not tested, but see if this works: $deact = get-content deact.txt |% {get-recipient $_ |% {$_.displayname} foreach ($grp in get-distributiongroup -resultsize unlimited){ $dlmem = get-distributiongroupmember $grp |% {$_.displayname} $deact |% {if ($dlmem -contains $_){remove-distributiongroupmember $grp -member $_} } }[string](0..33|%{[char][int](46+("686552495351636652556262185355647068516270555358646562655775 0645570").substring(($_*2),2))})-replace " "
Free Windows Admin Tool Kit Click here and download it now
August 27th, 2010 3:36pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics