2 개의 함수를 실행하려면 첫 번째 함수 인 "ad"가 사용자 목록을 실행하기 위해 스크립트를 실행하는 동안 csv 형식을 사용하여 출력 함수에서 적절한 출력을 업데이트해야합니다. 출력이 비어 있습니다.Powershell Function in function
$out = "F:\inactive.csv"
function ad() {
$users = Get-Content "C:\dis1.txt"
foreach ($user in $users) {
try {
$memberof = Get-ADUser $user -Properties * -ErrorAction Stop | Select-Object samaccountname, memberof
foreach ($groups in $memberof) {
if ($group=$groups.memberof -like "*mobile*") {
foreach ($name in $group) {
$gpnames += "$((Get-ADGroup $name).samaccountname);"
$gpname= "$($memberof.samaccountname),Exist,$($gpnames)"
}
Write-Output $gpname
} else {
Write-Output "$($memberof.samaccountname),Exist"
}
}
} catch [Microsoft.ActiveDirectory.Management.ADIdentityNotFoundException] {
$usrname = "$($user),NotExist"
Write-Output $usrname
}
}
}
function output {
param($usrname,$memberof,$gpnames,$ad)
New-Object PSObject -Property @{
UserAccount = $memberof.samaccountname
NotExist = $usrname
GroupNames = $gpnames
}
$gpnames = $memberof = $usrname = $null
output | Select-Object useraccount, notexist, groupnames | Export-Csv $out
} return output
죄송합니다, 그것은 무엇을 분명하지 않다 요 너는 묻고있다. 어떤 어려움을 겪으십니까? – JPBlanc
두 개의 함수를 실행해야합니다. 하나는 추출을위한 것이고 다른 하나는 CSV 형식의 출력을위한 것입니다. –
무엇이 오류입니까? 당신이 바로 잡으려고하는 행동은 무엇입니까? – sodawillow