禁用哈希结果?

Disable Hash Result?

我敢肯定这可能是一个非常简单的答案,但我现在已经用这种编码玩了一段时间,需要用一种更加用户友好的方法来格式化它。

代码如下:

$OU1 = 'CN=MbrshpOU, OU=Group, DC=place,DC=com'

Write-Host "Select user:"

$UName=Get-ADGroupMember -identity "$OU1" | Select sAMAccountName | Out-GridView -PassThru
$UserName = $UName 

--Using this displays nothing in the Write-Host below: $UserName = ($UName).sAMAccountName

Write-Host ""
Write-Host " The user is: " -NoNewline;
Write-Host -ForegroundColor Green $UserName -NoNewline;
Write-Host " is this correct? Y/N " -NoNewline

(Choice code follows)

这是当前发生的情况:

"The user is: @{sAMAccountName=first.last} is this correct? Y/N >"

我需要的是:

"The user is: first.last is this correct? Y/N >"

想法?

$OU1 = 'CN=Disabled Users,OU=SecurityGroups,OU=Groups,OU=Production,DC=ad,DC=evotec,DC=xyz'

Write-Host "Select user:"

$UName = Get-ADGroupMember -identity "$OU1" | Get-ADUser -Properties GivenName, SurName | Out-GridView -PassThru
$UserName = $UName

Write-Host ""
Write-Host " The user is: " -NoNewline;
Write-Host -ForegroundColor Green ("$($UserName.GivenName) $($UserName.SurName)") -NoNewline;
Write-Host " is this correct? Y/N " -NoNewline

我使用 Write-Color 的版本(我的 PowerShell 模块):

$OU1 = 'CN=Disabled Users,OU=SecurityGroups,OU=Groups,OU=Production,DC=ad,DC=evotec,DC=xyz'

Write-Host "Select user:"

$UName = Get-ADGroupMember -identity "$OU1" | Get-ADUser -Properties GivenName, SurName | Out-GridView -PassThru
$UserName = $UName

Write-Color -LinesBefore 1 -Text "The user is: ", "$($UserName.GivenName) $($UserName.SurName)", ". Is this correct? Y/N" -Color White, Green, White

您需要知道的是 Get-ADGroupMember 的属性集有限。这意味着您需要使用 Get-ADuser 来获取您需要的缺失属性。

我建议使用 Write-Color 进行显示,因为它更容易处理您正在使用的那种场景。这是 link:https://github.com/EvotecIT/PSWriteColor

当然,我假设您需要名字和姓氏。如果您只想要 SamAccountName,那就容易多了。

$OU1 = 'CN=Disabled Users,OU=SecurityGroups,OU=Groups,OU=Production,DC=ad,DC=evotec,DC=xyz'

Write-Host "Select user:"

$UName = Get-ADGroupMember -identity "$OU1" | Out-GridView -PassThru
$UserName = $UName

Write-Color -LinesBefore 1 -Text "The user is: ", $UserName.SamAccountName, ". Is this correct? Y/N" -Color White, Green, White

或者对于您的代码:

$OU1 = 'CN=Disabled Users,OU=SecurityGroups,OU=Groups,OU=Production,DC=ad,DC=evotec,DC=xyz'

Write-Host "Select user:"

$UName = Get-ADGroupMember -identity "$OU1" | Get-ADUser -Properties GivenName, SurName | Out-GridView -PassThru
$UserName = $UName

Write-Host ""
Write-Host " The user is: " -NoNewline;
Write-Host -ForegroundColor Green $UserName.SamAccountName -NoNewline;
Write-Host " is this correct? Y/N " -NoNewline

我看到你得到了答案,但这是另一种尝试方法...

Get-ADGroupMember -Identity $(Get-ADOrganizationalUnit -Filter '*' | 
Select-Object -Property Name, DistinguishedName | 
Out-GridView -PassThru -Title 'Select a Organizational Unit to see the users in that OU').Name | 
Select-Object -Property Name, SamAccountName | 
Out-GridView -PassThru -Title 'Select a username to review' 
Read-Host -Prompt 'The user is displays as: first.last. Is this correct? Y/N >'

…全部由 OGV 驱动,无需 Write-*。