禁用哈希结果?

时间:2019-04-22 18:49:29

标签: powershell active-directory powershell-ise

我敢肯定这可能是一个非常简单的答案,但是我现在一直在使用这种编码方式,并且需要用一种更加用户友好的方法对其进行格式化。

代码如下:

$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)

这是当前发生的情况:

  

“用户是:@ {sAMAccountName = first.last}正确吗?是/否>”

我需要的是

  

“用户是:first.last是否正确?是/否>”

想法?

2 个答案:

答案 0 :(得分:0)

$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进行显示,因为在您使用的这种情况下播放要容易得多。这是链接: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

答案 1 :(得分:0)

我看到你给了你答案,但这是尝试此方法的另一种方式...

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-*。