Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Find who is logged in on a PC #39

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions projects/FindUser/FindUser.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
Import-Module ActiveDirectory

$computer = Read-Host "What is the name of the computer: "
$dns = Resolve-DnsName -Name $computer
$ip = $dns.IPAddress


#Test the connection to the computer. If it is offline it provides the last known IP address.
ElseIF(!(Test-Connection -ComputerName $dns.address -BufferSize 16 -ErrorAction 0 -Count 1 -Quiet)){
Write-Host "The computer offline. Last known IP address: $IP"
}

#Checks to see if No One is logged in.
else{
$username = Get-WmiObject win32_computersystem -computername $computer -Property username | Select-Object -ExpandProperty username
if($username -eq $null)
}
{
Write-Host "No one is currently logged into $computer"
}

#Provides the user that is currently logged into the computer.
else{
Write-Host "`n"
$ADuser = $username.Replace("DOMAIN\","")
$ADusers = Get-ADUser -Identity $ADuser -Properties name | Select-Object name
$Name = $ADusers.name
Write-Host "Username: $ADuser"
Write-Host "Name: $Name" }
;