Hi Guys,
So i have a script that ran fine, all of a sudden, it seems like it isn’t passing a variable into my loop. Let me explain, i have this piece of code:
$sessionhost = @("***","***","***") $filestore = "***" $user = Read-Host "Please enter username" foreach($sessionhosts in $sessionhost) { $session = ((quser /server:$sessionhosts | ? { $_ -match $user }) -split ' +')[2] logoff $session /server:$server }
Which finds a user based on input, and logs them off the target RDS server. The issue im having is, whenever i run the script and enter a user, it just logs out whoever is running the script at that time! I think it isn’t passing the $user variable and is just running the logoff command locally, which is far from ideal. But it seemed to break itself (it’s code, so surely it can’t) but that’s what it seems like! Is there an error here that i’m blatantly missing? This script has ran successfully before, many times by the way!
Even if i can see what gets passed to $user, so i can confirm this, debugging is a skill i’m trying to get better at!