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,这大大简化了以前需要 ...
随机推荐
- Navicat Premium快速导出数据库ER图和数据字典
2.快速导出数据库数据字典: SQL Server 数据库,生成数据字典 use YourDatabase --指定要生成数据字典的数据库 go SELECT 表名= then d.name else ...
- intellij jetBrains phpstorm/webstorm/IDEA 编辑器使用诀窍
下载地址 https://www.jetbrains.com/products.html?fromMenu 主题/皮肤切换或下载:https://blog.csdn.net/smallxiannoti ...
- laravel文件存储Storage
use Illuminate\Support\Facades\Storage; //建立目录 Storage::disk('public')->makeDirectory(date('Y-m') ...
- flex and bison学习笔记01
工作需要,学习一下Flex and bison,以前在编译原理的课上听老师说过他们的前辈,lex and yacc.Flex and bison就是lex and yacc的升级版. 参考书:flex ...
- Linux_Command
系统 # uname -a # 查看内核/操作系统/CPU信息 # head -n 1 /etc/issue # 查看操作系统版本 # cat /proc/cpuinfo # 查看CPU信息 # ho ...
- 替换jar中的指定文件
替换jar 包下面的class 文件,很多人会想到直接用winrar 打开替换,在一般的情况下, 是可行的,但是如果说这个jar 的代码经过混淆后,会有大小写不同,文件名是相同的,在windos ...
- Excel函数sumproduct应用案例-多条件求和
作者:iamlaosong 越来越认为sumproduct这个函数实用,过去用sum组函数.改起来复制起来都麻烦,sumif在条件多的时候也认为不方便. 如今改用sumproduct函数,就简单多了. ...
- Django 图片路径问题
在 django 中不像PHP那样有根目录的概念 而取而代之的是包的概念, 通过URLS.PY 来提供每个URL 对应的DJANGO的 函数来显示页面 在包的 temolates目录中 的html页面 ...
- 微信小程序,时间戳转为日期格式
//数据转化 function formatNumber(n) { n = n.toString() ] ? n : ' + n } /** * 时间戳转化为年 月 日 时 分 秒 * number: ...
- redisson笔记
简介 Redisson - 是一个高级的分布式协调Redis客服端,能帮助用户在分布式环境中轻松实现一些Java的对象 (Bloom filter, BitSet, Set, SetMultimap, ...