PowerShell Script um spezielle Rechner herunterzufahren
Hi Leute,
wie man per CMD Rechner runterfährt ist mir bekannt. Mir geht es jetzt aber um den "Luxus" in solch einem Script.
Es soll wie folgt aufgebaut sein:
Doppelklick auf die .cmd -> Abfrage: "Welcher PC soll heruntergefahren werden?" -> da soll dann die Möglichkeit gegeben sein den PC einzutragen und DANACH soll die Abfrage kommen, wann der PC heruntergefahren werden soll 0 = sofort oder ansonsten die normale Zeitangabe in Sekunden -> Ausführung!
Kann mir da jemand helfen?
wie man per CMD Rechner runterfährt ist mir bekannt. Mir geht es jetzt aber um den "Luxus" in solch einem Script.
Es soll wie folgt aufgebaut sein:
Doppelklick auf die .cmd -> Abfrage: "Welcher PC soll heruntergefahren werden?" -> da soll dann die Möglichkeit gegeben sein den PC einzutragen und DANACH soll die Abfrage kommen, wann der PC heruntergefahren werden soll 0 = sofort oder ansonsten die normale Zeitangabe in Sekunden -> Ausführung!
Kann mir da jemand helfen?
Bitte markiere auch die Kommentare, die zur Lösung des Beitrags beigetragen haben
Content-ID: 313544
Url: https://administrator.de/forum/powershell-script-um-spezielle-rechner-herunterzufahren-313544.html
Ausgedruckt am: 22.04.2025 um 05:04 Uhr
20 Kommentare
Neuester Kommentar

PS
Regards
cls
$pc = Read-Host "Welcher PC soll heruntergefahren werden?"
$time = Read-Host "Wann soll der Rechner heruntergefahren werden?"
if ($time -eq ""){$time = 0}
& shutdown /M "\\$pc" /s /t $time /f

Zitat von @clSchak:
das "/f" kann ggf. aber zu Problemen führen wenn der Benutzer gerade noch was speichern kann ist das hilfreicher
But if no one is sitting in front of it or you want to be sure that the system is off after work das "/f" kann ggf. aber zu Problemen führen wenn der Benutzer gerade noch was speichern kann ist das hilfreicher
But i'm sure he knows the command ... so he can decide itself whats right for him.

Really ????
clear screen.
. That's the reason!
When i'm trying to start it as powershell file nothing happens
You are new in powershell right 
It works 100%. I suppose you did not set the Executionpolicy in an administrative command prompt?!
http://www.admin-source.de/BlogDeu/401/powershell-executionpolicy-richt ...
http://www.admin-source.de/BlogDeu/401/powershell-executionpolicy-richt ...

Yes.

You should first read
https://blog.udemy.com/powershell-tutorial/
before you post and ask such damn easy things in an administrator board
https://blog.udemy.com/powershell-tutorial/
before you post and ask such damn easy things in an administrator board

This command "Run As Admin" is not available for ps1 without registry modification! You can start it un-elevated without problems in a ps console or the ISE!
http://www.gutefrage.net/
and not to an administrator board. We can't explain the scripting basics to everyone, man.
Windows closes .... nothing happens!!!!!
OMG, open Powershell ISE and paste it there then you see any potential messages. This script is so easy, and doesn't contain any magic and it works, tested!but ok ...."damn easy things" ... alright.
They are really easy, if you would first read the fundamentals (link) how to work with powershell, otherwise you should go tohttp://www.gutefrage.net/
and not to an administrator board. We can't explain the scripting basics to everyone, man.

Are the machines in a domain environment ?
If yes the account you use to start the script needs enough local permissions on the machines, also you need to make sure that file and print services or Port 135 is open in the firewall on the clients.
Here it works without problems (domain).
If your management station is not in the domain. You need to set a registry entry to allow remote shutdown (LocalAccountTokenFilterPolicy) because of UAC.
If yes the account you use to start the script needs enough local permissions on the machines, also you need to make sure that file and print services or Port 135 is open in the firewall on the clients.
Here it works without problems (domain).
If your management station is not in the domain. You need to set a registry entry to allow remote shutdown (LocalAccountTokenFilterPolicy) because of UAC.

You would help us a lot if you post the errormessage instead of saying "its not working" the whole time, thanks. I would not have posted it if it doesn't work.
And please post what you have copied then we can see if there is an error in copying, perhaps wrong encoding in your browser, on the board or something else.
And please post what you have copied then we can see if there is an error in copying, perhaps wrong encoding in your browser, on the board or something else.

& shutdown /M "\\$host" /s /t $time /f
Where did you get the variable $host from ??? In my script this is the variable named $pc. Copy the code above correctly then it will run. No wonder when he doesn't find the hostname if the variable is not defined