Hello, 2nd time posting, so still fairly new and I know i’m just missing something with objects on this script, but can’t figure it out.
I want the output to include the quser output from all servers, but instead I get the quser output from the server I’m running the script on only. And 3 separate outputs of that because the text file contains 3 servers at the moment.
Server Operating System User
------ ---------------- ----
TSTEST2016-1 Win Srv 2016 Std User1
=
TSTEST2016-1 Win Srv 2016 Std User1
=
TSTEST2016-1 Win Srv 2016 Std User1
I know the “write-output” parts are wrong, but i was just trying something at the moment
Everything works except the foreach iteration, and i don’t know why i have a hard time grasping this part.
Any help would be appreciated.
This works great. Thanks, Olaf.
One last question, the command will run perfectly, and somewhat inadvertently so.
The “users” are people from my team, so just trying to automate where everyone is logged on or disconnected. I want to exclude where it’s not a user from my team, and it’s doing it, but it’s doing it because the parameters for users gives a null-valued expression. So it throws a lot of errors, but in the end, gives me the right output.
You cannot call a method on a null-valued expression.
At D:\~Scripts\Test\GetUsers.ps1:70 char:5
+ [PSCustomObject]@{
+ ~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
So the question is, how to ignore empty objects to not throw errors, but still give me the output of just my team?
I cannot test at the moment but to cleanup your code a little more you should provide a list of your users and check if the logged on user you get from a server is in this list of users. That’s much easier to read I think and in case easier to maintain. But the usernames have to be complete for this way of checking. You cannot use wildcards.