JoeRod
JoeRod

Reputation: 921

Powershell Out-file with variable

I'm trying to write a script that will check if a string is null and if it is output the user name to a file so I can go back and check that file and see who is null. Below is my code, the script is not writing to the out-file any ideas?

$user = "[email protected]"
#just gets the users info
$user_info = gam info user $user 
$suspended = $user_info | Select-String -pattern "Account Suspended: true"
if ($suspended = $null) {
  $user | Out-File -FilePath C:\scripts\not_suspended.txt -append -Encoding utf8
  }

Upvotes: 1

Views: 4940

Answers (1)

Lee
Lee

Reputation: 144176

You are assigning $null to $suspended in your if statement. Use -eq instead to do the comparison:

if ($suspended -eq $null) {
  $user | Out-File -FilePath C:\scripts\not_suspended.txt -append -Encoding utf8
}

Upvotes: 5

Related Questions