powershell 使用PowerShell检查活动目录中组用户的帐户

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了powershell 使用PowerShell检查活动目录中组用户的帐户相关的知识,希望对你有一定的参考价值。

#http://technet.microsoft.com/en-us/library/ff730967.aspx
$a = 'wbrown@fibrelite.com', 'wayne@fibrelite.com', 'nathan@fibrelite.com', 'vikki@fibrelite.com', 'jjackson@fibrelite.com', 'dcrowther@fibrelite.com', 'robert@fibrelite.com', 'sue@fibrelite.com', 'david@fibrelite.com', 'jostott@fibrelite.com', 'joanne@fibrelite.com', 'martin@fibrelite.com', 'ian@fibrelite.com', 'ryan.reinke@opwglobal.com', 'jacqui@fibrelite.com', 'mike.gritton@opwglobal.com', 'Surya@fibrelite.com', 'laura@fibrelite.com', 'caroline@fibrelite.com'
$file = 'C:\psp\UserNames.txt'
If (Test-Path $file){
	remove-item $file
}
foreach ( $item in $a ) 
{ 
$item
$strFilter = "(&(objectCategory=User)(userPrincipalName=$item))"
$objDomain = New-Object System.DirectoryServices.DirectoryEntry
$objSearcher = New-Object System.DirectoryServices.DirectorySearcher
$objSearcher.SearchRoot = $objDomain
$objSearcher.PageSize = 1000
$objSearcher.Filter = $strFilter
$objSearcher.SearchScope = "Subtree"
$objSearcher.PropertiesToLoad.Add("Name")
$objSearcher.FindAll() | ForEach-Object -begin {"Results"} -process {$_.properties.item("name")|Out-File $file -Append} -end {"Done"}
}
#http://technet.microsoft.com/en-us/library/ff730967.aspx

$a = 'Peter Huisers','Nagesh Kelkar','Lurui Qiu','Sarah White-Harvey','Tom OKeefe','Larry Cychosz','Tom Wieczorek','Erik Zerner','Rob Weichers','Dana MacPhail','Huda Ahmed','David Crowther','David Holmes','Emma Bean','Emma Burton','Hayley Egan','Ian Thompson','Jacqui Preston','James Jackson','Jo Stott','Joanne Westwood','Martin Heath','Martin Walsh','Nathan Pickles','Olivia Jennings','Paul Rutherford','Robert Caddick','Sandy Beverstock','Savvas Achilleos','Sue Clayton','Vikki Maher','Helen Lundberg','Karin Blomkvist','Asa Ekstrom','Ann Tingvall','Johan Viltling','Marianne Asvik','Laila Juntunen','Ryan Reinke','Thomas Hasche','Mattias Lindgren','Dana Hansen','Anthony Brett','Christophe Sanvoisin','Henrik Olsen','Peter Hunt','Gary Heard','Jagajit Singh','Tony Tang','Elodie Kong'

foreach ( $item in $a ) 
{  
	$strFilter = "(&(objectCategory=User)(Name=$item))"
	
	$objDomain = New-Object System.DirectoryServices.DirectoryEntry
	
	$objSearcher = New-Object System.DirectoryServices.DirectorySearcher
	$objSearcher.SearchRoot = $objDomain
	$objSearcher.PageSize = 1000
	$objSearcher.Filter = $strFilter
	$objSearcher.SearchScope = "Subtree"
	$colResults = $objSearcher.FindAll()
	$item
	$colResults.Count
	
}

以上是关于powershell 使用PowerShell检查活动目录中组用户的帐户的主要内容,如果未能解决你的问题,请参考以下文章

如何使用 C# 按组策略检查 PowerShell 禁用

powershell PowerShell:检查Microsoft / Windows Update是否需要重新启动。安装补丁后即可使用。

powershell 检查PowerShell模块更新

powershell Powershell检查网络

powershell 用于检查更新的Powershell脚本

powershell 检查powershell的版本