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=@()
$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
Powershell About Active Directory Group Membership of a domain user的更多相关文章
- Powershell About Active Directory Server
一.获取域控制器服务器清单 (Get-ADForest).Domains | %{ Get-ADDomainController -Filter * -Server $_ } | select hos ...
- Active Directory的基本概念
前言 本文是面对准备加入Active Directory编程的初学者的一份文章,主要是讲解Active Directory(活动目录)的一些概念和相关知识.这篇文章本来是不想写下来的,因为概念性内容的 ...
- Enabling Active Directory Authentication for VMWare Server running on Linux《转载》
Enabling Active Directory Authentication for VMWare Server running on Linux Version 0.2 - Adam Breid ...
- Active Directory 域服务 (AD DS) 虚拟化
TechNet 库 Windows Server Windows Server 2012 R2 和 Windows Server 2012 服务器角色和技术 Active Directory Acti ...
- 介绍 Active Directory 域服务 (AD DS) 虚拟化
TechNet 库 Windows Server Windows Server 2012 R2 和 Windows Server 2012 服务器角色和技术 Active Directory Acti ...
- 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 ru ...
- 【Azure API 管理】解决API Management添加AAD Group时遇见的 Failed to query Azure Active Directory graph due to error 错误
问题描述 为APIM添加AAD Group时候,等待很长很长的时间,结果添加失败.错误消息为: Write Groups ValidationError :Failed to query Azure ...
- PowerShell 批量导入/导出Active Directory
PowerShell 批量导入/导出Active Directory 近期由于公司要求,须要导入20个供应商.20个客户到AD域中,刚開始手动添�了2个供应商,2个客户.可是感觉费时费 ...
- Active Directory PowerShell模块收集AD信息
0x00 前言简介 Microsoft为Windows Server 2008 R2(以及更高版本)提供了多个Active Directory PowerShell cmdlet,这大大简化了以前需要 ...
随机推荐
- stl之hash_multiset
hash_multiset的元素不会被自己主动排序
- 多线程-CountDownLatch,CyclicBarrier,Semaphore,Exchanger,Phaser
CountDownLatch 一个同步辅助类,在完成一组正在其他线程中执行的操作之前,它允许一个或多个线程一直等待.用给定的计数初始化CountDownLatch.调用countDown()计数减一, ...
- mysql 一些常用指令
登陆: mysql -u root -p //登陆,输入root密码 退出登陆 mysql>exit; mysql 为所有ip授权 mysql> GRANT ALL PRIVILEGES ...
- matplotlib之legend
在<matplotlib极坐标系应用之雷达图> 中,我们提出了这个问题“图例中每种成员的颜色是怎样和极坐标相应的成员的颜色相对应的呢”,那么接下来我们说说legend的一般使用和设置. 调 ...
- hdu Distant Galaxy(遥远的银河)
Distant Galaxy Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)To ...
- SQL练习题汇总(Sqlserver和Mysql版本)
所需表及数据执行脚本: CREATE TABLE STUDENT (SNO ) NOT NULL, SNAME ) NOT NULL, SSEX ) NOT NULL, SBIRTHDAY DATET ...
- Apache: You don't have permission to access / on this server
当我们需要使用Apache配置虚拟主机时,有可能会出现这个问题:Apache: You don't have permission to access / on this server # 同IP不同 ...
- js----Open()函数
JS中open()函数介绍 window=object.open([URL ][, name ][, features ][, replace]]]]) URL:新窗口的URL地址 name:新窗口的 ...
- poll?transport=longpoll&connection...连接的作用
在浏览器中打开使用VS2013开发的项目时,按F12使用浏览器调试,会发现一堆无关的请求,结构大致是:poll?transport=longpoll&connection.....一直不停的请 ...
- 常用的几个linux命令
linux 命令众多,特别是每个命令后面的option更是很多,如果不经常使用,就容易忘记.下面是一些常用的命令和参数.其他不常用的,可以用help去现查现用. 1. 最常用的命令列表 下面列出几个在 ...