Windows Vista Forums

checked for logged on user on remote machine + remote reboot
  1. #1


    Ben Christian Guest

    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

  2. #2


    Shay Levi Guest

    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

    > 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

  3. #3


    Ben Christian Guest

    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:

    >
    >
    > 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
    >

    > > 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

checked for logged on user on remote machine + remote reboot problems?

Similar Threads
Thread Thread Starter Forum Replies Last Post
How to view remote certificates installed on remote machine? rmq PowerShell 2 20 Feb 2009
See who is logged in on a remote computer. Pedro PowerShell 2 08 Aug 2008
Remote Desktop Crashes Vista machin logged into Hugh G. Johnson Vista General 1 20 Jan 2008
Reboot via Remote Desktop? Bill Cohagan Vista General 4 29 Jul 2007
Remote Desktop - Able to have one user logged in locally and one user via remote desktop? Paul Murdock Vista networking & sharing 3 20 Oct 2006