Hello All,
I have a csv/excell file like so:
Server Database Users
xxxxxx\yyyyyyy zzzzz $ISSAdxxxxxL
xxxxxx\yyyyyyy zzzzz $ITIllllllllllallllll
xxxxxx\yyyyyyy zzzzz svckaldfasdf
xxxxxx\yyyyyyy zzzzz svcSQLSupportSrvr
xxxxxx\yyyyyyy zzzzz us438478
I am writing a power script to help send an email to the manager of each line in the user column to confirm if the user still need an access. Below is my attempt.
##Required for AD Support
Import-Module activedirectory
# List email recipients who should receive email
$InraDba = "dba@organization.com"
#Application & file paths
$ApplicationPath = "C:\script\databaseUsers\"
$RemediationCSV = $ApplicationPath + "SQL2000_Remediation.csv"
$ManagerCSV = $ApplicationPath + "ManagersResult.csv"
$UserCSV = $ApplicationPath + "UsersResult.csv"
### Deletes previous file
Remove-Item $UserCSV
import-csv $RemediationCSV | foreach {
$ServerName = $_.Server
$DatabaseName = $_.Database
$UserCSV = $_.Users
if ($_.Users -like "us.*" or "ew.*" or "os.*" or "sp.*"){ # This is a single user account
### look in the LDAP for user's manager
This part I am not sure how to go about this. Please help.
### Create the mail message and add the $Results.csv text file as an attachment###
Send-MailMessage –From $InraDba –To $ManagerCSV –Subject "Confirm user access to Database" –Body "Below is the list of users who have access to the database $DatabaseName. As the manager, please confirm that users still need access to the datbase, else access will be revoked in 7 days." -Attachment $UserCSV –SmtpServer
}
else ### This is a service account, look in the database inventory for the owner of the database.
Not sure how to go about this neither, but that can come later.
Send-MailMessage –From $InraDba –To $OwnerCSV –Subject "Confirm user access to Database" –Body "Below is the list of service account that have access to the database $. As the owner, please confirm that thise service account still need access to the datbase, else access will be revoked in 7 days." -Attachment $ResultsCSV –SmtpServer some.servers.com
}
Please help anyway you can to make this script work.
Thanks in advance.
I have a csv/excell file like so:
Server Database Users
xxxxxx\yyyyyyy zzzzz $ISSAdxxxxxL
xxxxxx\yyyyyyy zzzzz $ITIllllllllllallllll
xxxxxx\yyyyyyy zzzzz svckaldfasdf
xxxxxx\yyyyyyy zzzzz svcSQLSupportSrvr
xxxxxx\yyyyyyy zzzzz us438478
I am writing a power script to help send an email to the manager of each line in the user column to confirm if the user still need an access. Below is my attempt.
##Required for AD Support
Import-Module activedirectory
# List email recipients who should receive email
$InraDba = "dba@organization.com"
#Application & file paths
$ApplicationPath = "C:\script\databaseUsers\"
$RemediationCSV = $ApplicationPath + "SQL2000_Remediation.csv"
$ManagerCSV = $ApplicationPath + "ManagersResult.csv"
$UserCSV = $ApplicationPath + "UsersResult.csv"
### Deletes previous file
Remove-Item $UserCSV
import-csv $RemediationCSV | foreach {
$ServerName = $_.Server
$DatabaseName = $_.Database
$UserCSV = $_.Users
if ($_.Users -like "us.*" or "ew.*" or "os.*" or "sp.*"){ # This is a single user account
### look in the LDAP for user's manager
This part I am not sure how to go about this. Please help.
### Create the mail message and add the $Results.csv text file as an attachment###
Send-MailMessage –From $InraDba –To $ManagerCSV –Subject "Confirm user access to Database" –Body "Below is the list of users who have access to the database $DatabaseName. As the manager, please confirm that users still need access to the datbase, else access will be revoked in 7 days." -Attachment $UserCSV –SmtpServer
}
else ### This is a service account, look in the database inventory for the owner of the database.
Not sure how to go about this neither, but that can come later.
Send-MailMessage –From $InraDba –To $OwnerCSV –Subject "Confirm user access to Database" –Body "Below is the list of service account that have access to the database $. As the owner, please confirm that thise service account still need access to the datbase, else access will be revoked in 7 days." -Attachment $ResultsCSV –SmtpServer some.servers.com
}
Please help anyway you can to make this script work.
Thanks in advance.