#***********************************************
#Cr�ation d'un script pour les commandes du TP2
#***********************************************
#Renommer le Hostname
#**********************
Rename-Computer -NewName SRVRTP2 -Force
Restart -Computer
#**********************************
# Configuration de la carte R�seau
#**********************************
$crte=Read-host "Veuillez saisir le nom de votre carte r�seau?"
$IP=Read host "Veuillez saisir votre adresse IP?"
$Cdr=Read-host "Veuillez saisir le CIDR /?"
$Gtw=Read-host "Veuillez saisir l'adresse de votre passerelle?"
New-NetIPAddress -InterfaceAlias $crte -IPAddress $IP -PrefixLength $Cdr -
DefaultGateway $Gtw
$Dns1=Read-host "Veuillez saisir le Dns primary"
$dns2=Read host "Veuillez saisir le Dns secondary"
Set-DnsClientServerAddress -InterfaceAlias $crte -ServerAddresses ("$Dns1","$dns2")
#************************************
#INSTALLATION de l'Active Directory
#************************************
Install-WindowsFeature AD-Domain-Services �IncludeManagementTools
#**********************
#Promouvoir le Serveur
#**********************
$Main=Read-host "Veuillez saisir le nom du Domain"
$Bis=Read-host "Veuillez saisir le nom de votre NetBIOS"
Install-ADDSForest -DomainName $Main -DomainNetbiosName $dc1 -force
#$Main=Badame.local
#$dc1=BADAME
#Cr�er un mot de Pass
$MP=mot de pass Read-host "Veuillez saisir votre mot de pass"
#MP=P@ssw0rd
#*************************************
#Importer le module Active Directory
#*************************************
#****????????**A*******Revoir**********
#Liste.csv
***********************************************************
#Cr�ation de L'Unit� d'Organisation sur L'Active Directory
***********************************************************
#Rappelons les variables
#************************
#$dc1=BADAME
#$dc2=local
$D=Read-Host "Veuillez cr�er l'unit� d'organisation qui sera appel� D�partements"
$G=Read-Host "Veuillez cr�er l'unit� d'organisation qui sera appel� Groupe"
$Tist=Read-Host "Veuillez cr�er l'unit� d'organisation qui sera appel� Artistes"
$Aut=Read-Host "Veuillez cr�er l'unit� d'organisation qui sera appel� Auteur"
$Rection=Read-Host "Veuillez cr�er l'unit� D'organisation appel� Direction"
New-ADOrganizationalUnit -Name $ou -Path "DC=$dc1,DC=$dc2" -
ProtectedFromAccidentalDeletion $false
#********
#Partage
#********
**********************************************
#Cr�ation d'un groupe sur l'Active Directory
**********************************************
$Gs= Read-Host "Veuillez saisir le nom du Groupe que vous souhaitez cr�er
GroupScop"
**************************************************
#Cr�ation d'un Utilisateur sur l'Active Directory
**************************************************
$Oupt=Read-Host "Sp�cifi� l'OU o� l'utilisateur sera cr�er"
$dc1=Read-Host "Veuillez saisir le NetBIOS sans l'extension de domain"
$dc2=Read-Host "Veuillez saisir l'extension de domain sans le nom"
$Sam=Read-Host "Veuillez saisir votre login"
$Gnme=Read-Host "Veuillez saisir votre pr�nom"
$Nm=Read-Host "Veuillez saisir votre Nom"
$Upn=Read-Host "Veuillez saisir votre e-mail"
$Acp=Read-Host "Inscrivez votre mot de pass robuste en respectant les politiques de
complexit�s"
New-ADUser -Name "$Nm $Gnme" -GivenName $Gnme -Surname $Nm -SamAccountName $Sam -
UserPrincipalName $Upn -Path $Oupt,$dc1,$dc2 -AccountPassword (ConvertTo-
SecureString -AsPlainText $Acp -Force) -Enabled $true
$White-host "l'utilisateur � �t� cr�er avec succ�s dans $Oupt"
#****************************************
Annexe : Le script PowerShell � utiliser
# ***************************************
Import-Module ActiveDirectory
Import-Module NTFSSECURITY
New-Item -path -name HOMES -Type directory
New-Item -path -name PROFILES -Type directory
#*************************************
#*************************************
$ipServeurDeFichiers = 192.168.1.100
$emplacement= c:\PROFILES\ + $ipServeurDeFichiers + \homes\
#*****************************************************
$partage= "\\" + $ipServeurDeFichiers + "\profils$\"
#New-Smbshare -name PROFILES -Path C:\PROFILES -FullAccess Boss
#New-Smbshare -name PROFILES -Path C:\PROFILES -Lecture,read Art1
#New-Smbshare -name PROFILES -Path C:\PROFILES -Lecture,read Art2
#New-Smbshare -name PROFILES -Path C:\PROFILES -Lecture Aut1
#New-Smbshare -name PROFILES -Path C:\PROFILES -Lecture Aut2
# ************************************
# ************************************
New-ADOrganizationalUnit -Name Departements -Path "$dc1=BADAME,$dc2=local"
New-ADOrganizationalUnit -Name Groupes -Path "$dc1=BADAME,$dc2=local"
New-ADOrganizationalUnit -Name Artistes -Path "OU=Departements,$dc1=BADAME,
$dc2=local"
New-ADOrganizationalUnit -Name Auteurs -Path "OU=Departements,$dc1=BADAME,
$dc2=local"
New-ADOrganizationalUnit -Name Direction -Path "OU=Departements,$dc1=BADAME,
$dc2=local"
# ****************************
# ****************************
$chemin = "OU=Groupes,$dc1=BADAME,$dc2=local"
# **********************************************************
New-ADGroup -Name gg_Artistes -Path "$c:\PROFILES\ -GroupCategory Security -
GroupScope Global ` -SamAccountName gg_Artistes
New-ADGroup -Name gg_Auteurs -Path "$c:\PROFILES\ -GroupCategory Security -
GroupScope Global ` -SamAccountName gg_Auteurs
New-ADGroup -Name gg_Direction -Path "$c:\PROFILES\ -GroupCategory Security -
GroupScope Global ` -SamAccountName gg_Direction
# *****************************
New-ADGroup -Name gl_Artistes -Path $c:\PROFILES\BACKUP -GroupCategory Security -
GroupScope DomainLocal ` -SamAccountName gl_Artistes
New-ADGroup -Name gl_Auteurs -Path "$chemin" -GroupCategory Security -GroupScope
DomainLocal ` -SamAccountName gl_Auteurs
New-ADGroup -Name gl_Direction -Path "$chemin" -GroupCategory Security -GroupScope
DomainLocal ` -SamAccountName gl_Direction
# ************************************************************
Add-ADGroupMember -Identity gl_Artistes -Members gg_Artistes
Add-ADGroupMember -Identity gl_Auteurs -Members gg_Auteurs
Add-ADGroupMember -Identity gl_Direction -Members gg_Direction