Exclusifz Posted October 2, 2018 Report Share Posted October 2, 2018 Bonjour, J'ai un cahier des charges bien précis et je galère avec mon script. Je vous joins le cahier des charges et mon début de script pour essayer d'avancer. Je suis débutant en powershell ... Possible de le faire en Csv. Je vous remercie de votre aide Cordialement Exclusifz #script Clear-Host Import-Module ActiveDirectory Import-Module Microsoft.PowerShell.Security $users = Import-Csv -Delimiter ";" -Path 'C:\Import\test.csv' foreach ($creation in $users) { $password = "Azerty!1" $nomcomplet = $creation.NOM + " " + $creation.PRENOM $nom = $creation.NOM $prenom = $creation.PRENOM $upn = $prenom.substring(0,1) + "." + $nom $nombre=Get-Random -Minimum 1 -Maximum 9 $login = $prenom.substring(0,1).ToLower() + $nom.substring(0,4).ToLower() + $nombre $OU = $creation."CHEMIN OU".Split("\")[1] $chemin = "OU=" + $OU + "," + "DC=Formation,DC=LAb" $site = $creation."CHEMIN OU".Split("\")[2] $nomgroupe = "GG_" + $OU.substring(0,4) + "_" + $site.substring(0,4) $computer = $creation.'NOM PC' $mobile = $creation.MOBILE $nposte = $creation.NPOSTE $dossieruser = "C:\REPERTOIRE-USERS" try{ New-ADOrganizationalUnit -Name $OU -Path 'DC=Formation,DC=LAb' -ProtectedFromAccidentalDeletion $false New-ADUser -Name $nomcomplet -SamAccountName $login -UserPrincipalName $upn -DisplayName $nomcomplet -givenname $prenom -surname $nom -OfficePhone $mobile -office $nposte -Path $chemin -AccountPassWord (ConvertTo-SecureString $password -AsPlaintext -Force) -ChangePasswordAtLogon $true -Enabled $false New-ADGroup -Name $nomgroupe -Path $chemin -GroupScope Global -GroupCategory Security Add-ADGroupMember $nomgroupe -Members $login New-ADComputer -Name $computer -Path $chemin New-Item -ItemType directory -name $login -path $dossieruser #New-SmbShare -name $login -path $dossieruser -FullAccess "users"#,"administrators",$login #Set-SmbPathAcl -ShareName $login add-NTFSAccess –Path $dossieruser -Account "administrators",$login -AccessRights fullcontrol echo "Utilisateur ajouté : $nom" } catch{ echo "Utilisateur non ajouté : $nom" } } Link to comment Share on other sites More sharing options...
Schwarzer Posted November 26, 2020 Report Share Posted November 26, 2020 La présentation sur ce forum est obligatoire. De plus, nous ne sommes pas là pour faire tes devoirs. Link to comment Share on other sites More sharing options...
Recommended Posts