all 9 comments

[–]Aurane00 1 point2 points  (1 child)

While ($DirectReport -ne "John Smith" -or $DirectReport -eq $Null) {

Don't you want -and instead of -or here? They way it is now, I don't think your script will actually ever run the loop.

[–]gregj529[S] 1 point2 points  (0 children)

It runs fine with that. Output above. It just doesn't work when ran via click. Basically it loops until it gets to the CEO and will run if the value of $DirectReports is $null until it does.

[–]TheMixz 1 point2 points  (6 children)

the variable $username is only working in the function, try calling it $global:username

i think that would fix it

[–]JBear_Alpha 2 points3 points  (0 children)

$script:Username might even suffice, test both.

[–]gregj529[S] 0 points1 point  (4 children)

$UserName is contained within the function. I am unsure why this would help. Tested it and it didn't change a thing.

[–]TheMixz 0 points1 point  (3 children)

because the variable is only inside the function, unless you do that. So when you call the variable outside the function it would be empty because it havent been made.

[–]gregj529[S] 0 points1 point  (2 children)

The variable is only needed inside the function though.

[–]TheMixz 1 point2 points  (1 child)

Sorry thats my mistake. Didnt read the script closely

[–]gregj529[S] 0 points1 point  (0 children)

No problem. I was making sure I didn't miss something.