|
|
@@ -10,7 +10,7 @@
|
|
|
# This Script takes emails from pipe and group and access level from cli to invite them
|
|
|
$GITLAB_INVITE = "$PSScriptRoot\gitlab-invite.ps1"
|
|
|
|
|
|
-Set-Log ([IO.Path]::GetFullPath("$PSScriptRoot\..\runtime\groupusers-${env:computername}-.log")) 1mb 2
|
|
|
+Set-Log ([IO.Path]::GetFullPath("$PSScriptRoot\..\runtime\groupusers-${env:computername}.log")) 1mb 2
|
|
|
|
|
|
|
|
|
foreach ($module in @("ActiveDirectory")){
|
|
|
@@ -25,27 +25,49 @@ foreach ($module in @("ActiveDirectory")){
|
|
|
$departments = @(
|
|
|
@{
|
|
|
name="ANNAX CH Testing and Integration"
|
|
|
- id="3160"
|
|
|
- glgroup="annax/teams/integrationtest"
|
|
|
- access_level="20"
|
|
|
+ id=3160
|
|
|
+ glgroup=@{
|
|
|
+ name="annax/teams/integrationtest";
|
|
|
+ access_level="20";
|
|
|
+ }
|
|
|
},
|
|
|
@{
|
|
|
name="ANNAX DE Device Software Engineering"
|
|
|
- id="3130"
|
|
|
- glgroup="annax/teams/developers"
|
|
|
- access_level="30"
|
|
|
+ id=3130
|
|
|
+ glgroup=@{
|
|
|
+ name="annax/teams/developers";
|
|
|
+ access_level="30";
|
|
|
+ }
|
|
|
}
|
|
|
)
|
|
|
|
|
|
-&{
|
|
|
+function Main(){
|
|
|
+
|
|
|
$departments | ForEach-Object {
|
|
|
- $filter = "*("+$_.id+")"
|
|
|
- $_.name
|
|
|
- $_.glgroup
|
|
|
- Get-ADUser -Filter {Department -like $filter} -Properties emailaddress,Department |
|
|
|
- Select-Object -ExpandProperty emailaddress | &$GITLAB_INVITE -group $_.glgroup -access_level $_.access_level
|
|
|
+ $filter = "*($([string]$_.id))"
|
|
|
+ $department = $_;
|
|
|
+
|
|
|
+ if ($null -ne $department.glgroup){
|
|
|
+ "Inviting '$($department.name)' with id $($department.id) to '$($department.glgroup.name)'"
|
|
|
+ Get-ADUser -Filter {Department -like $filter} -Properties emailaddress,Department |
|
|
|
+ ForEach-Object {
|
|
|
+ @{glgroup=$department.glgroup;aduser=$_} | GitlabInvite;
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
-} *| Foreach-Object {
|
|
|
+}
|
|
|
+
|
|
|
+function GitlabInvite(){
|
|
|
+ param(
|
|
|
+ [Parameter(Mandatory=$true,ValueFromPipeline = $true)]
|
|
|
+ $user
|
|
|
+ )
|
|
|
+ $user.aduser |
|
|
|
+ Select-Object -ExpandProperty emailaddress |
|
|
|
+ &$GITLAB_INVITE -group $user.glgroup.name -access_level $user.glgroup.access_level
|
|
|
+}
|
|
|
+
|
|
|
+Main *| Foreach-Object {
|
|
|
Write-Log ([string]$_)
|
|
|
}
|
|
|
|