2014-01-28 5 views
0

8 일 이내에 만료 예정인 특정 사용자의 광고 그룹을 가져 오는 데 문제가 있습니다.사용자 그룹이 만료되어 그의 그룹이 만료됩니다.

은 내가 가진 사용자를 찾을 수 있어요 :

$users = Search-ADAccount -AccountExpiring -TimeSpan "7" | FT sAMAccountName -HideTableHeaders

을하지만 난 foreach는하려고하면

foreach ($user in $users) { Get-ADUser -identity $user -Properties memberof | select -ExpandProperty memberof | %{ $_.Split(',')[0]; }

를 내가 얻을 :

가져-ADUser : 매개 변수를 바인딩 할 수 없습니다 '정체'. 형식이 "Microsoft.PowerShell.Commands.Internal.Format.FormatEndData" "Microsoft.PowerShell.Commands.Internal.Format.FormatEndData"값을 "Microsoft.ActiveDirectory.Management.ADUser"로 변환 할 수 없습니다. C : \ scripts \ get expiry.ps1 : 13 char : 23 + Get-ADUser -identity $ user -Properties memberof | -ExpandProperty 멤버를 선택 ... + ~~~~~ + CategoryInfo : InvalidArgument : (:), ParameterBindingException + FullyQualifiedErrorId [-ADUser 가져 오기] : CannotConvertArgumentNoMessage, Microsoft.ActiveDirectory.Management.Commands.GetADUser

을하지만, 한 사용자를 위해 작동 :

Get-ADUser -identity guest1 -Properties memberof | select -ExpandProperty memberof | %{ $_.Split(',')[0]; }

CN = MY_GROUP

내 질문에 ADUser에 FormatEndData 변환하는 방법은? 또는 내가 필요한 것을 얻을 수있는 더 좋은 방법이 있습니까?

답변 : 작은 도움으로

은 내가

$datefrom = (Get-Date) $dateto = (Get-Date).AddDays(8) $users = Get-ADUser -filter {(AccountExpirationDate -gt $datefrom) -and (AccountExpirationDate -lt $dateto)} -Properties samaccountname,memberof

foreach ($user in $users) { $groups = $user | select -Property samaaccountname -ExpandProperty memberof | %{ $_.Split(',')[0]; } | %{ $_.Split('=')[1]; } foreach ($group in $groups){ if ($group -eq "MY_GROUP") { Write-Host $user.samaccountname echo $group }
} }

답변

0

아래 코드로 내가 원하는 것을 얻을 당신이 실제로 $로 옮기고 무엇인지 고려 할 수 있었다 사용자. Format-Table은 파이프 라인에서 개체를 가져 와서 멋진 표를 만들기 위해 화면 서식을 추가합니다. 변수에 보낼 때, 그것은 문자열과 형식 제어 문자의 묶음 인 - 변수 껍질에있는 것입니다. 여러분의 powershell 객체가 아닙니다.

형식 표를 제거하고 더 잘 작동하지 않는지 확인하십시오.