We help IT Professionals succeed at work.
Get Started

Compile multiple same line command to make a good script

Steve Bona
Steve Bona asked
on
70 Views
1 Endorsement
Last Modified: 2019-12-02
Is it a better way to compile my script that have a lot of repetetives command to make it easier to use ?

# Creation of many Domain Global group to be nest in one Domain Local Group 

$LocalGroupName = "DL-ACL-M-OCTOPUS-Shares-DAL"
$GlobalGroupName = "GG-ACL-M-OCTOPUS-Shares-DAL"
$CCSMTLServer = "$CCSMTLServer.ccsmtl.local.lab"

#regionCreate Domain Local Group in Domain CCSMTL
$Pathccsmtl= "OU=ACL,OU=Groupes,DC=CCSMTL,DC=local,DC=lab"
New-ADGroup -Name $LocalGroupName -GroupScope DomainLocal -Path $Pathccsmtl -Server $CCSMTLServer
#endregion 

#region Create Domain Global Group in Domain CRLB
$pathcrlb="OU=CCSMTL,OU=CRLB - CIUSSS,DC=lucie-bruneau,DC=local,DC=lab"
$serveurcrlb="S-ADS039.lucie-bruneau.local.lab"
New-ADGroup -Name $GlobalGroupName -GroupScope Global -Path $pathcrlb -Server $serveurcrlb 
# Add Member to Domain Local Group in CCSMTL
$accountGroupcrlb = Get-ADGroup -Identity $GlobalGroupName -Server $serveurcrlb
Add-ADGroupMember -Identity $LocalGroupName -Members $accountGroupcrlb -Server $CCSMTLServer
#endregion

#region Create Domain Global Group in Domain IRD
$pathird="OU=CCSMTL,OU=IRD_CIUSSS,DC=ird,DC=local,DC=lab"
$serveurird="irdsvr0045.ird.local.lab"
New-ADGroup -Name $GlobalGroupName -GroupScope Global -Path $pathird -Server $serveurird 
# Add Member to Domain Local Group in CCSMTL
$accountGroupird = Get-ADGroup -Identity $GlobalGroupName -Server $serveurird
Add-ADGroupMember -Identity $LocalGroupName -Members $accountGroupird -Server $CCSMTLServer
#endregion

#region Create Domain Global Group in Domain SOV
$serveursov= "TCRSVR1773.cssssov.local.lab"
$pathSOV="OU=CCSMTL,OU=ENTITES,DC=cssssov,DC=local,DC=lab"
New-ADGroup -Name $GlobalGroupName -GroupScope Global -Path $pathSOV -Server $serveursov 
# Add Member to Domain Local Group in CCSMTL
$accountGroupsov = Get-ADGroup -Identity $GlobalGroupName -Server $serveursov
Add-ADGroupMember -Identity $LocalGroupName -Members $accountGroupsov -Server $CCSMTLServer
#endregion

#region Create Domain Global Group in Domain TCR
$pathtcr="OU=DRI,OU=Groupes,OU=Utilisateurs,DC=tcrmtl,DC=local,DC=lab"
$serveurtcr="tcrsvr1447.tcrmtl.local.lab"
New-ADGroup -Name $GlobalGroupName -GroupScope Global -Path $pathtcr -Server $serveurtcr 
$accountGrouptcr = Get-ADGroup -Identity $GlobalGroupName -Server $serveurtcr
Add-ADGroupMember -Identity $LocalGroupName -Members $accountGrouptcr -Server $CCSMTLServer
#endregion

#region Create Domain Global Group in Domain CCSMTL
$Pathccsmtl= "OU=ACL,OU=Groupes,DC=CCSMTL,DC=local,DC=lab"
New-ADGroup -Name $GlobalGroupName -GroupScope Global -Path $pathccsmtl -Server $CCSMTLServer 
# Add Member to Domain Local Group in CCSMTL
$accountGroupcjmtl = Get-ADGroup -Identity $GlobalGroupName -Server $serveurcjmtl
Add-ADGroupMember -Identity $LocalGroupName -Members $accountGroupcjmtl -Server $CCSMTLServer
#endregion

#region Create Domain Global Group in Domain CJMTL
$pathcjmtl="OU=CCSMTL,dc=cjmtl,DC=local,DC=lab"
$serveurcjmtl= "ss001w1.cjmtl.local.lab"
New-ADGroup -Name $GlobalGroupName -GroupScope Global -Path $pathcjmtl -Server $serveurcjmtl 
# Add Member to Domain Local Group in CCSMTL
$accountGroupcjmtl = Get-ADGroup -Identity $GlobalGroupName -Server $serveurcjmtl
Add-ADGroupMember -Identity $LocalGroupName -Members $accountGroupcjmtl -Server $CCSMTLServer
#endregion

#region Create Domain Global Group in Domain IRGLM
$pathirglm="ou=CCSMTL,ou=IRGLM - CIUSSS,dc=irglm,DC=local,DC=lab"
$serveurirglm="Tcrsvr0398.irglm.local.lab"
New-ADGroup -Name $GlobalGroupName -GroupScope Global -Path $pathirglm -Server $serveurirglm 
# Add Member to Domain Local Group in CCSMTL
$accountGroupirglm = Get-ADGroup -Identity $GlobalGroupName -Server $serveurirglm
Add-ADGroupMember -Identity $LocalGroupName -Members $accountGroupirglm -Server $CCSMTLServer
#endregion

#region Create Domain Global Group in Domain CDC
$pathcdc="OU=CCSMTL,OU=CIUSSS-CEMTL,dc=cdc,DC=local,DC=lab"
$serveurcdc= "S-ADS045.cdc.local.lab"
New-ADGroup -Name $GlobalGroupName -GroupScope Global -Path $pathcdc -Server $serveurcdc 
# Add Member to Domain Local Group  in CCSMTL
$accountGroupcdc = Get-ADGroup -Identity $GlobalGroupName -Server $serveurcdc
Add-ADGroupMember -Identity $LocalGroupName -Members $accountGroupcdc -Server $CCSMTLServer
#endregion

#region Create Domain Global Group in Domain CRDITEDMTL
$pathcrditedmtl="OU=CCSMTL,OU=Organisation,DC=crditedmtl,DC=local,DC=lab"
$serveurcrditedmtl="Tcrsvr1237.crditedmtl.local.lab"
New-ADGroup -Name $GlobalGroupName -GroupScope Global -Path $pathcrditedmtl -Server $serveurcrditedmtl 
# Add Member to Domain Local Group in CCSMTL
$accountGroupcrditedmtl = Get-ADGroup -Identity $GlobalGroupName -Server $serveurcrditedmtl
Add-ADGroupMember -Identity $LocalGroupName -Members $accountGroupcrditedmtl -Server $CCSMTLServer
#endregion

#region Create Domain Global Group in Domain DSPMTL
$pathdspmtl="OU=CCSMTL,OU=Groupes,DC=dspmtl,DC=local,DC=lab"
$serveurdspmtl="tcrsvr1528.dspmtl.local.lab"
New-ADGroup -Name $GlobalGroupName -GroupScope Global -Path $pathdspmtl -Server $serveurdspmtl 
# Add Member to Domain Local Group in CCSMTL
$accountGroupdspmtl = Get-ADGroup -Identity $GlobalGroupName -Server $serveurdspmtl
Add-ADGroupMember -Identity $LocalGroupName -Members $accountGroupdspmtl -Server $CCSMTLServer
#endregion

#region Create Domain Global Group in Domain JEANNE-MANCE
$pathjma="OU=Groupes DFS,OU=CIUSSS CSMTL,DC=jeanne-mance,DC=local,DC=lab"
$serveurjma="TCRSVR1527.jeanne-mance.local.lab"
New-ADGroup -Name $GlobalGroupName -GroupScope Global -Path $pathjma -Server $serveurjma 
# Add Member to Domain Local Group in CCSMTL
$accountGroupjma = Get-ADGroup -Identity $GlobalGroupName -Server $serveurjma
Add-ADGroupMember -Identity $LocalGroupName -Members $accountGroupjma -Server $CCSMTLServer
#endregion

#region Create Domain Global Group in Domain IUGM
$pathiugm="OU=CCSMTL,OU=GROUPES,OU=CIUSSS,DC=iugm-06,DC=local,DC=lab"
$serveuriugm="tcrsvr1814.iugm-06.local.lab"
New-ADGroup -Name $GlobalGroupName -GroupScope Global -Path $pathiugm -Server $serveuriugm 
# Add Member to Domain Local Group in CCSMTL
$accountGroupiugm = Get-ADGroup -Identity $GlobalGroupName -Server $serveuriugm
Add-ADGroupMember -Identity $LocalGroupName -Members $accountGroupiugm -Server $CCSMTLServer
#endregion

Open in new window

Comment
Watch Question
CERTIFIED EXPERT
Most Valuable Expert 2019
Most Valuable Expert 2018
Commented:
This problem has been solved!
Unlock 1 Answer and 5 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant

An Experts Exchange subscription includes unlimited access to online courses.

Get Started
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE