Ran like this:
#List of shares:
$shares = @( "\\share1\this\that" "\\share2\this\that\also" )
foreach ($share in $shares) { $filename = $share -replace '\\','_'
Get-Acl $share | select -exp Access | Export-Csv $filename".csv" -Append -NoTypeInformation }
@1 year ago
The PCI police jumped us today to make sure we kept our vendors and contractors in the scope of PCI compliance. Many were over the 90 day cutoff to be in Active Directory, and many were up and coming to cross the plateau. I fixed it like this:
Right now tumblr is upset with the ‘pre’ and ‘code’ tags, so this is looking like a giant block, but, so it is for now:
#actually could do this easier and only run through it ONE time based off the stuff in $greaterthan90days #that way it doesn't search 5 separate times through the dir. # Check the QAD snapins are installed if ( (Get-PSSnapin -Name Quest.ActiveRoles.ADManagement -ErrorAction silentlycontinue) -eq $null ) { # The QAD snapin is not active. Check it's installed if ((Get-PSSnapin -Name Quest.ActiveRoles.ADManagement -Registered -ErrorAction SilentlyContinue) -eq $null) { Write-Error "You must install Quest ActiveRoles AD Tools to use this script!" } else { Write-Host "Importing QAD Tools" Add-PSSnapin -Name Quest.ActiveRoles.ADManagement -ErrorAction Stop } } $firsttime=get-date #no EXCLUDETHISGROUP1/EXCLUDETHISGROUP2 and the account is NOT disabled/termed. $everyone=Get-QADuser -sl 0 -DontUseDefaultIncludedProperties -IncludedProperties lastlogon,lastlogontimestamp,pwdlastset,mail,employeeid,accountexpires,distinguishedname -LdapFilter '(&(|(employeeid=c*)(employeeid=v*))(accountexpires=*))'| Where-Object {$_.distinguishedname -notmatch "testaccounts" -and $_.distinguishedname -notmatch "EXCLUDETHISGROUP4" -and $_.distinguishedname -notmatch "EXCLUDETHISGROUP2" -and $_.distinguishedname -notmatch "EXCLUDETHISGROUP3" -and $_.mail -notmatch "disabled"} #prior to the filter$everyone=Get-QADuser -sl 0 -DontUseDefaultIncludedProperties -IncludedProperties employeeid,accountexpires,distinguishedname -LdapFilter '(&(|(employeeid=c*)(employeeid=v*))(accountexpires=*))'| Where-Object {$_.ParentContainer -notmatch "EXCLUDETHISGROUP2" -or $_.Parentcontainer -notmatch "EXCLUDETHISGROUP4"}|select samaccountname,accountexpires,employeeid,manager,distinguishedname #$everyone=Get-QADuser -sl 0 -DontUseDefaultIncludedProperties -IncludedProperties mail,employeeid,accountexpires,distinguishedname -LdapFilter '(&(|(employeeid=c*)(employeeid=v*))(accountexpires=*))'| Where-Object {$_.distinguishedname -notmatch "testaccounts" -and $_.distinguishedname -notmatch "EXCLUDETHISGROUP3" -and $_.mail -notmatch "disabled"} $noexpire = $everyone | where-object {$_.accountexpires -eq $null} | select samaccountname,mail,accountexpires,employeeid,manager,distinguishedname,lastlogon,lastlogontimestamp,pwdlastset $90plus = $everyone | where-object {$_.accountexpires -gt (get-date).adddays(90)} | select samaccountname,mail,accountexpires,employeeid,manager,distinguishedname,lastlogon,lastlogontimestamp,pwdlastset $80to90 = $everyone | where-object {$_.accountexpires -gt (get-date).adddays(80) -and $_.accountexpires -lt (get-date).adddays(90)}|select samaccountname,mail,accountexpires,employeeid,manager,distinguishedname,lastlogon,lastlogontimestamp,pwdlastset $70to80 = $everyone | where-object {$_.accountexpires -gt (get-date).adddays(70) -and $_.accountexpires -lt (get-date).adddays(80)}|select samaccountname,mail,accountexpires,employeeid,manager,distinguishedname,lastlogon,lastlogontimestamp,pwdlastset $60to70 = $everyone | where-object {$_.accountexpires -gt (get-date).adddays(60) -and $_.accountexpires -lt (get-date).adddays(70)}|select samaccountname,mail,accountexpires,employeeid,manager,distinguishedname,lastlogon,lastlogontimestamp,pwdlastset $50to60 = $everyone | where-object {$_.accountexpires -gt (get-date).adddays(50) -and $_.accountexpires -lt (get-date).adddays(60)}|select samaccountname,mail,accountexpires,employeeid,manager,distinguishedname,lastlogon,lastlogontimestamp,pwdlastset $40to50 = $everyone | where-object {$_.accountexpires -gt (get-date).adddays(40) -and $_.accountexpires -lt (get-date).adddays(50)}|select samaccountname,mail,accountexpires,employeeid,manager,distinguishedname,lastlogon,lastlogontimestamp,pwdlastset #since you can't pipe directly to a csv file, send the file now to a csv $noexpire | export-csv doesnotexpire.csv -notypeinformation $90plus | export-csv expiresInGreaterThan90.csv -notypeinformation $80to90 | export-csv expiresin80to90days.csv -notypeinformation $70to80 | export-csv expiresin70to80days.csv -notypeinformation $60to70 | export-csv expiresin60to70days.csv -notypeinformation $50to60 | export-csv expiresin50to60days.csv -notypeinformation $40to50 | export-csv expiresin40to50days.csv -notypeinformation #first let's wrangle the folks that NEVER expire. Everyone that is NOT EXCLUDETHISGROUP3 or an FTE needs an expiration date. The filter ALREADY set to uninclude EXCLUDETHISGROUP3 folks above, so we just need to set them. $cutoffDate = (get-date).adddays(90) write-host -ForegroundColor green "The following folks never expire! Let's set their accountexpires attribute to $cutoffdate!" $noexpire | get-qaduser -identity {$_.samaccountname} | set-qaduser -accountexpires $cutoffDate #now let's validate what we did with the $noexpire people was right $noExpireFIXED = $noexpire | get-qaduser -identity {$_.samaccountname} -sl 0 -DontUseDefaultIncludedProperties -IncludedProperties mail,employeeid,accountexpires,distinguishedname -LdapFilter '(&(|(employeeid=c*)(employeeid=v*))(accountexpires=*))'| Where-Object {$_.distinguishedname -notmatch "testaccounts" -and $_.distinguishedname -notmatch "EXCLUDETHISGROUP4" -and $_.distinguishedname -notmatch "EXCLUDETHISGROUP2" -and $_.distinguishedname -notmatch "EXCLUDETHISGROUP3" -and $_.mail -notmatch "disabled"} | select samaccountname,accountexpires $noExpireFIXED | export-csv noExpireFIXED.csv -notypeinformation #now let's change the dates on the folks over 90 days: $cutoffDate = (get-date).adddays(90) write-host -ForegroundColor green "The following folks expire in
@1 year ago
We need to find out all the users that have an “accountexpires” attribute greater than 90 days from today, so:
Get-QAduser -sl 0 -DontUseDefaultIncludedProperties -IncludedProperties employeeid,accountexpires -LdapFilter '(&(|(employeeid=c*)(employeeid=v*))(accountexpires=*))'|where-object {$_.accountexpires -gt (get-date).adddays(91)}|select samaccountname,accountexpires,employeeid
@1 year ago
I couldn’t figure out, in the 20 seconds I spent, how to create a DL with a valid email address in the ADUC GUI, so I went to my friend Powershell with this one:
$user='sentryXMLNotifs'
new-qadGroup -ParentContainer 'OU=distribution groups,OU=user accounts,DC=AWebsite,DC=org' -name 'sentryXMLNotification' -samAccountName $user -grouptype 'Distribution' -groupscope 'global'
Set-QADgroup -Identity $user -IncludedProperties proxyAddresses -ObjectAttributes @{proxyAddresses="SMTP:"+$user+"@aWebsite.com"}
@1 year ago
At the day job, we routinely clean out the stale users, but seem to neglect the stale groups - I think the fairest way to start cleaning them up is to see which groups have no members in them, and email their manager asking if they want to keep it. So I came up with something like this: *NOTE: As usual I kept my #commented out code in the script to be able to learn where I had hiccups and how I worked around it.*
#I need to get a list of managers email addresses AND the Dl/Security Group name at the end
#get qad groups with NO managers listed>>:
#Get-QADgroup -sl 0 -Empty $true -ldapFilter '(&(!(managedby=*)))' | Export-Csv noowners.csv
#get a list of all groups with no members that have both a manager and an email addy
$EmptyDLs=get-qadgroup -sl 0 -Empty $true -ldapFilter '((managedby=*)(mail=*))' | select managedby,mail
$DLmail=$EmptyDLs | select mail
$DLmanager=$EmptyDLs |select managedby
#grabs user name from managedby field:
# (get-qaduser (($peeps[3] -split(",*..="))[2])).mail
#this will pull from the pipe
#get-qaduser (($peeps[3]) -split(",*..="))[2]
#give the csv file we're building a header
$details = New-Object psobject
$details | add-member -name username -value userName -membertype noteproperty
$details | add-member -name ownerEmail -value ownerEmail -membertype noteproperty
$details | add-member -name userOwns -value userOwns -membertype noteproperty
$details | ConvertTo-Csv -NoTypeInformation | Select-Object -Skip 1 | Out-File emptygroups.csv
#start a count:
$i=0
#this loop will grab the email address of each manager based on a split
foreach ($DLManagerName in $DLManager){
$DLManagerName=(([string]$DLManagername).split(",*..=")[2])
$DLManagerInfo=get-qadobject $DLManagerName -IncludedProperties mail |select mail,samaccountname
$DLmanagerEmail=$DLManagerInfo | select mail
$DLManagerSAMAccountName=$DLManagerInfo | select samaccountname
$justName=$dlmanagersamaccountname -replace ("@{SAMAccountName=") -replace ("}")
$justEmail=$dlmanageremail -replace ("@{mail=") -replace ("}")
$theDLowned=$DLmail[$i] -replace ("@{mail=") -replace ("}")
write "$i) hello $justName, I see your email addy is $justEmail and you own $theDLowned"
$i=$i+1
#put these all in a PSObject and export to a CSV that appends with each loop
$details = New-Object psobject
$details | add-member -name username -value $justName -membertype noteproperty
$details | add-member -name ownerEmail -value $justEmail -membertype noteproperty
$details | add-member -name userOwns -value $theDLowned -membertype noteproperty
$details | ConvertTo-Csv -NoTypeInformation | Select-Object -Skip 1 | Out-File emptygroups.csv -Append
# used this just to output to a text file and could work, but want it in a more readable CSV like above
#$justname | Out-File ed.txt -Append
#$justemail | Out-File ed.txt -Append
#$theDLowned | Out-File ed.txt -Append
#"***next entry***" | Out-File ed.txt -append
}
#now I need to put that into an email format that ties the manager name to the DL name.
@1 year ago