简体   繁体   English

提取Active Directory用户信息

[英]Pull Active Directory user information

Hi I have a script that will partially work if I write "write-host" but doesn't work at all when exporting the information to a text file. 嗨,我有一个脚本,如果我编写“ write-host”,它将部分起作用,但是在将信息导出到文本文件中时根本不起作用。 I want to find the user ID's description, name, displayname and manager. 我想找到用户ID的描述,名称,显示名称和管理器。 Please help me understand why it isn't working. 请帮助我了解为什么它不起作用。

Import-Module ActiveDirectory

$document = "C:\Temp\ADupdate yyyy.txt"

Clear-Content $document

<# 
-ne = not equal CN=xxpc37254,OU=Standard,OU=Users,OU=Corporate,DC=we,DC=dirsrv
-eq = equal
-lt = less than
-gt = greater than
-ge = greater than or qual to
-le = less than or equal to
#>

$Header = `
"User ID" + "|" + `
"Display Name" + "|" + `
Description" + "|" + `
"ID Owner" + "|" + `
"ID Owner Name"


#Write out the header
$Header | Out-File $document -Append

#$Users = Get-ADUser -Filter {name -like "xxpc*" -or name -like "xxmd*"} - SearchBase "OU=Corporate,DC=we,DC=dirsrv,DC=com" -Properties name, displayname, description, manager 
$Users = Get-ADUser -filter {name -like "xxpc*" -or name -like "xxmd*"} -Properties name,   displayname, description, manager 


foreach ($User in $Users)
{
#manager missing
if ($Users.Manager -eq $null) {
    $owner = "MISSING"
    $ownerid = "MISSING"
    $ownername = "MISSING"

} else {
#grab the manager's name, surname, and department
    $owner = Get-ADUser ($userid.Manager) -Properties GivenName, Surname, Department
    $ownerid = $owner.Name
    $ownername = $owner.Surname + "." + $owner.GivenName
}

$listing = `
$Users.Name + "|" + `
$Users.DisplayName + "|" + `
$Users.Description + "|" + `
$ownerid + "|" + `
$ownername 

$listing | Out-File $document -Append

Ok. 好。 The reason why it's not working is probably because the if statement inside the foreach is wrong. 它不起作用的原因可能是因为foreach中的if语句错误。 You should use $user inside the foreach, not $users like you use here. 您应该在foreach中使用$ user,而不要像在此使用$ users那样。

That being said, you should read up on creating custom objects, and get the data you want, create a custom object and write that to the pipeline. 话虽这么说,您应该通读创建自定义对象的知识,并获取所需的数据,创建一个自定义对象并将其写入管道。 That way you can use the output in a lot of different ways, whether that is to write to a text file, a csv file, xml or just to the screen. 这样,您可以以多种不同的方式使用输出,无论是写入文本文件,csv文件,xml还是仅写入屏幕。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 用于从 Azure Active Directory 检索用户信息的 VBS 脚本 - VBS script to retrieve user information from Azure Active Directory 从Active Directory说明中拉出名称 - Pull out name from Active Directory description 使用Powershell查询Active Directory用户信息 - 看似等效的语法,不同的结果? - Querying Active Directory user information using Powershell - seemingly equivalent syntax, different results? 使用Java查找简单的Active Directory信息 - Using Java to find simple Active Directory Information Active Directory用户名约定? - Active Directory User Name Convention? Azure Active Directory 用户报告 - Azure Active Directory User report Powershell 图形用户界面。 从动态列表框中选择一个项目,随后从 Active Directory 中卸载用户信息 - Powershell GUI. Selecting an item from a dynamic ListBox with subsequent unloading of user information from Active Directory Ask a question 使用Powershell更新Active Directory中的Active Directory用户属性 - Updating Active Directory user properties in Active Directory using Powershell Powershell不会从Active Directory中提取所有计算机名称 - Powershell won't pull every computer name from Active Directory 如何让 psloggedon 从 Active Directory 中提取? - How can I get psloggedon to pull from Active Directory?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM