0
입니다. PowerShell을 처음 사용하기 때문에이 스크립트는 '스위치'를 사용할 때 작동합니다. 나는 'while'을 사용하여 작동 시키려고했지만, 값이 1인지 0인지를 알 수 있습니다.값은 x
아래 스크립트를 보면 누군가 내가 잘못 가고있는 것을 지적 할 수 있습니까?
귀하의 도움에 감사드립니다. 여기
cls
Import-Module -Name ActiveDirectory
$ADpath = "OU=OU1,DC=DC1,DC=DC2,DC=DC3";
$i = 0
function yaynay(){
$i = Read-Host "`nSearch again.." "Y `tOR N";
switch -Regex ($i.ToUpper()){
"Y(es)?"{$i -eq 1}
default {$i -eq 0}
}
get-pssession | remove-pssession
}
function TableFormat(){
[email protected]{label='Full Name';Expression={$_.name};width=20},
@{label='Login Name';Expression={$_.samaccountname};width=15},
@{label='OU';Expression={(($_.DistinguishedName -split "=",4)[3] -split ",",2[0]};width=15}
$ADusr | Format-Table $x1
}
function getOut(){
Write-Host "AD Search will now exit"
exit
}
function ADUwrite(){
Write-Output "`n Cannot find user: $InputUsr"
}
while ($i -lt 1)
{
$InputUsr = Read-Host "Enter One or More Letters To Search For User"
$InputUsr1 = $InputUsr
if($InputUsr -eq ""){
write "`n No Search Criteria Entered... Exiting AD User Search"
exit
}
$InputUsr = "*"+$InputUsr+"*"
if([string]$InputUsr1 -contains "*"){
$InputUsr = $InputUsr.Replace($InputUsr, $InputUsr1)
}
$ADusr = Get-ADUser -Filter {name -like $InputUsr} -SearchBase $ADpath
$x=$ADusr.name.length
if($x -gt 0){
TableFormat
}
else{
$InputUsr = $InputUsr1.ToUpper()
ADUwrite $InputUsr
};
yaynay($i)
if($i = 1){
GetOut
}
Get-PSSession | Remove-PSSession
}
또한 yaynay()의'$ i'는 'Y'또는 'N'이 포함 된 문자열이 될 것입니다. 그것은 1이나 0과 결코 같지 않을 것입니다. 그리고 그것은 "yaynay"함수가 모든 PSSession을 제거한다는 것이 다소 이상합니다. 더 나은 접근 방식은 yaynay 'bool'을 리턴하는 것입니다. 'if (yaynay) {GetOut}'. –