While learning Powershell I am trying to make a script that will prompt me for my Domain Admin account details and then the Hostname that I would like to check to see who is currently logged in and whether the machine is locked/active/logged out/turned off.
I have the below so far, but unable to see why I keep getting errors when testing on my own machine that I do have admin access to,
Any ideas please?
Error I am getting is: "Error browsing Network...."
#Get my domain Admin Account details$Creds = Get-Credential
#To Query a PC for Current Logged in State$ComputerName = Read-host "Please enter the Hostname"
#query user /server:$ComputerName -credential $CredsC:\scripts\psloggedon.exe -accepteula \\$ComputerName -credential $Creds
#Get Admin Account details $Creds = Get-Credential #To Query a PC for Current Logged in State $ComputerName = Read-host "Please enter the Hostname" #query user /server:$ComputerName -credential $Creds C:\scripts\psloggedon.exe -accepteula \\$ComputerName -credential $Creds
In reply to postanote:
Thanks Im not near a pc now so cant test but think i did try something similar though it didnt show time stamps or if they were active or locked screen etc. I do hqve doman admire n access though its under a different account. Eg my everyday account is peter My admin account is peterx3
In reply to Private_IT_Support:
I've opted for the easier option for now to save time as it captures pretty much all I need, for now while i'm learning
$TargetHostname = 'localhost'
query user /server:$TargetHostname
However, I'm puzzled with the results:
How can Idle Time be 1 Day and 7 hours, when i just turned it on about 1.5 hours ago this evening?
Easier is almost always best. I say almost, because sometimes easier does not get you all you want. As for what you are seeing in the time slot, that is not uptime. The idle time (the number of minutes since the last keystroke or mouse movement at the session) More details here: 'technet.microsoft.com/en-us/library/bb490801.aspx' If you are after uptime, you'd try something like.... # Getting host up time, by converting the computer’s last boot time into a DateTime then subtract that from the current Get-Date (Get-Date) - ([Management.ManagementDateTimeConverter]::ToDateTime((Get-WmiObject Win32_OperatingSystem).LastBootUpTime))