PowerShell:Get-User –OrganizationalUnit 一级?

标签 powershell

嗨,我正在尝试获取命令 Get-User –OrganizationalUnit 的一级。

Get-User –OrganizationalUnit "domain.local/ou/this-one"

这将返回 this-one ou 及其下的所有内容,我想要一个级别的返回,我缺少什么参数?

最佳答案

创建一个基于可分辨属性的数组:

$aduserinfo = get-aduser -Identity "Username here"
$ou = $aduserinfo.distinguishedname.split(",")[2]
$ou = $ou.substring(3)

使用索引 [2],您将获得您搜索的 OU。Substring删除索引中的前 3 个字符“ou=”。

关于PowerShell:Get-User –OrganizationalUnit 一级?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10280001/

相关文章:

c# - 如何从 C# 执行 Service Fabric Powershell 命令?

powershell - 在属性中使用哈希表键

powershell - 是否可以使 cmdlet 与同时通过管道传输到其中的所有项目一起工作?

c# - 如何使用Powershell知道dotnet build命令是否出错

powershell - 根据属性的数量将对象的子集传递到管道中?

xml - Powershell invoke-webrequest with xml soap envelope body containing £ char 错误

带凭证的 Powershell 远程处理

regex - 在 Powershell 中使用函数替换

powershell - PowerShell工作流Hello World没有输出

azure - 如何在 Azure Cloud shell 中运行 PowerBI REST API