Hi Guys,
I’m trying to make a little tool, but at the moment i’m struggling to get my ElseIF working. I can’t see the flaw in my logic,
it currently looks like this:
Import-Module ActiveDirectory
$StudentNo = CustomInputBox "Please Give the Student Number"
$status = Get-ADUser -Filter "SAMAccountName -like '$StudentNo'" | Select-Object Enabled
if ("$status -Match '@{Enabled=True}'") {
Show-MessageBox "Account is Enabled"
} ElseIf ("$status -Match '@{Enabled=False}'") {
Show-MessageBox "Account is Disabled"
}
I have it using Windows Forms, whatever i type in (in this case it takes a student number which is the SAMAccountName)
it shows as enabled, even if the status, when checked seperately is @{Enabled=False}.
If you want the whole code, i can provide, but this seems to be the problem area?
Thank you.
Maybe try
if ($status.enabled -eq 'True') {
Show-MessageBox "Account is Enabled"
} Else {
Show-MessageBox "Account is Disabled"
}
As it is (probably, cant check sorry) a boolean:
if ($status.enabled) {
Show-MessageBox “Account is Enabled”
} Else {
Show-MessageBox “Account is Disabled”
}
I think the problem is with your code. Can you send us the code? Here is what I have.
$StudentNo = Read-Host "Please give the student number"
$status = Get-ADUser -Filter {SamAccountName -like $StudentNo} | Select-Object enabled
if ($Status.enabled -eq "True"){
Write-Output "Account is eabled"
}else{
Write-Output "Account is disabled"
Thank’s for all your help guys,
I got it working using the following
if ($status.Enabled -eq $true) {
Show-MessageBox "Account is Enabled"
} ElseIf ($status.Enabled -eq $false) {
Show-MessageBox "Account is Disabled"
}
Again, thank you!