Repository navigation
Expand file tree
/
Copy pathfinduser.ps1
More file actions
39 lines (35 loc) · 1.41 KB
/
Copy pathfinduser.ps1
File metadata and controls
39 lines (35 loc) · 1.41 KB
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
Add-PSSnapin Quest.ActiveRoles.ADManagement -ErrorAction SilentlyContinue
$ErrorActionPreference = "SilentlyContinue"
# Retrieve Username to search for, error checks to make sure the username
# is not blank and that it exists in Active Directory
Function Get-Username {
$Global:Username = Read-Host "Enter username you want to search for"
if ($Username -eq $null) {
Write-Host "Username cannot be blank, please re-enter username!"
Get-Username
}
$UserCheck = Get-QADUser -SamAccountName $Username
if ($UserCheck -eq $null) {
Write-Host "Invalid username, please verify this is the logon id for the account"
Get-Username
}
}
get-username
$computers = Get-QADComputer | where {$_.accountisdisabled -eq $false} -searchroot '\\activedirectorydsserver\computers'
foreach ($comp in $computers) {
$Computer = $comp.Name
$ping = new-object System.Net.NetworkInformation.Ping
$Reply = $null
$Reply = $ping.send($Computer)
if($Reply.status -like 'Success') {
#Get explorer.exe processes
$proc = gwmi win32_process -computer $Computer -Filter "Name = 'explorer.exe'"
#Search collection of processes for username
ForEach ($p in $proc) {
$temp = ($p.GetOwner()).User
if ($temp -eq $Username) {
write-host "$Username is logged on $Computer"
}
}
}
}