-
Notifications
You must be signed in to change notification settings - Fork 0
/
report service accounts OU path.ps1
36 lines (29 loc) · 1.11 KB
/
report service accounts OU path.ps1
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
# Import the necessary modules
#Import-Module ActiveDirectory
# Specify the path to the exported CSV file
$csvPath = "C:\Users\914476\OneDrive - Giant Eagle, Inc\service accounts.csv"
# Read the CSV file
$accounts = Import-Csv $csvPath
# Create an array to store the results
$results = @()
# Iterate through the accounts and look them up in Active Directory
foreach ($account in $accounts) {
$accountName = $account.AccountName
$accountOwner = $account.Manager
# Check if the account exists in Active Directory
if (Get-ADUser -Filter {SamAccountName -eq $accountName} -ErrorAction SilentlyContinue) {
# Get the account details
$user = Get-ADUser $accountName -Properties DistinguishedName, managedby
# Add the account details to the results array
$result = [PSCustomObject] @{
AccountName = $accountName
OUPath = $user.DistinguishedName
UPN = $user.UserPrincipalName
AD_Manager = $user.managedby
SN_Owner = $accountOwner
}
$results += $result
}
}
# Display the results
$results | Format-Table -AutoSize