Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > PowerShell

Vista - checked for logged on user on remote machine + remote reboot

Reply
 
Old 03-10-2008   #1 (permalink)
Ben Christian


 
 

checked for logged on user on remote machine + remote reboot

i want to write something like the following...

foreach ($computer in $list) {
if (!(any-user-logged-in-to-$computer)) { reboot $computer }
}

so...there should be some WMI to retrieve that says if any user is logged in
or not...

help =D

My System SpecsSystem Spec
Old 03-10-2008   #2 (permalink)
Shay Levi


 
 

Re: checked for logged on user on remote machine + remote reboot



That would be something like:


$computers ="server1","server2","server3"
gwmi win32_computersystem -computer $computers | where {$_.username} | foreach
{ (gwmi Win32_OperatingSystem -computer $_.__server).reboot() }



-----
Shay Levi
$cript Fanatic
http://scriptolog.blogspot.com
Quote:

> i want to write something like the following...
>
> foreach ($computer in $list) {
> if (!(any-user-logged-in-to-$computer)) { reboot $computer }
> }
> so...there should be some WMI to retrieve that says if any user is
> logged in or not...
>
> help =D
>

My System SpecsSystem Spec
Old 03-10-2008   #3 (permalink)
Ben Christian


 
 

Re: checked for logged on user on remote machine + remote reboot

thanks!

here's the final script

$list = get-content c:\ps-testing\machines.txt
$output = "c:\ps-testing\youroutputfile.csv"

if (test-path $output) { remove-item $output }

add-content $output "Rebooted, Unreachable, Logged in User"

foreach ($machine in $list) {
if (test-path "\\$machine\c$\") {
if (gwmi win32_computersystem -computer $machine | where
{(!($_.username))}) {
gwmi win32_computersystem -computer $machine | foreach {
(gwmi win32_operatingsystem -computer $_.__Server).reboot()
add-content $output "$machine,-,-"
}
}
else { add-content $output "-,-,$machine" }
}
else {
add-content $output "-,$machine,-"
}
}

"Shay Levi" wrote:
Quote:

>
>
> That would be something like:
>
>
> $computers ="server1","server2","server3"
> gwmi win32_computersystem -computer $computers | where {$_.username} | foreach
> { (gwmi Win32_OperatingSystem -computer $_.__server).reboot() }
>
>
>
> -----
> Shay Levi
> $cript Fanatic
> http://scriptolog.blogspot.com
>
Quote:

> > i want to write something like the following...
> >
> > foreach ($computer in $list) {
> > if (!(any-user-logged-in-to-$computer)) { reboot $computer }
> > }
> > so...there should be some WMI to retrieve that says if any user is
> > logged in or not...
> >
> > help =D
> >
>
>
>
My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
How to view remote certificates installed on remote machine? PowerShell
See who is logged in on a remote computer. PowerShell
Remote Desktop Crashes Vista machin logged into Vista General
Reboot via Remote Desktop? Vista General
Remote Desktop - Able to have one user logged in locally and one user via remote desktop? Vista networking & sharing


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46