Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use Powershell script to automatically remove the group of outgoing users and save the log

2025-01-30 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

Recently, the work received a requirement to clean up the group and log the account of the departing personnel, so I studied how to use Powershell to achieve this function:

# query the exit account under the corresponding OU

$users = get-aduser-Filter *-SearchBase "OU=xxxx,DC=it581,DC=com" | foreach {if ($.enabled-eq $false) {echo $.sampled name}}

# get the current date

$data=get-date-Format 'yyyyMMdd'

# use a circular log and delete the corresponding group

Foreach ($user in $users)

{

Get-ADUser-Identity $user-Properties * | select name,memberof | fl > > d:\ $data.txt

Get-ADPrincipalGroupMembership-Identity $user | where {$.name-notlike "domain users"} |% {Remove-ADPrincipalGroupMembership-Identity $user-MemberOf $- Confirm:$false-ErrorAction SilentlyContinue}

}

Write-host "removal complete!"

The above is the script that implements this requirement.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report