Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #region Header Declaration
- <#
- .SYNOPSIS
- Script is used to automate and maintain AD user accounts
- .DESCRIPTION
- Script has 4 different sections that runs powershell commands to automate the AD accounts
- Adds New Accounts -
- Update Existing Accounts -
- Move Accounts -
- Grouping -
- .NOTES
- Author : Demosesneeds B. Punchard - dpunchard@fisdk12.net
- .LINK
- http://www.myfisd.com
- #>
- #endregion Header Declaration
- #region Begin Import AD Module
- Clear
- Import-Module ActiveDirectory
- $targetPath = "D:\ExportFiles\Active.Directory\001_FHS\Students" #Set working root directory
- Set-Location $targetPath
- $campus = "FHS"
- #endregion End Import AD Module
- #region Begin Section 1 Add New AD Accounts
- Write-Host " Begin Add New AD Accounts " -ForegroundColor 'Green'
- #region Setup Variables
- $users = Import-Csv -Path .\AD_Up_Stu_FHS.csv
- $OU = $User.ouPath
- $t = [DateTime]::Now.ToString("MM_dd_yy-HHmmss")
- $archivePath = "$targetPath\NewUser"
- $CreateGAMUser = ".\NEW_GAM_USERS.csv"
- $CreateGAMUserHTML = ".\NEW_GAM_USERS.HTML"
- $CreateADUser = ".\NEW_AD_USERS.csv"
- $GamPict = "D:\ExportFiles\GAM(Google Apps Manager)\High_Schools\001_FHS\default.jpg"
- #endregion
- IF (Test-Path -Path $CreateGAMUser)
- {Move-item $CreateGAMUser "$archivePath\NEW_GAM_USERS_$t.csv" }
- Foreach ($user in $users)
- {
- $name = $user.samaccountname
- $UserChk = Get-ADUser -Filter {sAMAccountName -eq $Name}
- If ($UserChk -eq $Null)
- {
- $user|Export-Csv -path $CreateGAMUser -NoTypeInformation -Append
- #region Setup new user Google account
- #region Create Google User Account
- & gam.exe create user $($user.mail)
- #timeout /t 5
- #endregion
- #region Update new user Google Account
- & gam.exe update user $($user.mail) firstname $($user.givenname) lastname $($user.sn)
- #endregion
- #region Change new user's Google account photo
- & gam.exe user $($user.mail) update photo $GamPict
- #endregion
- #endregion
- #region Setup new user AD account
- New-ADUser -Name $($user.samaccountname) `
- -SamAccountName $($user.samaccountname) `
- -EmployeeID $($user.employeeID) `
- -title $($user.title) `
- -department $($user.department) `
- -company $($user.company) `
- -city $($user.l) `
- -country $($user.c) `
- -state $($user.st) `
- -EmailAddress $($user.mail) `
- -Description $($user.description) `
- -ScriptPath $($user.scriptPath) `
- -HomeDirectory $($user.homeDirectory) `
- -AccountPassword (ConvertTo-SecureString $($user.Password) -AsPlainText -Force)`
- -Enabled $true
- "Just created an AD account for $($User.SamAccountname). Please verify that the user account exists in the directory."
- #endregion
- #region Setup new user AD home directory
- $NetPath = "\\cifs0.fisdk12.net\Student_Home\$($user.serialnumber)"
- $dletter = "H:"
- $userhomepath = $NetPath + "\" + $($user.SamAccountName)
- if(-not(Test-Path $userhomepath))
- {
- New-Item -Path $userhomepath -ItemType Directory
- Write-host "$userhomepath ------Created" -foregroundcolor 'Grey'
- $acl = get-acl $userhomepath
- $inheritanceFlags = ([Security.AccessControl.InheritanceFlags]::ContainerInherit -bor `
- [Security.AccessControl.InheritanceFlags]::ObjectInherit)
- $propagationFlags = [Security.AccessControl.PropagationFlags]::None
- $permissions = $($user.SamAccountName),"Modify",$inheritanceFlags,$propagationFlags,"Allow"
- $access = New-Object system.security.accesscontrol.filesystemaccessrule ($permissions)
- $acl.SetAccessRule($access)
- $acl | Set-Acl $userhomepath
- $homedir = $aduser.HomeDirectory
- if ($homedir -like $null)
- {
- $aduser |Set-aduser -ObjectAttributes @{HomeDirectory = $userhomepath}
- $aduser |Set-aduser -ObjectAttributes @{HomeDrive = $dletter}
- $usr = $_
- Write-host "Added Homedrive "$usr.HomeDrive" and Home directory "$usr.HomeDirectory"" -foregroundcolor Green
- }
- else {Write-host "$homedir already exists in AD for $_" -foregroundcolor yellow}
- }
- else
- {
- Write-Warning -Message "'$userhomepath' already exists."
- $homedir = $aduser.HomeDirectory
- if ($aduser.HomeDirectory -like $null)
- {
- $aduser | Set-aduser -homeDirectory $userhomepath
- $aduser | Set-aduser -HomeDrive $dletter
- $usr = Get-aduser $_
- Write-host "Added Homedrive "$usr.HomeDrive" and Home directory "$usr.HomeDirectory"" -foregroundcolor Green
- }
- else {Write-host "$homedir already exists in AD for $_" -foregroundcolor yellow}
- }
- #endregion
- }
- Else
- {
- Enable-ADAccount -Identity $name
- }
- #timeout /t 5
- }
- #region Send Email to campus personell that new users have been created
- #region Create HTML file which contains the list of users that have not registered with the PWM Portal
- #region Create HTML File
- $Date = get-date
- Write-Host " Begin Create HTML " -ForegroundColor 'Yellow'
- $a = “<style>”
- $a = $a + “BODY{font-family: Verdana, Arial, Helvetica, sans-serif;font-size:10;font-color: #000000}”
- $a = $a + “TABLE{border-width: 2px;border-style: solid;border-color: black;border-collapse: collapse;}”
- $a = $a + “TH{border-width: 2px;padding: 0px;border-style: solid;border-color: black;background-color: #E8E8E8}”
- $a = $a + “TD{border-width: 2px;padding: 0px;border-style: solid;border-color: black}”
- $a = $a + “</style>”
- IF (Test-Path -Path $CreateGAMUser)
- {
- $HTMLFILE = Import-CSV -Path $CreateGAMUser
- $HTMLFILE|Sort-Object whenCreated,passwordlastset -descending| select sAMAccountName,division,displayName,mail,whenCreated,passwordlastset `
- |Foreach-Object -Begin {
- $a
- "<H2>$campus New Student List</H2> <H3>New Student Accounts created at $campus on $Date</H3>"
- "<table>"
- "<tr><th> USERNAME </th><th> DIVISION </th><th> DISPLAY NAME </th><th> EMAIL ADDRESS </th></tr>"
- $row = 0
- } -Process {
- $style = "style='background-color: white;'";
- if ( $row % 2 -eq 0 )
- {
- $style = "style='background-color: lightblue;'";
- }
- "<tr><td {0}>{1}</td><td {0}>{2}</td><td {0}>{3}</td><td {0}>{4}</td></tr>" -f $style, $_.sAMAccountName,$_.division,$_.displayName,$_.mail
- $row++
- } -End {"</table>"}|Out-File .\$CreateGAMUserHTML
- }
- #| ConvertTo-Html -head $a -body $b | Set-Content $CreateGAMUserHTML}
- Write-Host " End Create HTML Output " -ForegroundColor 'Yellow'
- #endregion Create HTML Output
- #region Begin Email Processing
- IF (Test-Path -Path $CreateGAMUser)
- {
- If ($(Get-Item -Path $CreateGAMUser ).Length -gt 0)
- {
- $Date = Get-date
- $body = Get-Content .\NEW_GAM_USERS.HTML -raw
- Send-MailMessage `
- -To "Demosesneeds Punchard <dpunchard@fisdk12.net>","$campus.Campus.Techs <$campus.Campus.Techs@fisdk12.net>","FISD.District.Techs <FISD.District.Techs@fisdk12.net>" `
- -Subject "**Automation** New AD Student Accounts created at FHS" `
- -Body "The AD_$campus has added new user account data on $date $body" `
- -BodyAsHtml `
- -SmtpServer "sta0.fisdk12.net" `
- -From "do.not.reply@fisdk12.net" `
- -Attachments $CreateGAMUser `
- #-Bcc "" `
- #-Cc "" `
- #-Credential "" `
- #-DeliveryNotificationOption "" `
- #-Encoding "" `
- #-Port "" `
- #-Priority "" `
- #-UseSsl ""
- }
- }
- #endregion Send Email with attachment
- #endregion
- Write-Host " End Add New AD Accounts " -ForegroundColor 'Blue'
- #endregion
- Write-Host " End Add New AD Accounts " -ForegroundColor 'Red'
- #endregion End Section 1 Add New AD Accounts
- #region Begin Section 2 Update Existing AD Accounts
- Write-Host " Begin Section 2 Update Existing AD Accounts " -ForegroundColor 'Green'
- # Import CSV into variable $userscsv
- $users = Import-Csv -Path .\AD_Up_Stu_FHS.csv
- $OU = $User.ouPath
- Foreach ($user in $users)
- {
- #Search in specified OU and Update existing attributes
- Get-ADUser -Filter "SamAccountName -eq '$($user.samaccountname)'" -Properties * -SearchBase "DC=fisdk12,DC=net"|
- Set-ADUser -GivenName $($user.givenName) `
- -EmployeeID $($user.employeeID) `
- -Surname $($user.sn) `
- -Division $($user.Password) `
- -DisplayName $($user.DisplayName) `
- -UserPrincipalName $($user.eUserPrincipalName) `
- -title $($user.title) `
- -department $($user.department) `
- -company $($user.company) `
- -city $($user.l) `
- -state $($user.st) `
- -country $($user.c) `
- -EmailAddress $($user.mail) `
- -Description $($user.description) `
- -CannotChangePassword:$false
- <#-ScriptPath $($user.scriptPath) `#>
- }
- #region Begin Update Section 2b Custom AD Attributes
- Write-Host " Begin Update Section 2b Custom AD Attributes " -ForegroundColor 'Green'
- # Add Graduation year to users serialNumber Attribute
- $users = Import-Csv -Path .\AD_Up_Stu_FHS.csv
- Foreach ($user in $users)
- {
- SET-ADUSER -Identity $($user.SamAccountName) –replace @{serialnumber= $($user.serialNumber)}
- }
- # Add TSDS to AD profile using the roomNumber Attribute
- Foreach ($user in $users)
- {
- $roomNumber = $($user.roomNumber)
- $UserChk = Get-ADUser -Filter {roomNumber -eq $roomNumber}
- If ($UserChk -eq $Null)
- {Set-ADUser -Identity $($user.SamAccountName) -replace @{roomNumber= $($user.roomNumber)}
- }
- #Else {"$($user.samaccountname) user has a TSDS in AD"}
- }
- Write-Host " End Update Section 2b Custom AD Attributes " -ForegroundColor 'Green'
- #endregion End Update Section 2b Custom AD Attributes
- #region Begin Enabling all active accounts
- <# Begin Enabling all active accounts
- # Enable all accounts being updated from the File.
- Write-Host " Begin Enabling all active accounts " -ForegroundColor 'Blue'
- # Import CSV into variable $userscsv
- $users = Import-Csv -Path .\AD_Up_Stu_FHS.csv
- $OU = $User.ouPath
- Foreach ($user in $users)
- {
- # Enable all accounts in the current file
- Enable-ADAccount -Identity $($user.samaccountname)
- }
- Write-Host " End Enabling all active accounts " -ForegroundColor 'Blue'#>
- #endregion
- Write-Host " End Section 2 Update Existing AD Accounts " -ForegroundColor 'Red'
- #endregion End Section 2 Update Existing AD Accounts
- #region Begin Section 3 Move AD Accounts
- Write-Host " Begin Section 3 Move AD Accounts " -ForegroundColor 'Green'
- # Import CSV into variable $userscsv
- $users = Import-Csv -Path .\AD_Up_Stu_FHS.csv
- $OU = $User.ouPath
- Foreach ($user in $users)
- {
- # Search in specified OU and Update existing attributes
- Get-ADUser -Filter "SamAccountName -eq '$($user.samaccountname)'" -Properties * -SearchBase "DC=fisdk12,DC=net" |
- move-adobject -targetpath $($user.ouPATH)
- }
- Write-Host " End Section 3 Move AD Accounts " -ForegroundColor 'Red'
- #endregion End Section 3 Move AD Accounts
- #region Begin Section 4 Shadow Group AD Accounts
- # Import CSV into variable $userscsv
- Write-Host " Begin Section 4 Shadow Group AD Accounts " -ForegroundColor 'Blue'
- $users = Import-Csv -Path .\AD_Up_Stu_FHS.csv
- $OU = $User.ouPath
- Foreach($user in $campus_staff_data)
- {
- $grpname = $($user.group1)
- $name = $user.samaccountname
- $UsergrpChk = Get-adgroupmember -Identity $grpname
- $UserChk = $UsergrpChk|where-object {$_.samaccountname -eq $Name}
- If ($UserChk -eq $Null)
- {add-adgroupmember -identity $grpname -member $($user.samaccountname)}
- Else
- {"$($user.samaccountname) User found in $grpname"}
- }
- # This section will add and remove users from the corresponding shadow group
- # Define shadow group variables
- $OU="OU=Grade09,OU=Users,OU=001_Students,OU=001_FHS,OU=_High_Schools,OU=FISDK12,DC=fisdk12,DC=net"
- $ShadowGroup="CN=FHS.Students.Grade09,OU=Security_Groups,OU=Automated_Groups,OU=Do_Not_Remove,OU=FISDK12,DC=fisdk12,DC=net"
- Get-ADGroupMember –Identity $ShadowGroup | Where-Object {$_.distinguishedName –NotMatch $OU} | ForEach-Object {Remove-ADPrincipalGroupMembership –Identity $_ –MemberOf $ShadowGroup –Confirm:$false}
- Get-ADUser –SearchBase $OU –SearchScope Subtree –LDAPFilter "(!memberOf=$ShadowGroup)" | ForEach-Object {Add-ADPrincipalGroupMembership –Identity $_ –MemberOf $ShadowGroup}
- # This section will add and remove users from the corresponding shadow group
- # Define shadow group variables
- $OU="OU=Grade10,OU=Users,OU=001_Students,OU=001_FHS,OU=_High_Schools,OU=FISDK12,DC=fisdk12,DC=net"
- $ShadowGroup="CN=FHS.Students.Grade10,OU=Security_Groups,OU=Automated_Groups,OU=Do_Not_Remove,OU=FISDK12,DC=fisdk12,DC=net"
- Get-ADGroupMember –Identity $ShadowGroup | Where-Object {$_.distinguishedName –NotMatch $OU} | ForEach-Object {Remove-ADPrincipalGroupMembership –Identity $_ –MemberOf $ShadowGroup –Confirm:$false}
- Get-ADUser –SearchBase $OU –SearchScope Subtree –LDAPFilter "(!memberOf=$ShadowGroup)" | ForEach-Object {Add-ADPrincipalGroupMembership –Identity $_ –MemberOf $ShadowGroup}
- # This section will add and remove users from the corresponding shadow group
- # Define shadow group variables
- $OU="OU=Grade11,OU=Users,OU=001_Students,OU=001_FHS,OU=_High_Schools,OU=FISDK12,DC=fisdk12,DC=net"
- $ShadowGroup="CN=FHS.Students.Grade11,OU=Security_Groups,OU=Automated_Groups,OU=Do_Not_Remove,OU=FISDK12,DC=fisdk12,DC=net"
- Get-ADGroupMember –Identity $ShadowGroup | Where-Object {$_.distinguishedName –NotMatch $OU} | ForEach-Object {Remove-ADPrincipalGroupMembership –Identity $_ –MemberOf $ShadowGroup –Confirm:$false}
- Get-ADUser –SearchBase $OU –SearchScope Subtree –LDAPFilter "(!memberOf=$ShadowGroup)" | ForEach-Object {Add-ADPrincipalGroupMembership –Identity $_ –MemberOf $ShadowGroup}
- # This section will add and remove users from the corresponding shadow group
- # Define shadow group variables
- $OU="OU=Grade12,OU=Users,OU=001_Students,OU=001_FHS,OU=_High_Schools,OU=FISDK12,DC=fisdk12,DC=net"
- $ShadowGroup="CN=FHS.Students.Grade12,OU=Security_Groups,OU=Automated_Groups,OU=Do_Not_Remove,OU=FISDK12,DC=fisdk12,DC=net"
- Get-ADGroupMember –Identity $ShadowGroup | Where-Object {$_.distinguishedName –NotMatch $OU} | ForEach-Object {Remove-ADPrincipalGroupMembership –Identity $_ –MemberOf $ShadowGroup –Confirm:$false}
- Get-ADUser –SearchBase $OU –SearchScope Subtree –LDAPFilter "(!memberOf=$ShadowGroup)" | ForEach-Object {Add-ADPrincipalGroupMembership –Identity $_ –MemberOf $ShadowGroup}
- # This section will add and remove users from the corresponding shadow group
- # Define shadow group variables
- $OU="OU=GradeGD,OU=Users,OU=001_Students,OU=001_FHS,OU=_High_Schools,OU=FISDK12,DC=fisdk12,DC=net"
- $ShadowGroup="CN=FHS.Students.GradeGD,OU=Security_Groups,OU=Automated_Groups,OU=Do_Not_Remove,OU=FISDK12,DC=fisdk12,DC=net"
- Get-ADGroupMember –Identity $ShadowGroup | Where-Object {$_.distinguishedName –NotMatch $OU} | ForEach-Object {Remove-ADPrincipalGroupMembership –Identity $_ –MemberOf $ShadowGroup –Confirm:$false}
- Get-ADUser –SearchBase $OU –SearchScope Subtree –LDAPFilter "(!memberOf=$ShadowGroup)" | ForEach-Object {Add-ADPrincipalGroupMembership –Identity $_ –MemberOf $ShadowGroup}
- # This section will add and remove users from the corresponding shadow group
- # Define shadow group variables
- $SearchOU="OU=Users,OU=001_Students,OU=001_FHS,OU=_High_Schools,OU=FISDK12,DC=fisdk12,DC=net"
- $OU=Get-ADUser -Filter {(department -ge "09") -and (department -ge "12") } -Properties * -SearchBase $SearchOU -SearchScope Subtree
- $ShadowGroup="CN=FHS.All.Students,OU=Security_Groups,OU=Automated_Groups,OU=Do_Not_Remove,OU=FISDK12,DC=fisdk12,DC=net"
- Get-ADGroupMember –Identity $ShadowGroup|Where-Object {(($_.department -ge "09") -and ($_.department -ge "12")) -and ($_.company -ne "001")} | ForEach-Object {Remove-ADPrincipalGroupMembership –Identity $_ –MemberOf $ShadowGroup –Confirm:$false}
- Get-ADUser -LDAPFilter "(!memberOf=$ShadowGroup)" -SearchBase $SearchOU -SearchScope Subtree | ForEach-Object {Add-ADPrincipalGroupMembership –Identity $_ –MemberOf $ShadowGroup}
- Write-Host " End Section 4 Shadow Group AD Accounts " -ForegroundColor 'Blue'
- #endregion End Section 4 Shadow Group AD Accounts
- #region Begin Section 5 Isolate New AD Accounts
- Write-Host " Begin Isolate New AD Accounts " -ForegroundColor 'Blue'
- #use -.0429 = 1 hour
- #use -.0825 = 2 hours
- #use -1 = 24 hours
- #use -.5 = 12 hours
- $week = ((Get-Date).AddDays(-.0825))
- Get-ADUser -Filter * -Properties * -SearchBase "OU=001_Students,OU=001_FHS,OU=_High_Schools,OU=FISDK12,DC=fisdk12,DC=net" |
- <#Get-ADUser -Filter * -Properties * | `#>
- where { $_.whenCreated -ge $week } | select sAMAccountName,division,displayName,mail,whenCreated,passwordlastset `
- | Export-Csv -Path ".\AD_Pass_FHS_STU.csv" -NoTypeInformation
- Get-ADUser -Filter * -Properties * -SearchBase "OU=001_Students,OU=001_FHS,OU=_High_Schools,OU=FISDK12,DC=fisdk12,DC=net" |
- where { $_.whenCreated -ge $week } | select sAMAccountName,division,displayName,mail,whenCreated,passwordlastset `
- | Export-Csv -Path ".\AD_Pass_Append_FHS_STU.csv" -append -NoTypeInformation
- Write-Host " End Isolate New AD Accounts " -ForegroundColor 'Blue'
- Write-Host " Begin Create HTML " -ForegroundColor 'Blue'
- # Begin Create HTML Output
- Write-Host " Begin Create HTML Output " -ForegroundColor 'Blue'
- $a = “<style>”
- $a = $a + “BODY{font-family: Verdana, Arial, Helvetica, sans-serif;font-size:10;font-color: #000000}”
- $a = $a + “TABLE{border-width: 2px;border-style: solid;border-color: black;border-collapse: collapse;}”
- $a = $a + “TH{border-width: 2px;padding: 0px;border-style: solid;border-color: black;background-color: #E8E8E8}”
- $a = $a + “TD{border-width: 2px;padding: 0px;border-style: solid;border-color: black}”
- $a = $a + “</style>”
- Get-ADUser -Filter * -Properties * -SearchBase "OU=001_Students,OU=001_FHS,OU=_High_Schools,OU=FISDK12,DC=fisdk12,DC=net" |
- <#Get-ADUser -Filter * -Properties * | `#>
- Sort-Object whenCreated,passwordlastset -descending |
- where { $_.whenCreated -ge $week } | select sAMAccountName,division,displayName,mail,whenCreated,passwordlastset `
- | ConvertTo-Html -head $a -body $b | Set-Content ".\AD_Pass_FHS_STU.html"
- Write-Host " End Create HTML Output " -ForegroundColor 'Blue'
- #End Create HTML Output
- #endregion End Isolate New AD Accounts Section 5
- #region Begin Section 6 Change New Account Passwords
- Write-Host " Begin Change New Account Passwords " -ForegroundColor 'Blue'
- If ($(Get-Item -Path ".\AD_Pass_FHS_STU.csv" ).Length -gt 0)
- {
- # Import CSV into variable $userscsv
- $users = Import-Csv -Path ".\AD_Pass_FHS_STU.csv"
- # Loop through CSV and update users if the exist in CVS file
- Foreach ($user in $users)
- {
- Set-ADAccountPassword $($user.samaccountname) -Reset -NewPassword (ConvertTo-SecureString -AsPlainText $($user.division)-Force)
- }
- {
- Write-Host " No passwords to change " -ForegroundColor 'Blue'
- }
- }
- Write-Host " End Change New Account Passwords " -ForegroundColor 'Blue'
- #endregion End Section 6 Change New Account Passwords
- #region Begin Section 7 Disabling Inactive Accounts
- # Disabled all accounts that are inactive via Skyward export
- # Import CSV into variable $userscsv
- Write-Host " Step 1 of 3 Disabling all accounts that are inactive via Skyward export " -BackgroundColor Yellow -ForegroundColor Blue
- $users = Import-Csv -Path .\AD_InActive_FHS_Stu.csv
- Foreach ($user in $users)
- {
- $name = $user.samAccountname
- $UserChk = Get-ADUser -Filter {samAccountname -eq $Name}
- If ($UserChk -eq $Null)
- {"$($user.samAccountname) was not found in AD"}
- Else {Disable-ADAccount -Identity $($user.sAMAccountName)}
- }
- Write-Host " End Step 1 of 3 Disabling all accounts that are inactive via Skyward export " -BackgroundColor Yellow -ForegroundColor Blue
- # Set users description to Disabled via AD Automation and Clear EmailAddress to prevent sync with Google
- # Import CSV into variable $userscsv
- Write-Host " Step 2 of 3 Set users description to Disabled via AD Automation " -ForegroundColor 'Green'
- $users = Import-Csv -Path .\AD_InActive_FHS_Stu.csv
- Foreach ($user in $users)
- {
- Get-ADUser -Filter "SamAccountName -eq '$($user.samaccountname)'" -Properties * -SearchBase "DC=fisdk12,DC=net" |
- Set-ADUser -Description $($user.description) #-Clear mail
- }
- # Move disabled user accounts to Students inactive OU
- # Import CSV into variable $userscsv
- Write-Host " Step 3 of 3 Move disabled user accounts to Students inactive OU " -ForegroundColor 'Green'
- $users = Import-Csv -Path .\AD_InActive_FHS_Stu.csv
- $OU = $User.ouPath
- Foreach ($user in $users)
- {
- Get-ADUser -Filter "SamAccountName -eq '$($user.samaccountname)'" -Properties * -SearchBase "DC=fisdk12,DC=net" |
- move-adobject -targetpath $($user.ouPath)
- }
- #endregion End Section 7 Disabling Inactive Accounts
- #region Begin Section 8 Calling of External Scripts
- Write-Host " Begin Calling of External Scripts " -Foreground 'Yellow'
- & "D:\ExportFiles\Active.Directory\001_FHS\Students\AD_GD_Stu_FHS.ps1"
- Write-Host " End Calling of External Scripts " -Foreground 'Yellow'
- #endregion End Section 8 Calling of External Scripts
- #region Begin Section 9 Email Processing
- If ($(Get-Item -Path ".\AD_Pass_FHS_STU.csv" ).Length -gt 0)
- {
- # Begin Send Email with attachmen
- $Date = Get-date
- Send-MailMessage `
- -To "Demosesneeds Punchard <dpunchard@fisdk12.net>","FHS.Campus.Techs <FHS.Campus.Techs@fisdk12.net>","FISD.District.Techs <FISD.District.Techs@fisdk12.net>" `
- -Subject "**Automation** AD Accounts FHS Students" `
- -Body "The AD_FHS Scheduled task has completed on $date. " `
- -SmtpServer "sta0.fisdk12.net" `
- -From "do.not.reply@fisdk12.net" `
- -Attachments ".\AD_Pass_FHS_STU.html",".\AD_Pass_FHS_STU.csv"
- #-Bcc "" `
- #-BodyAsHtml `
- #-Cc "" `
- #-Credential "" `
- #-DeliveryNotificationOption "" `
- #-Encoding "" `
- #-Port "" `
- #-Priority "" `
- #-UseSsl ""
- #End Send Email with attachment
- }
- else
- {
- Write-Host " " -ForegroundColor 'Blue'
- }
- Write-Host " End Email Processing " -ForegroundColor 'Blue'
- #endregion End Section 9 Email Processing
- #region Begin Section 10 Cleanup of working files
- Write-Host " Begin CleanUp " -Foreground 'Blue'
- Remove-Item .\AD_Pass_FHS_STU.csv
- Remove-Item .\AD_Pass_FHS_STU.html
- Write-Host " End CleanUp " -Foreground 'Blue'
- #endregion End Section 10 Cleanup of working files
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement