Quantcast
Viewing all articles
Browse latest Browse all 21975

Remotely send message and shutdown depending on users response

Hi all I have a script that works fine on a local machine. It asks users if they want to shut down the machine. However I can't seem to get it to work remotely.

$a = new-object -comobject wscript.shell 
$start = Get-Date
$end = $start.AddMinutes(5)

do{
    $answer = $a.popup("Your machine will shutdown in 5 minutes unless you choose no.",0,"Shut Down",4) 
    if($answer -eq 6 -or $start -eq $start.AddMinutes(5)){ 
        $a.popup("Shutting Down.")
        Write-Host $answer
        Stop-Computer -ComputerName $env:COMPUTERNAME
    }
    if($answer -eq 7){ 
        $a.popup("Aborted.")
        break 
    }
}until($start -ge $end) 

Here's the script.

Here is what I'm using to call it.

Invoke-Command -computername tsvc2552142x003 -FilePath '\\tsvc2552142x011\C$\Users\cody\Desktop\remoteshutdown.ps1'

Thanks I thought I read somewhere that popup runs in the background. If that is true what do I need to use that would store a users input?


Viewing all articles
Browse latest Browse all 21975

Trending Articles