Quantcast
Channel: The Official Scripting Guys Forum! forum
Viewing all articles
Browse latest Browse all 15028

Powershell - Need help combining multiple commands (?) into one script

$
0
0

Scenario:

When a user is terminated from our company, I run these scripts separately:

1. I use the script below in Windows Powershell ISE to launch an entry box so I can enter in the username@domain and get a list of distribution groups the termed employee currently manage export to a CSV file on my desktop:

Add-PSSnapin quest.activeroles.admanagement
$USerID = Read-host "Enter in Username@domain. Example: JohnDoe@cba.corp"
connect-QADService -service blah.dc1.cba.corp -UseGlobalCatalog
get-qadgroup -ManagedBy $UserID -Verbose | select Name,Type,DN | export-csv -
NoTypeInformation "$home\desktop\$UserID.csv" -Verbose -Force

2. I launch Powershell as an Administrator and run the following to activate Exchange Management in Powershell and to give me access to the entire forest of accounts:

Add-PSSnapin -name "Microsoft.Exchange.Management.PowerShell.E2010"

Set-AdServerSettings -ViewEntireForest $true

3. Next, I run this script to remove the former owner's write permissions from the list of distribution lists they managed in the above CSV file:

import-csv -Path "<PATH>" | Foreach-Object {Remove-ADPermission -Identity $_.Name -
User '<domain\username>' -AccessRights WriteProperty -Properties “Member” -
Confirm:$false}

4. I run this script to show the new owner of the DLs, allow DL management via Webmail and add info in the Notes section on the DLs:

import-csv -Path "<PATH>" | Foreach-Object {set-Group -Identity $_.Name -ManagedBy
"<domain\username>" –Notes “<Enter Here>”}

5. I run this script to allow management via Outlook and to automatically check the box in Active Directory "Manager can update membership list" under the Managed By tab within the Group's Properties:

import-csv -Path "<PATH>" | Foreach-Object {Add-ADPermission -Identity $_.Name -User
‘<domain\username’ -AccessRights WriteProperty -Properties “Member”}

Is there a way I can combine this into one Powershell script or two, at the most instead of having to copy and paste 6 different times and use two programs (Powershell and Powershell ISE)? 


Viewing all articles
Browse latest Browse all 15028

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>