Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
Scripts
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
SOWI Administratoren
Scripts
Commits
09831bfc
Commit
09831bfc
authored
4 years ago
by
Saad Chaaban
Browse files
Options
Downloads
Patches
Plain Diff
Upload webfiles_04.ps1
parent
c7859eda
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
windows/AD/webfiles_04.ps1
+77
-0
77 additions, 0 deletions
windows/AD/webfiles_04.ps1
with
77 additions
and
0 deletions
windows/AD/webfiles_04.ps1
0 → 100644
+
77
−
0
View file @
09831bfc
# webfiles 1.0
# Dieses Script liest die bei der angegebenen Domäne die User aus und fügt unter Rufnummern die Laufwerke:
# webfiles
# Das StammOU Laufwerk sowie
# "Sowitemp" hinzu.
# User bei denen schon ein eintrag unter "Rufnummern" besteht werden ignoriert.DESCRIPTION
#########################################################################################################################################
# ToDo
# - Alte werte auslesen
# - Alte Werte Speichern (fertig aber nicht eingebunden!)
# - Bereiche vergleichen
# - Alte Werte mit neuen kombinieren und zusammenführen!
# Weitere Informationen findet man unter: https://docs.microsoft.com/en-us/powershell/module/addsadministration/set-aduser?view=win10-ps
#########################################################################################################################################
# Create silently a Logfile
New-Item
$PSScriptRoot
\
$
((
Get-Date
)
.
ToString
(
'1yyyy-MM-dd'
))
_webfiles.txt
|
out-null
$Server
=
"\\husowi28c.user.hu-berlin.de"
# Speichere alle Abteilungen in einem Array, vergleiche diese später mit $check_abteilung
$Bereiche
=
@(
'AGV'
,
'AllgSoz'
,
'BGSS'
,
'Demografie'
,
'Div'
,
'DivPol'
,
'Dynamics'
,
'EmpiSoz'
,
'Ifq'
,
'InnenPol'
,
'IntPol'
,
'Komp'
,
'Makro'
,
'Mikrosoz'
,
'PolVerw'
,
'Pool'
,
'SozPol'
,
'Sprof'
,
'Stadtsoz'
,
'TheoPol'
,
'Vaps'
,
'Verw'
)
# Speichere alle Laufwerke in einen Array
$Laufwerke
=
@(
"
$Server
\sowiabteilungen\AGV"
,
"
$Server
\sowiabteilungen\AllgSoz"
,
"
$Server
\sowiabteilungen\BGSS"
,
"
$Server
\sowiabteilungen\Demografie"
,
"
$Server
\sowiabteilungen\diversity"
,
"
$Server
\sowiabteilungen\DivPol"
,
"
$Server
\sowiabteilungen\Dynamics"
,
"
$Server
\sowiabteilungen\EmpiSoz"
,
"
$Server
\sowiabteilungen\Ifq"
,
"
$Server
\sowiabteilungen\InnenPol"
,
"
$Server
\sowiabteilungen\Interpol"
,
"
$Server
\sowiabteilungen\Komp"
,
"
$Server
\sowiabteilungen\Makro"
,
"
$Server
\sowiabteilungen\Mikrosoz"
,
"
$Server
\sowiabteilungen\PolVerw"
,
"
$Server
\sowiabteilungen\Pool"
,
"
$Server
\sowiabteilungen\SozPol"
,
"
$Server
\sowiabteilungen\Sprof"
,
"
$Server
\sowiabteilungen\Stadtsoz"
,
"
$Server
\sowiabteilungen\politik"
,
"
$Server
\sowiabteilungen\Vaps"
,
"
$Server
\sowiabteilungen\Verw"
)
# Spezielle Laufwerke (WIP)
$Laufwerk_EDV
=
"
$Server
\sowiabteilungen\edv"
$Laufwerk_excellenz
=
"
$Server
\sowiabteilungen\excellenz"
$Laufwerk_Temp
=
"
$Server
\sowitemp"
# OU Liste
# 'OU=ifq', 'OU=InnenPol', 'OU=Verw', 'OU=BGSS', 'OU=Dynamics', 'OU=Stadtsoz
# Hier eintragen welche OUs nicht durchsucht werden sollen.
$OU_NOT
=
@(
'OU=Gaeste'
,
'OU=Tellab'
)
# Hier wird eingetragen welche User gesucht/ausgeschlossen werden sollen
$search
=
{
$OU_NOT
-notcontains
$_
.
DistinguishedName
.
split
(
','
)[
2
]
-and
$_
.
DistinguishedName
.
split
(
','
)[
3
]
-contains
"OU=sowiBereiche"
-and
(
$_
.
SamAccountName
-notlike
"sowi_*"
-and
$_
.
SamAccountName
-notlike
"admin.*"
)
-and
$_
.
Enabled
-like
"true"
}
# $search = { $_.DistinguishedName -like "*OU=sowiBereiche*" -and $_.Enabled -like "true" -and ($_.SamAccountName -notlike "sowi_*" -and $_.SamAccountName -notlike "admin.*") }
# $like = ''
# $notlike = ''
# Schritt 1 Finde jeden User im AD welcher in der OU Sowi Bereiche ist und einen Aktiven Account hat!
$Users
=
Get-ADUser
-Filter
*
-Property
Enabled
,
DistinguishedName
,
SamAccountName
|
Where-Object
$search
# Schritt 2 - Abteilungscheck
#####################################################################################################
ForEach
(
$Item
in
$Users
){
# 1. Lese die OU aus.
$check_ou
=
$
(
Get-ADUser
$Item
.
SamAccountName
)
.
DistinguishedName
# 2. Überprüfe ob die OU mit der Array Liste übereinstimmt. Wenn ja, speichere diesen Wert in i.
if
(
$check_ou
.
split
(
','
)[
2
]
.
substring
(
3
)
-in
$Bereiche
)
{
$i
=
[
array
]::
indexof
(
$Bereiche
,
$check_ou
.
split
(
','
)[
2
]
.
substring
(
3
))
# Hier werden die Zeilen für den Webfiles Zugriff gschrieben
$Info_new
=
"webfiles"
$Info_new
=
"
$Info_new
`r`n
"
+
$Laufwerke
[
$i
]
$Info_new
=
"
$Info_new
`r`n
$Laufwerk_Temp
"
$check_info
=
$
(
Get-ADUser
$Item
.
SamAccountName
-Properties
info
)
.
info
# 3. Überprüfe ob in dem Feld "Anmerkungen" schon in Informationen geschrieben worden sind. Wenn ja Ignoriere den User.
# Wenn nein, schreibe die Informationen für den Webfileszugriff beim User rein.
if
(
$check_info
)
{
# Alte Werte Auslesen
# $Info_original = $(Get-ADUser Get-ADUser $Item.SamAccountName -Properties info).info
"
$(
$Item
.
SamAccountName
)
, "
+
$check_ou
.
split
(
','
)[
2
]
.
substring
(
3
)
+
", NO CHANGE"
>>
$PSScriptRoot
\
$
((
Get-Date
)
.
ToString
(
'1yyyy-MM-dd'
))
_webfiles.txt
}
else
{
# Der eigentliche Füllprozess!
Set-ADUser
$
(
$Item
.
SamAccountName
)
-Replace
@{
"info"
=
$Info_new
}
"
$(
$Item
.
SamAccountName
)
, "
+
$check_ou
.
split
(
','
)[
2
]
.
substring
(
3
)
+
", SET"
>>
$PSScriptRoot
\
$
((
Get-Date
)
.
ToString
(
'1yyyy-MM-dd'
))
_webfiles.txt
# Kann wahrscheinlich entfernt werden
Clear-Variable
-Name
Info_new
}
}
else
{
"
$(
$Item
.
SamAccountName
)
, "
+
$check_ou
.
split
(
','
)[
2
]
.
substring
(
3
)
+
", ERROR"
>>
$PSScriptRoot
\
$
((
Get-Date
)
.
ToString
(
'1yyyy-MM-dd'
))
_webfiles.txt
}
# Kann wahrscheinlich entfernt werden
Clear-Variable
-Name
check_ou
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment