Compare commits
25 Commits
a42c3bf5ef
...
1.0.0
Author | SHA1 | Date | |
---|---|---|---|
07bf2c14ce | |||
f308f5e804 | |||
826c49d164 | |||
7df974133a | |||
e7d688f972 | |||
842a474a80 | |||
7285578906 | |||
67f3e3a4fa | |||
5de0e4613d | |||
1ea4f9e09c | |||
74d891415f | |||
15a7637596 | |||
ec5cb7dc4a | |||
9409e59f57 | |||
|
8ee990cca2 | ||
|
d6982c4927 | ||
|
bc97219e5e | ||
|
eadda6107c | ||
|
2dd5bd9217 | ||
|
09d5e0f281 | ||
|
9c7533edb0 | ||
66bd96e180 | |||
5614dcb11c | |||
|
7824d55859 | ||
|
5f11213de5 |
115
AD/CreateN1-N2Users/Create-ADtechs.ps1
Normal file
115
AD/CreateN1-N2Users/Create-ADtechs.ps1
Normal file
@@ -0,0 +1,115 @@
|
||||
#On vérifie que les modules soient bien installés
|
||||
if (Get-Module -ListAvailable -Name PSWriteColor) {
|
||||
$modExiste = $true
|
||||
}
|
||||
else {
|
||||
$modExiste = $false
|
||||
}
|
||||
|
||||
#Cette étape permet de désactiver les messages de confirmation d'install
|
||||
Set-PSRepository -Name 'PSGallery' -InstallationPolicy Trusted
|
||||
|
||||
switch ($modExiste) {
|
||||
$true{Import-Module ActiveDirectory;Import-Module PSWriteColor}
|
||||
$false{Install-Module PSWriteColor -Confirm:$False;Import-Module ActiveDirectory;Import-Module PSWriteColor}
|
||||
Default {Import-Module ActiveDirectory;Import-Module PSWriteColor}
|
||||
}
|
||||
|
||||
#On crée le CSV pour y stocker les ID
|
||||
$pcName = (Get-ComputerInfo).CSName
|
||||
Set-Content "C:\techLogins-$pcName.csv" -Value "Username,Password"
|
||||
|
||||
########### Fonctions ###########
|
||||
function GenPass { #Genere un mdp aléatoire selon les parametres indiqués
|
||||
|
||||
$TokenSet = @{
|
||||
U = [Char[]]'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
|
||||
L = [Char[]]'abcdefghijklmnopqrstuvwxyz'
|
||||
N = [Char[]]'0123456789'
|
||||
S = [Char[]]'!"#$%&()*+,-.:;<=>?@[]^_`{}~'
|
||||
}
|
||||
|
||||
$Upper = Get-Random -Count 5 -InputObject $TokenSet.U
|
||||
$Lower = Get-Random -Count 5 -InputObject $TokenSet.L
|
||||
$Number = Get-Random -Count 5 -InputObject $TokenSet.N
|
||||
$Special = Get-Random -Count 5 -InputObject $TokenSet.S
|
||||
|
||||
$StringSet = $Upper + $Lower + $Number + $Special
|
||||
|
||||
$RdString = (Get-Random -Count 15 -InputObject $StringSet) -join ''
|
||||
|
||||
return $RdString
|
||||
|
||||
}
|
||||
|
||||
function GetADSID { #On récupere le SID de l'AD pour pouvoir l'intégrer aux groupes qui en ont besoin
|
||||
$fullSID = (Get-ADDomain).DomainSID.Value
|
||||
$domaineSID = $fullSID.split("-",5)[-1]
|
||||
return $domaineSID
|
||||
}
|
||||
|
||||
########### Variables ###########
|
||||
$userList = "Tech-N1","Tech-N2","Tech-N3"
|
||||
|
||||
# On récupère le SID du serveur car certains SID de groupes en ont besoin
|
||||
$domaineSID = (GetADSID)
|
||||
|
||||
# On utilise le SID des groupes au lieu de leur noms familliers car Microsoft les traduit dans la langue cible du serveur
|
||||
$grpAccountOp = "S-1-5-32-548"
|
||||
$grpDomainAdm = "S-1-5-21-$domaineSID-512"
|
||||
$grpPrintOp = "S-1-5-32-550"
|
||||
#$grpServerOp = "S-1-5-32-549" Pas utilisé
|
||||
#$grpPowerUsers = "S-1-5-32-547" Déprécié
|
||||
$grpDHCPadm = "S-1-5-21-$domaineSID-1111"
|
||||
$grpDHCPuser = "S-1-5-21-$domaineSID-1110"
|
||||
$grpGPOadmin = "S-1-5-21-$domaineSID-520"
|
||||
$grpNetAdmin = "S-1-5-32-556"
|
||||
#################################
|
||||
|
||||
|
||||
########### Script ############
|
||||
|
||||
#Pour chaque user, on le crée + ajoute aux bons groupes
|
||||
ForEach($user in $userList){
|
||||
try{
|
||||
# On vérifie si l'utilisateur existe déjà, passe au suivant si oui
|
||||
$existingUser = Get-ADUser -Filter { Name -eq $user } -ErrorAction SilentlyContinue
|
||||
if ($existingUser) {
|
||||
Write-Color -Text "L'utilisateur ", $user, " existe déjà. Application des permissions." -Color White, Yellow
|
||||
}
|
||||
$userPass = (GenPass)
|
||||
$userEncPass = ConvertTo-SecureString -String $userPass -AsPlainText -Force
|
||||
$detailsUser = @{
|
||||
Name = $user
|
||||
AccountPassword = $userEncPass
|
||||
Enabled = $true
|
||||
ChangePasswordAtLogon = $false
|
||||
PasswordNeverExpires = $true #On fait en sorte qu'il n'expire pas
|
||||
}
|
||||
New-ADUser @detailsUser #On cree l'user...
|
||||
|
||||
#...puis on l'ajoute aux bons groupes
|
||||
switch ($user) {
|
||||
"Tech-N1"{$Groups = @($grpAccountOp,$grpPrintOp,$grpDHCPuser)}
|
||||
"Tech-N2"{$Groups = @($grpAccountOp,$grpPrintOp,$grpDHCPadm,$grpGPOadmin,$grpNetAdmin)}
|
||||
"Tech-N3"{$Groups = @($grpDomainAdm)}
|
||||
Default {}
|
||||
}
|
||||
|
||||
$newCsvLine = @([PSCustomObject]@{Username = $user; Password = $userPass})
|
||||
$newCsvLine | Export-CSV "C:\techLogins-$pcName.csv" -Append -NoTypeInformation -Encoding UTF8
|
||||
|
||||
ForEach ($Group in $Groups) {
|
||||
|
||||
Add-ADPrincipalGroupMembership $User -MemberOf $Group
|
||||
|
||||
}
|
||||
|
||||
Write-Color -Text "L'utilisateur ",$User," a bien été crée. Son mot de passe est ",$userPass -Color White,Green,White,Cyan
|
||||
}
|
||||
catch {
|
||||
Write-Error "Erreur pour l'utilisateur $user : $_"
|
||||
}
|
||||
}
|
||||
|
||||
Write-Color -Text "Les utilisateurs ainsi que leur mots de passes ont été exportés ici : ","C:\techLogins-$pcName.csv" -Color White,Green
|
17
Intune/Random-PWGen.ps1
Normal file
17
Intune/Random-PWGen.ps1
Normal file
@@ -0,0 +1,17 @@
|
||||
$TokenSet = @{
|
||||
U = [Char[]]'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
|
||||
L = [Char[]]'abcdefghijklmnopqrstuvwxyz'
|
||||
N = [Char[]]'0123456789'
|
||||
S = [Char[]]'!"#$%&''()*+,-./:;<=>?@[\]^_`{|}~'
|
||||
}
|
||||
|
||||
$Upper = Get-Random -Count 5 -InputObject $TokenSet.U
|
||||
$Lower = Get-Random -Count 5 -InputObject $TokenSet.L
|
||||
$Number = Get-Random -Count 5 -InputObject $TokenSet.N
|
||||
$Special = Get-Random -Count 5 -InputObject $TokenSet.S
|
||||
|
||||
$StringSet = $Upper + $Lower + $Number + $Special
|
||||
|
||||
$RdString = (Get-Random -Count 15 -InputObject $StringSet) -join ''
|
||||
|
||||
#You can use now $RdString in your script to make a random password to an AD user or other stuff...
|
7
Misc/Multi-Thread/template.ps1
Normal file
7
Misc/Multi-Thread/template.ps1
Normal file
@@ -0,0 +1,7 @@
|
||||
# This is a template for multi-threaded stuff, or at least it should be...
|
||||
|
||||
# We start a new job and store it in a variable to be able to display said job later by invoking the variable in the Receive-Job cmdlet.
|
||||
$Job = Start-Job -ScriptBlock {Write-Output 'Hello World'}
|
||||
Receive-Job $Job # Will display Hello World in the cmd
|
||||
|
||||
|
@@ -32,9 +32,6 @@ $newRunspace.SessionStateProxy.SetVariable("syncHash",$syncHash)
|
||||
# $ScriptPath = Get-ScriptDirectory
|
||||
###
|
||||
|
||||
#### Premier runspace, contien le programme dans sa totalité
|
||||
$MainWindowGUI = [PowerShell]::Create().AddScript({
|
||||
|
||||
# Chargement des assemblies externes
|
||||
Add-Type -AssemblyName System.Windows.Forms
|
||||
Add-Type -AssemblyName System.Drawing
|
||||
@@ -399,6 +396,7 @@ $FMain.Text = "SharePoint Utils GUI"
|
||||
|
||||
#Onglet Move
|
||||
##Lister les sites dans les comboBoxes
|
||||
#### On lance le ScriptBlock dans un runspace au clic du bouton BlistSites
|
||||
$BlistSites.Add_Click({
|
||||
$newRunspace =[runspacefactory]::CreateRunspace()
|
||||
$newRunspace.ApartmentState ="STA"
|
||||
@@ -484,6 +482,7 @@ $pnpConnection = Get-PnPConnection | Out-string
|
||||
$tenantURL = $URLTenant.Text
|
||||
|
||||
$BconnectSP.Add_Click({
|
||||
|
||||
Disconnect-PnPOnline
|
||||
$newRunspace =[runspacefactory]::CreateRunspace()
|
||||
$newRunspace.ApartmentState ="STA"
|
||||
@@ -533,6 +532,9 @@ function OnFormClosing_FMain{
|
||||
$FMain.Add_FormClosing({
|
||||
#Disconnect-PnPOnline
|
||||
Write-Host "Goodbye, come again soon :*"
|
||||
$RunspacePool.Close()
|
||||
$RunspacePool.Dispose()
|
||||
[gc]::Collect()
|
||||
OnFormClosing_FMain
|
||||
})
|
||||
|
||||
@@ -540,8 +542,3 @@ $FMain.Add_Shown({$FMain.Activate()})
|
||||
$ModalResult=$FMain.ShowDialog()
|
||||
# Libération de la Form
|
||||
$FMain.Dispose()
|
||||
|
||||
})
|
||||
|
||||
$MainWindowGUI.Runspace = $newRunspace
|
||||
$data = $MainWindowGUI.BeginInvoke()
|
Reference in New Issue
Block a user