Search code examples
powershellshutdownlogoff

Using Powershell to log off remote devices; based on a list of IPs


so as the title self implies i'm trying to code a powershell script so I can log off a list of computers, from a central server which is connected to all of them.

Luckily, the hard part is over. All computers are completely intertwined, and communicating with my server. I'm trying to come up with a powershell script which will automate the log off process, on a list of stations.

So basically, i'd have a basic txt file which would have a list of the station IPs. Based on the list, i would ideally simply run a powershell script which would send out a shutdown -l -f command, to log the stations off.

I can already communicate with the stations, but logging them off is kind of a pain. I'm currently using this simple command to get the stations off

shutdown -m 10.123.45.67 -l -f

naturally, typing this over and over again for 10 or so stations at any given time is time consuming. I've tried searching aroudn here but its somewhat hard to word x_x

Any suggestions?


Solution

  • Looks like this ended up working for me:

    foreach ($_ in get-content computers.txt) 
    {(gwmi win32_operatingsystem -ComputerName $_).Win32Shutdown(4)}