If I run this by itself it works fine and returns a list of servers, but when I have it followed by the rest of the code that starts with "$Remote Server = Read-Host "Enter server name to log users off of: " it doesn’t list the servers, it just promprts for the server name and then continues with the rest of the code on down. I can’t figure out why it doesn’t show the list of servers first.
Hmmm … call me picky but Get-ADUser does sound as it should not show servers at all.
Have you tried forcing the output with
Since you seem to list the possible options with a command before this one why don’t you use an Out-GridView and let the user select the server with the mouse? That might even reduce errors because it avoids typos.
I debated for a bit commenting on this. I felt ultimately there were a couple things that needed to be said regarding the communication here and as a mod I felt it was important enough to address. My aim isn’t to call anyone out but to comment and provide some guiding principles. My intent is to show messages can be received in different ways by folks. Communication is difficult and forums like this, things can be lost to really take away from the goal.
Sarcasm doesn’t really come through in all contexts of written prose. There’s certainly a time and place for it, but I don’t think it’s here, in a PowerShell online forum. As to why, it does not add value to these types of conversations. Additionally, I think ways of declaring sarcasm can have multiple meanings. I think it’s an assumption to say a winky face = sarcasm, as it could mean different things to different people, and it also depends on the context of the message. I think this clouds any message and only adds to the confusion of communication.
I do also want to mention the response did not come off as sarcastic to me. I did look at each version of the post to make sure the message wasn’t change from OP to ensure I would not read it differently. When I read the response, it read more like a misunderstanding of what the code did, maybe not seeing the thing it was being piped too at first glance, and it came off as ‘obviously Get-ADUser doesn’t return computer objects, look at what the cmdlet name says’. I don’t see what value sarcasm adds to this or why it would have been used. Just a reminder that regardless of intent, messages are interpreted by the people who are receiving it. Sometimes, asking for clarification, giving folks the benefit of the doubt, and even a simple apology goes a long way. We can’t always know if someone would read that as sarcastic or not given the context, so it’s better to avoid in this context.
It’s possible I misinterpreted this but when provided some things to try, I would avoid saying ‘it’s above my pay grade’. I would also avoid stating ‘I tried everything’ then ask for how to implement it, and not share any of the code that you tried as a follow up. if it is above your paygrade, then you have someone else who is managing the code at your company, and you should start there. It’s highly unlikely you’ve tried ‘everything’. Perhaps it might be helpful to know why we are asking for it. Simply put, we need to know what you tried to help you. We aren’t here to write code for folks, though occasionally people are nice enough to do that. In order to get help, you do need to provide what you tried specifically. I’m pointing this out as this was stated in reference to Out-Host, and simply saying ‘I’m a novice’ doesn’t help folks who do genuinely wish to help, but we certainly can’t translate what ‘tried everything means’. In general folks who help on forums often get roped into helping a bit more than they should. When someone says “I tried everything” but doesn’t share or says something like above my paygrade, it comes off as you’re not willing to put in the effort, so you’re asking someone else to do that to ‘fix it’ for you. While it occasionally happens, that isn’t what these forums are for and that’s not the expectation of anyone responding to a thread. I’m sure it wasn’t your intention to come off this way and from your perspective you’re thinking it’s probably something quick to write but we’re really about helping others learn and sometimes that means writing some code, failing, and coming back with ’ I tried to add this code here, and it’s erroring with this message. I tried to address the error like this, but I have not been successful, what else can I do to accomplish X task? It’s going to be much easier to assist you, and furthermore, it’s clear you’re putting in the effort to solve your problems by writing code and it might just be that something needs slightly tweaked. I hope that makes sense.
Again, I am not trying to hurt anyone’s feelings or call anyone out, I just want to take a moment to share some things and hopefully we can all grow a bit from it.