使用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的更多相关文章

  1. Powershell About Active Directory Server

    一.获取域控制器服务器清单 (Get-ADForest).Domains | %{ Get-ADDomainController -Filter * -Server $_ } | select hos ...

  2. Active Directory的基本概念

    前言 本文是面对准备加入Active Directory编程的初学者的一份文章,主要是讲解Active Directory(活动目录)的一些概念和相关知识.这篇文章本来是不想写下来的,因为概念性内容的 ...

  3. 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 ...

  4. Active Directory 域服务 (AD DS) 虚拟化

    TechNet 库 Windows Server Windows Server 2012 R2 和 Windows Server 2012 服务器角色和技术 Active Directory Acti ...

  5. 介绍 Active Directory 域服务 (AD DS) 虚拟化

    TechNet 库 Windows Server Windows Server 2012 R2 和 Windows Server 2012 服务器角色和技术 Active Directory Acti ...

  6. 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 ...

  7. 【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 ...

  8. PowerShell 批量导入/导出Active Directory

    PowerShell 批量导入/导出Active Directory         近期由于公司要求,须要导入20个供应商.20个客户到AD域中,刚開始手动添�了2个供应商,2个客户.可是感觉费时费 ...

  9. Active Directory PowerShell模块收集AD信息

    0x00 前言简介 Microsoft为Windows Server 2008 R2(以及更高版本)提供了多个Active Directory PowerShell cmdlet,这大大简化了以前需要 ...

随机推荐

  1. 盘点SEO和SEM的优劣势

    如果你不知如何分配你的搜索营销预算,或是和客户提案的时候不知道怎么样去解释搜索营销产品(SEO和SEM)的区别,又或者不了解网站/企业在当前阶段应该优先施行哪种搜索营销策略,本文可以帮助你深入了解SE ...

  2. Certificates

    Certificates Certificates 即 ”证书“,约等于通行证,申请证书是我们进行真机调试与发布的第一步.证书主要分为两类:Development证书用来开发和调试应用程序Produc ...

  3. 227. Mock Hanoi Tower by Stacks【easy】

    In the classic problem of Towers of Hanoi, you have 3 towers and N disks of different sizes which ca ...

  4. hMailServer之允许用户自己修改密码

    使用hMailServer搭建邮件系统,使用webmail实现web收发邮件,但是又个问题是在webmail中用户自己无法修改密码. 可以使用hMailServer自带的PhpWebAdmin来实现让 ...

  5. ORACLE中NVL和COALESCE的区别

    nvl(COMMISSION_PCT,0)如果第一个参数为null,则返回第二个参数如果第一个参数为非null,则返回第一个参数 COALESCE(EXPR1,EXPR2,EXPR3...EXPRn) ...

  6. poj1182食物链--并查集

    动物王国中有三类动物A,B,C,这三类动物的食物链构成了有趣的环形.A吃B, B吃C,C吃A. 现有N个动物,以1-N编号.每个动物都是A,B,C中的一种,但是我们并不知道它到底是哪一种.有人用两种说 ...

  7. org.apache.jasper.JasperException: The absolute uri: http://java.sun.com/jsp/jstl/core cannot be resolved in ……

    编程中遇到:org.apache.jasper.JasperException: The absolute uri: http://java.sun.com/jsp/jstl/core cannot ...

  8. 如何移植.NET Framework项目至.NET Core?

    公司的项目一直采用.NET框架来开发Web项目.目前基础类库均为.NET Framework 4.6.2版本.Caching, Logging,DependencyInjection,Configur ...

  9. 03 Java图形化界面设计——布局管理器之FlowLayout(流式布局)

    前文讲解了JFrame.JPanel,其中已经涉及到了空布局的使用.Java 虽然可以以像素为单位对组件进行精确的定位,但是其在不同的系统中将会有一定的显示差异,使得显示效果不尽相同,为此java提供 ...

  10. HTML表单页面的运用

    本章目标:掌握表单基本结构<form> 掌握各种表单元素 能理解post和get两种提交方式的区别 本章重点:掌握各种表单元素 本章难点:post和get两种提交方式的区别 一.    H ...