Ci-dessous, les différences entre deux révisions de la page.
| Les deux révisions précédentesRévision précédente | |||
| wiki:windows:scripting:serverip [2022/11/21 13:52] – DEROUET Valentin | wiki:windows:scripting:serverip [2022/12/11 14:35] (Version actuelle) – DEROUET Valentin | ||
|---|---|---|---|
| Ligne 1: | Ligne 1: | ||
| - | ====== Gérer un AD avec du powershell ====== | ||
| + | ====== Modification d'IP et des paramètres de l' | ||
| - | {{ : | ||
| - | Cette petite fiche concerne la gestion d'un AD avec Powershell. | + | {{ : |
| - | ### Vérifier | + | Cette petite fiche concerne la gestion d'une carte réseau via CLI sur un windows server installé sans GUI. |
| - | ```powershell | + | ## Paramétrage d'une carte réseau |
| - | Import-Csv C: | + | |
| - | ``` | + | |
| - | ## Créer des OU et des sous-OU | + | Sur la version GUI de Windows, nous avons l' |
| - | ### Exemple de fichier .CSV | + | ### Lister les cartes réseaux disponibles |
| - | [Téléchargeable ici](http:// | + | < |
| - | #### Le script de création des OU : | + | ### Configurer les IP |
| - | ```powershell | + | #### Avec netsh |
| - | Import-Module activedirectory | + | |
| - | $ADOU = Import-csv | + | Connaître le nom de l'interface |
| - | foreach ($ou in $ADou) { | + | < |
| - | $name = $ou.name | + |  |
| - | Import-Module ActiveDirectory | + | - **IPAddress** : Adresse IP à attribuer à la carte |
| - | + | - **PrefixLength** | |
| - | $ADUsers = Import-Csv C:\Users\Administrateur\Desktop\Scripts\utilisateurs.csv | + | - **DefaultGateway** : Passerelle par défaut |
| - | $UPN = " | + | |
| - | foreach ($User in $ADUsers) { | + | --- |
| - | $username = $User.username | + | * Activer |
| - | $password = $User.password | + | |
| - | $firstname = $User.firstname | + | |
| - | $lastname = $User.lastname | + | |
| - | $initials = $User.initials | + | |
| - | $OU = $User.ou | + | |
| - | $email = $User.email | + | |
| - | $streetaddress = $User.streetaddress | + | |
| - | $city = $User.city | + | |
| - | $zipcode = $User.zipcode | + | |
| - | $state = $User.state | + | |
| - | $country = $User.country | + | |
| - | $telephone = $User.telephone | + | |
| - | $jobtitle = $User.jobtitle | + | |
| - | $company = $User.company | + | |
| - | $department = $User.department | + | |
| - | if (Get-ADUser | + | < |
| - | Write-Warning " | + | |
| - | } | + | |
| - | else { | + | |
| - | New-ADUser ` | + | |
| - | -SamAccountName $username ` | + | |
| - | -UserPrincipalName " | + | |
| - | -Name " | + | |
| - | -GivenName $firstname ` | + | |
| - | -Surname $lastname ` | + | |
| - | -Initials $initials ` | + | |
| - | -Enabled | + | |
| - | -DisplayName " | + | |
| - | -Path $OU ` | + | |
| - | -City $city ` | + | |
| - | -PostalCode $zipcode ` | + | |
| - | -Country $country ` | + | |
| - | -Company $company ` | + | |
| - | -State $state ` | + | |
| - | -StreetAddress $streetaddress ` | + | |
| - | -OfficePhone $telephone ` | + | |
| - | -EmailAddress $email ` | + | |
| - | -Title $jobtitle ` | + | |
| - | -Department $department ` | + | |
| - | -AccountPassword (ConvertTo-secureString $password -AsPlainText -Force) -ChangePasswordAtLogon $True | + | |
| - | Write-Host " | + | |
| - | } | + | |
| - | } | + | |
| - | Read-Host -Prompt " | + | * Supprimer l' |
| - | ``` | + | |
| - | ## Création des groupes | + | < |
| - | ### Exemple de fichier .CSV | + | * Ajout d'un serveur DNS sur l' |
| - | [Téléchargeable ici](http:// | + | < |
| - | #### Le script | + | * Vérification |
| - | ```powershell | + | < |
| - | Import-Module ActiveDirectory | + | |
| - | $groups = Import-Csv ‘C:\Users\Administrateur\Desktop\Scripts\groupes.csv‘ | + | * Désactiver le NetBIOS |
| - | foreach ($group in $groups) { | + | < |
| - | $groupProps = @{ | + | * Paramètres disponible : |
| + | * **0** – Utiliser les paramètres NetBIOS venant du DHCP | ||
| + | * **1** – Activer NetBIOS | ||
| + | * **2** – Désactiver NetBIOS | ||
| - | Name = $group.name | + | ## Utilisation de sconfig |
| - | Path = $group.path | + | |
| - | GroupScope | + | |
| - | GroupCategory = $group.category | + | |
| - | Description | + | |
| - | } | + | Indiquer le paramètre 8 pour accéder à la configuration réseau. |
| - | New-ADGroup @groupProps | + | {{ : |
| - | Write-Host " | + | |
| - | + | ||
| - | } | + | |
| - | Read-Host -Prompt " | + | |
| - | ``` | + | |
| - | ## Mettre le groupe local dans le groupe global | + | {{ : |
| - | ### Exemple de fichier | + | Configurer la carte avec l' |
| - | [Téléchargeable ici](http:// | + | ## Utilisation d' |
| - | #### Le script d' | + | * Vider le cache DNS : |
| + | * /flushdns | ||
| + | * Lacher le serveur DHCP : | ||
| + | * /release | ||
| + | * Refaire une requête au DHCP : | ||
| + | * /renew | ||
| + | * Afficher les informations réseaux | ||
| + | * /all | ||
| - | ```powershell | + | ## Utilisation de la commande route |
| - | Import-Module ActiveDirectory | + | |
| - | $List = Import-Csv " | + | * Ajouter une route vers 10.111.20.0 |
| + | < | ||
| + | route -p add 10.111.20.0/ | ||
| + | </ | ||
| - | foreach ( $Group in $List ) { | + | {{ : |
| - | foreach ( $MemberOf in $Group.memberof -split ", " ) { | + | |
| - | Add-ADGroupMember -Identity $MemberOf -Members $Group.group | + | |
| - | | + | |
| - | write-Host " | + | |
| - | | + | |
| - | ``` | + | |
| - | ## Ajouter un utilisateur dans un groupe | + | * Lister toutes les routes actives |
| - | ### Exemple de fichier .CSV | + | < |
| + | route print | ||
| + | </ | ||
| - | [Téléchargeable ici](http:// | + | {{ :wiki:windows:scripting:mremoteng_21m3x8nyu5.png?500 |}} |
| - | + | ||
| - | #### Le script d' | + | |
| - | + | ||
| - | ```powershell | + | |
| - | Import-Module ActiveDirectory | + | |
| - | + | ||
| - | $List = Import-Csv " | + | |
| - | + | ||
| - | foreach ($User in $List) | + | |
| - | + | ||
| - | $UserSam = $User.SamAccountName | + | |
| - | $Groups = $User.Group | + | |
| - | + | ||
| - | $ADUser = Get-ADUser -Filter " | + | |
| - | $ADGroups = Get-ADGroup -Filter * | Select-Object DistinguishedName, | + | |
| - | + | ||
| - | if ($ADUser -eq $null) | + | |
| - | Write-Host " | + | |
| - | Continue | + | |
| - | } | + | |
| - | + | ||
| - | if ($Groups -eq $null) { | + | |
| - | Write-Host " | + | |
| - | Continue | + | |
| - | } | + | |
| - | + | ||
| - | $ExistingGroups = Get-ADPrincipalGroupMembership $UserSam | Select-Object DistinguishedName, | + | |
| - | + | ||
| - | foreach ($Group in $Groups.Split(';' | + | |
| - | + | ||
| - | if ($ADGroups.SamAccountName -notcontains $Group) { | + | |
| - | Write-Host "$Le groupe n' | + | |
| - | Continue | + | |
| - | } | + | |
| - | + | ||
| - | if ($ExistingGroups.SamAccountName -eq $Group) { | + | |
| - | Write-Host " | + | |
| - | } | + | |
| - | else { | + | |
| - | + | ||
| - | Add-ADGroupMember -Identity $Group -Members $UserSam | + | |
| - | Write-Host " | + | |
| - | } | + | |
| - | } | + | |
| - | } | + | |
| - | ``` | + | |
| - | + | ||
| - | ## Création de la structure des dossiers | + | |
| - | + | ||
| - | *Fonctionnalité | + | |
| - | + | ||
| - | - Création de la structure des dossiers | + | |
| - | - Suppression de l' | + | |
| - | - Suppression des utilisateurs indésirables | + | |
| - | - Ajout des groupes et définitions des permissions à partir d'un .csv | + | |
| - | + | ||
| - | ### Exemple de fichier .CSV | + | |
| - | + | ||
| - | [Téléchargeable ici](http:// | + | |
| - | + | ||
| - | #### Le script d' | + | |
| - | + | ||
| - | ```powershell | + | |
| - | Set-Location "C:\" | + | |
| - | write-Host " | + | |
| - | + | ||
| - | + | ||
| - | $Folders = Import-Csv " | + | |
| - | + | ||
| - | ForEach ($Folder in $Folders) { | + | |
| - | + | ||
| - | if (Test-Path -Path $Folder.Name) { | + | |
| - | write-Host "Le dossier existe déjà !" -ForegroundColor Red | + | |
| - | | + | |
| - | New-Item $Folder.Name -type directory | + | |
| - | write-Host " | + | |
| - | | + | |
| - | + | ||
| - | echo " | + | |
| - | echo ' | + | |
| - | + | ||
| - | write-Host " | + | |
| - | + | ||
| - | $acl = Get-ACL -Path $Folder.Name | + | |
| - | $acl.SetAccessRuleProtection($True, | + | |
| - | Set-Acl -Path $Folder.Name -AclObject $acl | + | |
| - | write-Host " | + | |
| - | + | ||
| - | write-Host " | + | |
| - | + | ||
| - | $acl = Get-ACL -Path $Folder.Name | + | |
| - | icacls C: | + | |
| - | $usersid = New-Object System.Security.Principal.Ntaccount (" | + | |
| - | $acl.PurgeAccessRules($usersid) | + | |
| - | $acl | Set-Acl -Path $Folder.Name | + | |
| - | write-Host " | + | |
| - | + | ||
| - | write-Host " | + | |
| - | + | ||
| - | echo $Folder.Group | + | |
| - | echo $Folder.ACL | + | |
| - | $acl = Get-Acl -Path $Folder.Name | + | |
| - | $AccessRule = New-Object System.Security.AccessControl.FileSystemAccessRule($Folder.Group, | + | |
| - | $acl.SetAccessRule($AccessRule) | + | |
| - | $acl | Set-Acl -Path $Folder.Name | + | |
| - | write-Host " | + | |
| - | } | + | |
| - | ``` | + | |
| - | + | ||
| - | ## Mes sources | + | |
| - | + | ||
| - | 1. [https:// | + | |
| - | 2. [https:// | + | |
| - | 3. [https:// | + | |
| - | 4. [https:// | + | |
| - | 5. [https:// | + | |
| - | 6. [https:// | + | |