mirror of
https://dev.azure.com/effectory/Survey%20Software/_git/Cloud%20Engineering
synced 2026-02-27 18:52:18 +01:00
Updated script to use automatic dates
This commit is contained in:
@@ -1,90 +1,90 @@
|
||||
# import AD Module
|
||||
Import-Module activedirectory
|
||||
Import-Module activedirectory
|
||||
#Set-ExecutionPolicy unrestricted
|
||||
|
||||
#---------------------------
|
||||
#-------- Variable ---------
|
||||
#---------------------------
|
||||
$ADUserMembers=""; $ADUser=""
|
||||
$ADGroupName=""; $ADGroupCategory=""; $ADGroupScope=""
|
||||
$i=0
|
||||
|
||||
#---------------------------
|
||||
#------- Functions ---------
|
||||
#---------------------------
|
||||
function Get-ADGroupName ($DN)
|
||||
function Get-ADGroupName ([string] $ADDistinguishedName)
|
||||
{
|
||||
$ADGrpName= (Get-ADGroup -Filter {DistinguishedName -eq $DN}).SamAccountName
|
||||
$ADGrpName= (Get-ADGroup -Filter "DistinguishedName -eq '$ADDistinguishedName'").SamAccountName
|
||||
return $ADGrpName
|
||||
}
|
||||
|
||||
|
||||
function Get-GroupMemberOf ($ADGroupName)
|
||||
function Get-GroupMemberOf ([string] $ADGroupName)
|
||||
{
|
||||
if ($ADGroupName -eq "# Developer") {
|
||||
return
|
||||
}
|
||||
$ii++; $a=0
|
||||
$Message=""; $Prefix=""
|
||||
$GroupCategory=""; $GroupScope=""; $GroupName=""
|
||||
if ($ADGroupName -eq "# Developer") { return } # prevent recursing
|
||||
|
||||
$ii++; $a=0
|
||||
$Message=""; $Prefix=""
|
||||
$GroupCategory=""; $GroupScope=""; $GroupName=""
|
||||
|
||||
For ($a=0; $a -lt $ii; $a++) {$Prefix = $Prefix + " "}
|
||||
For ($a=0; $a -lt $ii; $a++) {$Prefix = $Prefix + " "}
|
||||
|
||||
$DNs=(Get-ADGroup $ADGroupName -Properties *).MemberOf
|
||||
if ($DNs.count -ne 0)
|
||||
{
|
||||
foreach ($DN in $DNs)
|
||||
{
|
||||
# $Prefix =" $ADGroupName => "
|
||||
$GroupName = (Get-ADGroupName $DN)
|
||||
$GroupCategory = (Get-ADGroup $GroupName -Properties *).GroupCategory
|
||||
$GroupScope = (Get-ADGroup $GroupName -Properties *).GroupScope
|
||||
$DNs=(Get-ADGroup $ADGroupName -Properties *).MemberOf
|
||||
if ($DNs.count -ne 0)
|
||||
{
|
||||
foreach ($DN in $DNs)
|
||||
{
|
||||
$GroupName = (Get-ADGroupName $DN)
|
||||
$GroupCategory = (Get-ADGroup $GroupName -Properties *).GroupCategory
|
||||
$GroupScope = (Get-ADGroup $GroupName -Properties *).GroupScope
|
||||
|
||||
$Message="$Prefix $ADGroupName => $GroupName [$GroupCategory - $GroupScope]"
|
||||
Write-Output $Message
|
||||
$Message="$Prefix $ADGroupName => $GroupName [$GroupCategory - $GroupScope]"
|
||||
Write-Output $Message
|
||||
|
||||
Get-GroupMemberOf $GroupName ' '
|
||||
}# End ForEach
|
||||
}# End IF
|
||||
Get-GroupMemberOf $GroupName ' '
|
||||
}# End ForEach
|
||||
}# End IF
|
||||
}#End Function
|
||||
|
||||
function Get-UserMemberships ($ADUserSID)
|
||||
function Get-UserMemberships ([string] $ADUserSID)
|
||||
{
|
||||
|
||||
$ADUser = Get-ADUser $ADUserSID -Properties *
|
||||
$ADUserMembers=$ADUser.MemberOf
|
||||
$ADUserMembers=$ADUser.MemberOf
|
||||
|
||||
$ADUserName = $ADUser.name
|
||||
Write-Host "AD-User: $ADUserName"
|
||||
Write-Output "AD-User: $ADUserName"
|
||||
#PrimaryGroup
|
||||
$ADPrimaryGroupDN = (Get-ADUser -Properties * -Filter {SID -eq $ADUserSID}).PrimaryGroup
|
||||
$ADUserName = $ADUser.name
|
||||
Write-Host "AD-User: $ADUserName ($ADUserSID)"
|
||||
Write-Output "AD-User: $ADUserName"
|
||||
|
||||
#PrimaryGroup
|
||||
$ADPrimaryGroupDN = (Get-ADUser -Properties * -Filter "SID -eq '$ADUserSID'").PrimaryGroup
|
||||
$ADPrimaryGroupName=(Get-ADGroupName $ADPrimaryGroupDN)
|
||||
$ADGroupCategory=(Get-ADGroup $ADPrimaryGroupName).GroupCategory
|
||||
$ADGroupScope=(Get-ADGroup $ADPrimaryGroupName).GroupScope
|
||||
$Message = "Primary Group: $ADPrimaryGroupName [$ADGroupCategory, $ADGroupScope]"
|
||||
Write-Output $Message
|
||||
|
||||
#Other groups
|
||||
foreach ($ADUserMember in $ADUserMembers)
|
||||
{$i++
|
||||
$ADGroupName = (Get-ADGroupName $ADUserMember)
|
||||
$ADGroupCategory=(Get-ADGroup $ADGroupName).GroupCategory
|
||||
$ADGroupScope=(Get-ADGroup $ADGroupName).GroupScope
|
||||
$Message = "($i) $ADGroupName [$ADGroupCategory, $ADGroupScope]"
|
||||
Write-Output $Message
|
||||
Get-GroupMemberOf $ADGroupName ' '
|
||||
Write-Output " "
|
||||
}
|
||||
#Other groups
|
||||
foreach ($ADUserMember in $ADUserMembers)
|
||||
{
|
||||
$i++
|
||||
$ADGroupName = (Get-ADGroupName $ADUserMember)
|
||||
$ADGroupCategory=(Get-ADGroup $ADGroupName).GroupCategory
|
||||
$ADGroupScope=(Get-ADGroup $ADGroupName).GroupScope
|
||||
$Message = "($i) $ADGroupName [$ADGroupCategory, $ADGroupScope]"
|
||||
Write-Output $Message
|
||||
Get-GroupMemberOf $ADGroupName ' '
|
||||
Write-Output " "
|
||||
}
|
||||
}
|
||||
|
||||
function Get-AllMembershipsOfUsers($ADGroupName) {
|
||||
function Get-AllMembershipsOfUsers([string] $ADGroupName)
|
||||
{
|
||||
$i=0
|
||||
|
||||
$devadmaccounts = get-adgroupmember -Identity $ADGroupName -Recursive
|
||||
foreach ($devADM in $devadmaccounts) {
|
||||
Get-UserMemberships $devADM.SID
|
||||
Write-Output "======================================================================================================"
|
||||
}
|
||||
$devadmaccounts = get-adgroupmember -Identity $ADGroupName -Recursive
|
||||
foreach ($devADM in $devadmaccounts)
|
||||
{
|
||||
Get-UserMemberships $devADM.SID
|
||||
Write-Output "======================================================================================================"
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -92,21 +92,21 @@ foreach ($devADM in $devadmaccounts) {
|
||||
#-----------------------------------------------------------------
|
||||
Clear-Host
|
||||
|
||||
#$ADUser= "Qualys"
|
||||
#Get-UserMemberships $ADUser
|
||||
[string] $ADGroupName
|
||||
[string] $date = Get-Date -Format "yyyy-MM-dd HHmm"
|
||||
|
||||
$ADGroupName = "# Developer ADM"
|
||||
Get-AllMembershipsOfUsers $ADGroupName | Out-file "2021-10-13 Developer ADM.txt"
|
||||
Get-AllMembershipsOfUsers $ADGroupName | Out-file "$date Developer ADM.txt"
|
||||
|
||||
$ADGroupName = "Domain Admins"
|
||||
Get-AllMembershipsOfUsers $ADGroupName | Out-file "2021-10-13 Domain Admins.txt"
|
||||
$ADGroupName = "Domain Admins"
|
||||
Get-AllMembershipsOfUsers $ADGroupName | Out-file "$date Domain Admins.txt"
|
||||
|
||||
$ADGroupName = "# Developer"
|
||||
Get-AllMembershipsOfUsers $ADGroupName | Out-file "2021-10-13 Developer.txt"
|
||||
$ADGroupName = "# Developer"
|
||||
Get-AllMembershipsOfUsers $ADGroupName | Out-file "$date Developer.txt"
|
||||
|
||||
$ADGroupName = "# Interne Automatisering Team-Assistent"
|
||||
Get-AllMembershipsOfUsers $ADGroupName | Out-file "2021-10-13 Interne Automatisering Team-Assistent.txt"
|
||||
$ADGroupName = "# Interne Automatisering Team-Assistent"
|
||||
Get-AllMembershipsOfUsers $ADGroupName | Out-file "$date Interne Automatisering Team-Assistent.txt"
|
||||
|
||||
$ADGroupName = "# Interne Automatisering"
|
||||
Get-AllMembershipsOfUsers $ADGroupName | Out-file "2021-10-13 Interne Automatisering.txt"
|
||||
$ADGroupName = "# Interne Automatisering"
|
||||
Get-AllMembershipsOfUsers $ADGroupName | Out-file "$date Interne Automatisering.txt"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user