Powershell About Active Directory Group Membership of a domain user

使用Get-User命令去寻找group membership of a domain user

$((Get-ADUser Wendy -Properties *).MemberOf -split (“,”)  | Select-String -SimpleMatch “CN=”) -replace “CN=”,””

扩展1?:获取在群组Wendy和群组Gaga中的所有用户

Get-ADUser -Filter * -SearchScope Subtree -SearchBase "dc=xx,dc=xx,dc=xxx" -Properties * |  where {($($_.MemberOf -split (“,”)  | Select-String -SimpleMatch “CN=”) -replace “CN=”,””) -contains "GroupGaga" -or ($($_.MemberOf -split (“,”)  | Select-String -SimpleMatch “CN=”) -replace “CN=”,””) -contains "GroupWendy"} | select name,$($_.MemberOf -split (“,”)  | Select-String -SimpleMatch “CN=”) -replace “CN=”,””)

扩展2:定义筛选范围条件,将这个范围内不属于某个群组的用户加入某个群组

Get-ADUser -Filter * -SearchScope Subtree -SearchBase "OU=XX,dc=XX,dc=XX,dc=XX" -Properties * |  where {$_.Title -eq "WW有限公司" -and $_.EmailAddress -ne $null -and $_.City -ne $null -and $_.Enabled -eq $true -and ($($_.MemberOf -split (“,”)  | Select-String -SimpleMatch “CN=”) -replace “CN=”,””) -notcontains "GroupNacy"} | Get-ADUser | ForEach-Object {Add-ADGroupMember -Identity “GroupNacy)” -Members $_}

扩展3:查询用户的隶属群组

$export[email protected]()
$Users=Get-ADUser -Filter * -SearchScope Subtree -SearchBase "OU=xx,OU=xx,dc=xx,dc=xx,dc=xx" -Properties *
 
foreach($user in $users)
{
#$User=Get-ADUser -identity wendy -Properties *
$members=($user.MemberOf -split (“,”) | Select-String -SimpleMatch “CN=”) -replace “CN=”,””
$name=$user.name
#$all=$members | findstr /i "GroupWendy Groupgaga" 可以放在一个条件中
$w=$members | findstr /i "GroupWendy"
#筛选群组,用findstr   /i为忽略大小写参数  findstr /i "^Groupgaga" 表示:查询以Groupgaga开头的string
$g=$members | findstr /i "^Groupgaga"
$wendy=[string]$w
$gaga=[string]$g
$info=New-Object Psobject
$info |Add-Member -MemberType NoteProperty -Name 姓名 -Value $name
$info |Add-Member -MemberType NoteProperty -Name Groupgaga -Value $gaga
$info |Add-Member -MemberType NoteProperty -Name GroupWendy -Value $wendy
$export+=$info
}
$CurrentDate = Get-Date
$CurrentDate = $CurrentDate.ToString(‘yyyy-MM-dd‘)
$export |Export-Csv D:\ps\userPermissioninfo_$CurrentDate.csv -Encoding UTF8 -NoTypeInformation
时间: 2025-01-09 15:02:45

Powershell About Active Directory Group Membership of a domain user的相关文章

Powershell About Active Directory Server

一.获取域控制器服务器清单 (Get-ADForest).Domains | %{ Get-ADDomainController -Filter * -Server $_ } | select hostname,ipv4address,OperatingSystem | Export-Csv d:\ps\List.csv $allDCs = (Get-ADForest).Domains | %{ Get-ADDomainController -Filter * -Server $_ } 二:备份

Enabling Active Directory Authentication for VMWare Server running on Linux《转载》

Enabling Active Directory Authentication for VMWare Server running on Linux Version 0.2 - Adam Breidenbaugh - 2007-06-29 Purpose The purpose of this guide is as follows: Document the steps necessary to enable Active Directory Authentication on a Linu

Three Steps to Migrate Group Policy Between Active Directory Domains or Forests Using PowerShell

Three Steps Ahead Have you ever wished that you had three legs? Imagine how much faster you could run.  Today we are going to look at three steps to migrating GPOs between domains or forests with PowerShell.  Now that is fast! The Problem Have you ev

PowerShell 批量导入/导出Active Directory

PowerShell 批量导入/导出Active Directory 最近因为公司要求,需要导入20个供应商.20个客户到AD域中,刚开始手动加入了2个供应商,2个客户.但是感觉费时费力.如果能够找到一个命令,批量导入AD该多好呀. 因为之前有师兄在AD方面留下的有文档,发现AD域用户导出的命令是这样的: csvde -f E:\20131015.csv -r "(objectClass=user)" -d "OU=XXX,DC=XXX,DC=com" -u 这里对

Active Directory Authentication in ASP.NET MVC 5 with Forms Authentication and Group-Based Authorization

I know that blog post title is sure a mouth-full, but it describes the whole problem I was trying to solve in a recent project. The Project Let me outline the project briefly.  We were building a report dashboard-type site that will live inside the c

Office365 Active Directory同步配置筛选

我们上一篇介绍了Office365联合身份验证服务的配置,实现本地的Active Directory和Office365实现联合认证,完成SSO-单点登陆.其中有一个过程是需要通过dirsync工具将本地的Active Directory 信息同步到Office365上,同步后,我们发现默认是将本地所有的用户组信息同步到Office365,这样的同步结果对于管理员来说是很不方便的,为什么呢,因为如果本地有上千甚至过万的用户,这些用户信息都同步到Office365上的话维护起来不方便,那怎么实现将

User Attributes - Inside Active Directory

User Attributes - Inside Active Directory Related to the book Inside Active Directory, ISBN 0-201-61621-1Copyright (C) 2002 by Sakari KoutiVersion: December 21, 2001Back to the book's Web site Attr LDAP Name Attr Display Name ADUC Tab ADUC Field Prop

TFS 与活动目录AD(Active Directory)的同步机制

TFS用户管理机制 TFS系统与企业域服务器用户系统(或本地计算机用户系统)高度集成在一起,使用域服务器验证系统用户的账户和密码,从而在企业中实现单一用户,单点登录.也就是说,TFS系统自身并没有用户管理的功能,没有针对账户信息的创建.修改.删除功能.当用户通过域服务器提供的功能修改了账户密码以后,登陆TFS系统时,需要使用新的账户密码. 但是,并不是说在TFS系统中完全没有账户信息的概念.实际上,当管理员将开发人员的域账户或本地服务器的账户添加到TFS的团队项目中时,TFS系统自动将账户的部分

Active Directory participation features and security extensions

Participation in the Active Directory Samba 3.0 series, as well as the OS since Windows 2000, is possible to participate in the Active Directory domain using Kerberos authentication. Because I think people often are interested, let's explain specific