this code my teacher gave it to us as homework and it does not work with me idk why

VonPryz is correct,

Please try the below code

Write-Host "checking users"

$checkUser = Get-WmiObject -Class Win32_UserAccount -Filter  "LocalAccount="True""  | Select-String -Pattern $testUser

if($checkUser -ne $null) {
  Write-Host "user $testUser found"
} else {
  Write-Host "user $testUser not found"    

The error in the code was stating that the -Pattern parameter was failing because the variable $testuser was null. This was because of the formatting on your first line of code.

Incorrectly Formatted Code:

Write-Host "checking users"$testUser="hgallo"

Correctly Formatted Code:

Write-Host "checking users"

Leave a Comment