Question
Projet Création User AD
- rootux
- Auteur du sujet
- Hors Ligne
- Nouveau membre
-
- Messages : 6
- Remerciements reçus 0
Voilà je suis un petit nouveau dans le PowerShell mais j'ai commencé un GROS projet qui consiste a créer une interface universelle pour créer un utilisateur dans un Active Directory.......Mais je rencontre quelques problème....
Voilà le code :
[code:1]#Generated Form Function
function GenerateForm {
########################################################################
# Code Generated By: SAPIEN Technologies PrimalForms (Community Edition) v1.0.8.0
# Generated On: 23/06/2010 18:25
# Generated By: Administrateur
########################################################################
#region Import the Assemblies
[reflection.assembly]::loadwithpartialname(\"System.Windows.Forms\"«») | Out-Null
[reflection.assembly]::loadwithpartialname(\"System.Drawing\"«») | Out-Null
#endregion
#region Generated Form Objects
$form_Fond = New-Object System.Windows.Forms.Form
$DescriptionPanelGroupes = New-Object System.Windows.Forms.Label
$panel_GroupesOrg1 = New-Object System.Windows.Forms.Panel
$checkedListBox_GroupesOrg1 = New-Object System.Windows.Forms.CheckedListBox
$panel_GroupesOrg2 = New-Object System.Windows.Forms.Panel
$checkedListBox_GroupesOrg2 = New-Object System.Windows.Forms.CheckedListBox
$panel_GroupesOrg3 = New-Object System.Windows.Forms.Panel
$checkedListBox_GroupesOrg3 = New-Object System.Windows.Forms.CheckedListBox
$panel_GroupesOrg4 = New-Object System.Windows.Forms.Panel
$checkedListBox_GroupesOrg4 = New-Object System.Windows.Forms.CheckedListBox
$panel_GroupesOrg5 = New-Object System.Windows.Forms.Panel
$checkedListBox_GroupesOrg5 = New-Object System.Windows.Forms.CheckedListBox
$panel_InfoUser = New-Object System.Windows.Forms.Panel
$comboBox_TypePoste = New-Object System.Windows.Forms.ComboBox
$lbl_TypePoste = New-Object System.Windows.Forms.Label
$comboBox_Organisme = New-Object System.Windows.Forms.ComboBox
$lbl_Organisme = New-Object System.Windows.Forms.Label
$Email = New-Object System.Windows.Forms.TextBox
$lbl_Email = New-Object System.Windows.Forms.Label
$Phone = New-Object System.Windows.Forms.TextBox
$lbl_Phone = New-Object System.Windows.Forms.Label
$Nom = New-Object System.Windows.Forms.TextBox
$lbl_Nom = New-Object System.Windows.Forms.Label
$Prenom = New-Object System.Windows.Forms.TextBox
$lbl_Prenom = New-Object System.Windows.Forms.Label
$panel_InfoLogin = New-Object System.Windows.Forms.Panel
$Mdp = New-Object System.Windows.Forms.TextBox
$lbl_Mdp = New-Object System.Windows.Forms.Label
$Login = New-Object System.Windows.Forms.TextBox
$lbl_Login = New-Object System.Windows.Forms.Label
$panel_InfoDomaine = New-Object System.Windows.Forms.Panel
$CtlDomaine = New-Object System.Windows.Forms.TextBox
$lbl_CtlDomaine = New-Object System.Windows.Forms.Label
$NomDomaine = New-Object System.Windows.Forms.TextBox
$Lbl_Domaine = New-Object System.Windows.Forms.Label
$buttonCreer = New-Object System.Windows.Forms.Button
$InitialFormWindowState = New-Object System.Windows.Forms.FormWindowState
#endregion Generated Form Objects
#
#Generated Event Script Blocks
#
#Provide Custom Code for events specified in PrimalForms.
$handler_form_Fond_Load=
{
#TODO: Place custom script here
}
$handler_DescriptionPanelGroupes_Click=
{
#TODO: Place custom script here
}
$handler_label1_Click=
{
#TODO: Place custom script here
}
$handler_comboBox1_SelectedIndexChanged=
{
#TODO: Place custom script here
}
$handler_button1_Click=
{
#TODO: Place custom script here
###################################
## Récupération des Champs Texte ##
###################################
[string]$CP = $Login.get_text()
[string]$M2p = $Mdp.get_text()
[string]$Prnom = $Prenom.get_text()
[string]$Nm = $Nom.get_text()
[string]$tel = $Phone.get_text()
[string]$Mail = $Email.get_text()
[string]$Domaine = $NomDomaine.get_text()
[string]$CtrlDomaine = $CtlDomaine.get_text()
[string]$userCN=\"CN=$($Nom) $($Prenom)\"
################################
## Code pour Active Directory ##
################################
$domaineLDAP = \"$Domaine\"
$domaineLDAP = $domaineLDAP.Replace('.',',DC=')
$domaineLDAP = \"DC=$domaineLDAP\"
$Organisme = $ComboBox_Organisme.SelectedItem
$TypePoste = $ComboBox_TypePoste.SelectedItem
$OU = \"OU=$Typeposte,OU=Utilisateurs,OU=$Organisme\"
$objOU = [ADSI]\"LDAP://$OU,$domaineLDAP\"
#########################################################
## On vérifie que l'utilisateur n'existe pas dans l'AD ##
#########################################################
$dom = [System.DirectoryServices.ActiveDirectory.Domain]::GetCurrentDomain()
$domainnb = \"DOMAIN\"
$root = $dom.GetDirectoryEntry()
$search = [System.DirectoryServices.DirectorySearcher]$root
$search.Filter = \"(samAccountName=$CP)\"
$result = $search.FindOne()
if ($result -ne $null) {
$user = $result.GetDirectoryEntry()
Set-Popup -titre 'Avertissement' -message \"L'utilisateur $CP Existe Déjà dans l'AD\"
Break
}
#########################################
## Création de l'utilisateur dans l'AD ##
#########################################
$objUser= $objOU.Create(\"user\",$userCN)
$objUser.put(\"sAMAccountName\", $CP)
$objUser.put(\"userPrincipalName\", $CP)
$objUser.put('givenName', $Prnom)
$objUser.put('sn', $Nm)
$objUser.put('Description', \"$Organisme - $Nm $Prnom\"«»)
Start-Sleep -s 10
$objUser.userAccountControl[0] = $objUser.userAccountControl[0] -band (-bnot 2)
$objUser.SetInfo()
$objUser.SetPassword($M2p)
Set-Popup -titre 'Avertissement' -message \"Compte Créé !\"
}
$OnLoadForm_StateCorrection=
{#Correct the initial state of the form to prevent the .Net maximized form issue
$form_Fond.WindowState = $InitialFormWindowState
}
#
#region Generated Form Code
$form_Fond.BackColor = [System.Drawing.Color]::FromArgb(255,191,205,219)
$form_Fond.Text = \"Création Compte AD V0 b7\"
$form_Fond.Name = \"form_Fond\"
$form_Fond.DataBindings.DefaultDataSourceUpdateMode = 0
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Width = 1031
$System_Drawing_Size.Height = 647
$form_Fond.ClientSize = $System_Drawing_Size
$form_Fond.add_Load($handler_form_Fond_Load)
$DescriptionPanelGroupes.TabIndex = 12
$DescriptionPanelGroupes.TextAlign = 32
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Width = 404
$System_Drawing_Size.Height = 23
$DescriptionPanelGroupes.Size = $System_Drawing_Size
$DescriptionPanelGroupes.Text = \"Cochez les groupes de l''utilisateur :\"
$DescriptionPanelGroupes.Font = New-Object System.Drawing.Font(\"Microsoft Sans Serif\",14.25,1,3,0)
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 313
$System_Drawing_Point.Y = 143
$DescriptionPanelGroupes.Location = $System_Drawing_Point
$DescriptionPanelGroupes.DataBindings.DefaultDataSourceUpdateMode = 0
$DescriptionPanelGroupes.Name = \"DescriptionPanelGroupes\"
$DescriptionPanelGroupes.add_Click($handler_DescriptionPanelGroupes_Click)
$form_Fond.Controls.Add($DescriptionPanelGroupes)
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Width = 200
$System_Drawing_Size.Height = 361
$panel_GroupesOrg1.Size = $System_Drawing_Size
$panel_GroupesOrg1.TabIndex = 11
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 831
$System_Drawing_Point.Y = 189
$panel_GroupesOrg1.Location = $System_Drawing_Point
$panel_GroupesOrg1.DataBindings.DefaultDataSourceUpdateMode = 0
$panel_GroupesOrg1.Name = \"panel_GroupesOrg1\"
$form_Fond.Controls.Add($panel_GroupesOrg1)
$checkedListBox_GroupesOrg1.FormattingEnabled = $True
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Width = 194
$System_Drawing_Size.Height = 349
$checkedListBox_GroupesOrg1.Size = $System_Drawing_Size
$checkedListBox_GroupesOrg1.DataBindings.DefaultDataSourceUpdateMode = 0
$checkedListBox_GroupesOrg1.Name = \"checkedListBox_GroupesOrg1\"
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 3
$System_Drawing_Point.Y = 9
$checkedListBox_GroupesOrg1.Location = $System_Drawing_Point
$checkedListBox_GroupesOrg1.TabIndex = 0
$panel_GroupesOrg1.Controls.Add($checkedListBox_GroupesOrg1)
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Width = 200
$System_Drawing_Size.Height = 361
$panel_GroupesOrg2.Size = $System_Drawing_Size
$panel_GroupesOrg2.TabIndex = 10
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 624
$System_Drawing_Point.Y = 189
$panel_GroupesOrg2.Location = $System_Drawing_Point
$panel_GroupesOrg2.DataBindings.DefaultDataSourceUpdateMode = 0
$panel_GroupesOrg2.Name = \"panel_GroupesOrg2\"
$form_Fond.Controls.Add($panel_GroupesOrg2)
$checkedListBox_GroupesOrg2.FormattingEnabled = $True
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Width = 193
$System_Drawing_Size.Height = 349
$checkedListBox_GroupesOrg2.Size = $System_Drawing_Size
$checkedListBox_GroupesOrg2.DataBindings.DefaultDataSourceUpdateMode = 0
$checkedListBox_GroupesOrg2.Name = \"checkedListBox_GroupesOrg2\"
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 4
$System_Drawing_Point.Y = 9
$checkedListBox_GroupesOrg2.Location = $System_Drawing_Point
$checkedListBox_GroupesOrg2.TabIndex = 0
$panel_GroupesOrg2.Controls.Add($checkedListBox_GroupesOrg2)
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Width = 200
$System_Drawing_Size.Height = 361
$panel_GroupesOrg3.Size = $System_Drawing_Size
$panel_GroupesOrg3.TabIndex = 9
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 417
$System_Drawing_Point.Y = 189
$panel_GroupesOrg3.Location = $System_Drawing_Point
$panel_GroupesOrg3.DataBindings.DefaultDataSourceUpdateMode = 0
$panel_GroupesOrg3.Name = \"panel_GroupesOrg3\"
$form_Fond.Controls.Add($panel_GroupesOrg3)
$checkedListBox_GroupesOrg3.FormattingEnabled = $True
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Width = 193
$System_Drawing_Size.Height = 349
$checkedListBox_GroupesOrg3.Size = $System_Drawing_Size
$checkedListBox_GroupesOrg3.DataBindings.DefaultDataSourceUpdateMode = 0
$checkedListBox_GroupesOrg3.Name = \"checkedListBox_GroupesOrg3\"
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 4
$System_Drawing_Point.Y = 9
$checkedListBox_GroupesOrg3.Location = $System_Drawing_Point
$checkedListBox_GroupesOrg3.TabIndex = 0
$panel_GroupesOrg3.Controls.Add($checkedListBox_GroupesOrg3)
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Width = 200
$System_Drawing_Size.Height = 361
$panel_GroupesOrg4.Size = $System_Drawing_Size
$panel_GroupesOrg4.TabIndex = 8
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 210
$System_Drawing_Point.Y = 189
$panel_GroupesOrg4.Location = $System_Drawing_Point
$panel_GroupesOrg4.DataBindings.DefaultDataSourceUpdateMode = 0
$panel_GroupesOrg4.Name = \"panel_GroupesOrg4\"
$form_Fond.Controls.Add($panel_GroupesOrg4)
$checkedListBox_GroupesOrg4.FormattingEnabled = $True
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Width = 193
$System_Drawing_Size.Height = 349
$checkedListBox_GroupesOrg4.Size = $System_Drawing_Size
$checkedListBox_GroupesOrg4.DataBindings.DefaultDataSourceUpdateMode = 0
$checkedListBox_GroupesOrg4.Name = \"checkedListBox_GroupesOrg4\"
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 4
$System_Drawing_Point.Y = 9
$checkedListBox_GroupesOrg4.Location = $System_Drawing_Point
$checkedListBox_GroupesOrg4.TabIndex = 0
$panel_GroupesOrg4.Controls.Add($checkedListBox_GroupesOrg4)
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Width = 200
$System_Drawing_Size.Height = 361
$panel_GroupesOrg5.Size = $System_Drawing_Size
$panel_GroupesOrg5.TabIndex = 7
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 3
$System_Drawing_Point.Y = 189
$panel_GroupesOrg5.Location = $System_Drawing_Point
$panel_GroupesOrg5.DataBindings.DefaultDataSourceUpdateMode = 0
$panel_GroupesOrg5.Name = \"panel_GroupesOrg5\"
$form_Fond.Controls.Add($panel_GroupesOrg5)
$checkedListBox_GroupesOrg5.FormattingEnabled = $True
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Width = 192
$System_Drawing_Size.Height = 349
$checkedListBox_GroupesOrg5.Size = $System_Drawing_Size
$checkedListBox_GroupesOrg5.DataBindings.DefaultDataSourceUpdateMode = 0
$checkedListBox_GroupesOrg5.Name = \"checkedListBox_GroupesOrg5\"
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 3
$System_Drawing_Point.Y = 9
$checkedListBox_GroupesOrg5.Location = $System_Drawing_Point
$checkedListBox_GroupesOrg5.TabIndex = 6
$panel_GroupesOrg5.Controls.Add($checkedListBox_GroupesOrg5)
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Width = 428
$System_Drawing_Size.Height = 110
$panel_InfoUser.Size = $System_Drawing_Size
$panel_InfoUser.TabIndex = 5
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 448
$System_Drawing_Point.Y = 12
$panel_InfoUser.Location = $System_Drawing_Point
$panel_InfoUser.DataBindings.DefaultDataSourceUpdateMode = 0
$panel_InfoUser.Name = \"panel_InfoUser\"
$form_Fond.Controls.Add($panel_InfoUser)
$comboBox_TypePoste.FormattingEnabled = $True
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Width = 121
$System_Drawing_Size.Height = 21
$comboBox_TypePoste.Size = $System_Drawing_Size
$comboBox_TypePoste.DataBindings.DefaultDataSourceUpdateMode = 0
$comboBox_TypePoste.Name = \"comboBox_TypePoste\"
$comboBox_TypePoste.Items.Add(\"Wyse\"«»)|Out-Null
$comboBox_TypePoste.Items.Add(\"PC\"«»)|Out-Null
$comboBox_TypePoste.Items.Add(\"Portable\"«»)|Out-Null
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 269
$System_Drawing_Point.Y = 80
$comboBox_TypePoste.Location = $System_Drawing_Point
$comboBox_TypePoste.TabIndex = 11
$panel_InfoUser.Controls.Add($comboBox_TypePoste)
$lbl_TypePoste.TabIndex = 10
$lbl_TypePoste.TextAlign = 32
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Width = 100
$System_Drawing_Size.Height = 23
$lbl_TypePoste.Size = $System_Drawing_Size
$lbl_TypePoste.Text = \"Type de Poste\"
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 280
$System_Drawing_Point.Y = 53
$lbl_TypePoste.Location = $System_Drawing_Point
$lbl_TypePoste.DataBindings.DefaultDataSourceUpdateMode = 0
$lbl_TypePoste.Name = \"lbl_TypePoste\"
$panel_InfoUser.Controls.Add($lbl_TypePoste)
$comboBox_Organisme.FormattingEnabled = $True
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Width = 121
$System_Drawing_Size.Height = 21
$comboBox_Organisme.Size = $System_Drawing_Size
$comboBox_Organisme.DataBindings.DefaultDataSourceUpdateMode = 0
$comboBox_Organisme.Name = \"comboBox_Organisme\"
$comboBox_Organisme.Items.Add(\"ORGANISME5\"«»)|Out-Null
$comboBox_Organisme.Items.Add(\"ORGANISME4\"«»)|Out-Null
$comboBox_Organisme.Items.Add(\"ORGANISME3\"«»)|Out-Null
$comboBox_Organisme.Items.Add(\"ORGANISME2\"«»)|Out-Null
$comboBox_Organisme.Items.Add(\"ORGANISME1\"«»)|Out-Null
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 269
$System_Drawing_Point.Y = 25
$comboBox_Organisme.Location = $System_Drawing_Point
$comboBox_Organisme.TabIndex = 9
$comboBox_Organisme.add_SelectedIndexChanged($handler_comboBox1_SelectedIndexChanged)
$panel_InfoUser.Controls.Add($comboBox_Organisme)
$lbl_Organisme.TabIndex = 8
$lbl_Organisme.TextAlign = 32
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Width = 100
$System_Drawing_Size.Height = 23
$lbl_Organisme.Size = $System_Drawing_Size
$lbl_Organisme.Text = \"Organisme\"
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 280
$System_Drawing_Point.Y = 3
$lbl_Organisme.Location = $System_Drawing_Point
$lbl_Organisme.DataBindings.DefaultDataSourceUpdateMode = 0
$lbl_Organisme.Name = \"lbl_Organisme\"
$panel_InfoUser.Controls.Add($lbl_Organisme)
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Width = 100
$System_Drawing_Size.Height = 20
$Email.Size = $System_Drawing_Size
$Email.DataBindings.DefaultDataSourceUpdateMode = 0
$Email.Name = \"Email\"
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 131
$System_Drawing_Point.Y = 80
$Email.Location = $System_Drawing_Point
$Email.TabIndex = 7
$panel_InfoUser.Controls.Add($Email)
$lbl_Email.TabIndex = 6
$lbl_Email.TextAlign = 32
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Width = 100
$System_Drawing_Size.Height = 23
$lbl_Email.Size = $System_Drawing_Size
$lbl_Email.Text = \"Email\"
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 131
$System_Drawing_Point.Y = 53
$lbl_Email.Location = $System_Drawing_Point
$lbl_Email.DataBindings.DefaultDataSourceUpdateMode = 0
$lbl_Email.Name = \"lbl_Email\"
$panel_InfoUser.Controls.Add($lbl_Email)
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Width = 100
$System_Drawing_Size.Height = 20
$Phone.Size = $System_Drawing_Size
$Phone.DataBindings.DefaultDataSourceUpdateMode = 0
$Phone.Name = \"Phone\"
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 131
$System_Drawing_Point.Y = 26
$Phone.Location = $System_Drawing_Point
$Phone.TabIndex = 5
$panel_InfoUser.Controls.Add($Phone)
$lbl_Phone.TabIndex = 4
$lbl_Phone.TextAlign = 32
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Width = 100
$System_Drawing_Size.Height = 23
$lbl_Phone.Size = $System_Drawing_Size
$lbl_Phone.Text = \"Téléphone\"
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 131
$System_Drawing_Point.Y = 3
$lbl_Phone.Location = $System_Drawing_Point
$lbl_Phone.DataBindings.DefaultDataSourceUpdateMode = 0
$lbl_Phone.Name = \"lbl_Phone\"
$panel_InfoUser.Controls.Add($lbl_Phone)
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Width = 100
$System_Drawing_Size.Height = 20
$Nom.Size = $System_Drawing_Size
$Nom.DataBindings.DefaultDataSourceUpdateMode = 0
$Nom.Name = \"Nom\"
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 16
$System_Drawing_Point.Y = 80
$Nom.Location = $System_Drawing_Point
$Nom.TabIndex = 3
$panel_InfoUser.Controls.Add($Nom)
$lbl_Nom.TabIndex = 2
$lbl_Nom.TextAlign = 32
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Width = 100
$System_Drawing_Size.Height = 23
$lbl_Nom.Size = $System_Drawing_Size
$lbl_Nom.Text = \"Nom\"
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 16
$System_Drawing_Point.Y = 54
$lbl_Nom.Location = $System_Drawing_Point
$lbl_Nom.DataBindings.DefaultDataSourceUpdateMode = 0
$lbl_Nom.Name = \"lbl_Nom\"
$panel_InfoUser.Controls.Add($lbl_Nom)
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Width = 100
$System_Drawing_Size.Height = 20
$Prenom.Size = $System_Drawing_Size
$Prenom.DataBindings.DefaultDataSourceUpdateMode = 0
$Prenom.Name = \"Prenom\"
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 16
$System_Drawing_Point.Y = 26
$Prenom.Location = $System_Drawing_Point
$Prenom.TabIndex = 1
$panel_InfoUser.Controls.Add($Prenom)
$lbl_Prenom.TabIndex = 0
$lbl_Prenom.TextAlign = 32
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Width = 100
$System_Drawing_Size.Height = 23
$lbl_Prenom.Size = $System_Drawing_Size
$lbl_Prenom.Text = \"Prénom\"
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 16
$System_Drawing_Point.Y = 3
$lbl_Prenom.Location = $System_Drawing_Point
$lbl_Prenom.DataBindings.DefaultDataSourceUpdateMode = 0
$lbl_Prenom.Name = \"lbl_Prenom\"
$panel_InfoUser.Controls.Add($lbl_Prenom)
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Width = 135
$System_Drawing_Size.Height = 110
$panel_InfoLogin.Size = $System_Drawing_Size
$panel_InfoLogin.TabIndex = 4
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 306
$System_Drawing_Point.Y = 12
$panel_InfoLogin.Location = $System_Drawing_Point
$panel_InfoLogin.DataBindings.DefaultDataSourceUpdateMode = 0
$panel_InfoLogin.Name = \"panel_InfoLogin\"
$form_Fond.Controls.Add($panel_InfoLogin)
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Width = 100
$System_Drawing_Size.Height = 20
$Mdp.Size = $System_Drawing_Size
$Mdp.DataBindings.DefaultDataSourceUpdateMode = 0
$Mdp.Name = \"Mdp\"
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 17
$System_Drawing_Point.Y = 80
$Mdp.Location = $System_Drawing_Point
$Mdp.TabIndex = 3
$panel_InfoLogin.Controls.Add($Mdp)
$lbl_Mdp.TabIndex = 2
$lbl_Mdp.TextAlign = 32
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Width = 100
$System_Drawing_Size.Height = 23
$lbl_Mdp.Size = $System_Drawing_Size
$lbl_Mdp.Text = \"Mot de Passe\"
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 17
$System_Drawing_Point.Y = 53
$lbl_Mdp.Location = $System_Drawing_Point
$lbl_Mdp.DataBindings.DefaultDataSourceUpdateMode = 0
$lbl_Mdp.Name = \"lbl_Mdp\"
$panel_InfoLogin.Controls.Add($lbl_Mdp)
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Width = 100
$System_Drawing_Size.Height = 20
$Login.Size = $System_Drawing_Size
$Login.DataBindings.DefaultDataSourceUpdateMode = 0
$Login.Name = \"Login\"
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 17
$System_Drawing_Point.Y = 26
$Login.Location = $System_Drawing_Point
$Login.TabIndex = 1
$panel_InfoLogin.Controls.Add($Login)
$lbl_Login.TabIndex = 0
$lbl_Login.TextAlign = 32
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Width = 100
$System_Drawing_Size.Height = 23
$lbl_Login.Size = $System_Drawing_Size
$lbl_Login.Text = \"Login\"
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 17
$System_Drawing_Point.Y = 3
$lbl_Login.Location = $System_Drawing_Point
$lbl_Login.DataBindings.DefaultDataSourceUpdateMode = 0
$lbl_Login.Name = \"lbl_Login\"
$panel_InfoLogin.Controls.Add($lbl_Login)
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Width = 145
$System_Drawing_Size.Height = 110
$panel_InfoDomaine.Size = $System_Drawing_Size
$panel_InfoDomaine.TabIndex = 3
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 155
$System_Drawing_Point.Y = 12
$panel_InfoDomaine.Location = $System_Drawing_Point
$panel_InfoDomaine.DataBindings.DefaultDataSourceUpdateMode = 0
$panel_InfoDomaine.Name = \"panel_InfoDomaine\"
$form_Fond.Controls.Add($panel_InfoDomaine)
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Width = 100
$System_Drawing_Size.Height = 20
$CtlDomaine.Size = $System_Drawing_Size
$CtlDomaine.DataBindings.DefaultDataSourceUpdateMode = 0
$CtlDomaine.Name = \"CtlDomaine\"
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 21
$System_Drawing_Point.Y = 80
$CtlDomaine.Location = $System_Drawing_Point
$CtlDomaine.TabIndex = 4
$panel_InfoDomaine.Controls.Add($CtlDomaine)
$lbl_CtlDomaine.TabIndex = 3
$lbl_CtlDomaine.TextAlign = 32
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Width = 133
$System_Drawing_Size.Height = 23
$lbl_CtlDomaine.Size = $System_Drawing_Size
$lbl_CtlDomaine.Text = \"Contrôleur de domaine\"
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 5
$System_Drawing_Point.Y = 54
$lbl_CtlDomaine.Location = $System_Drawing_Point
$lbl_CtlDomaine.DataBindings.DefaultDataSourceUpdateMode = 0
$lbl_CtlDomaine.Name = \"lbl_CtlDomaine\"
$panel_InfoDomaine.Controls.Add($lbl_CtlDomaine)
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Width = 100
$System_Drawing_Size.Height = 20
$NomDomaine.Size = $System_Drawing_Size
$NomDomaine.DataBindings.DefaultDataSourceUpdateMode = 0
$NomDomaine.Name = \"NomDomaine\"
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 21
$System_Drawing_Point.Y = 26
$NomDomaine.Location = $System_Drawing_Point
$NomDomaine.TabIndex = 1
$panel_InfoDomaine.Controls.Add($NomDomaine)
$Lbl_Domaine.TabIndex = 2
$Lbl_Domaine.TextAlign = 32
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Width = 100
$System_Drawing_Size.Height = 21
$Lbl_Domaine.Size = $System_Drawing_Size
$Lbl_Domaine.Text = \"Nom de Domaine\"
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 21
$System_Drawing_Point.Y = 5
$Lbl_Domaine.Location = $System_Drawing_Point
$Lbl_Domaine.DataBindings.DefaultDataSourceUpdateMode = 0
$Lbl_Domaine.Name = \"Lbl_Domaine\"
$Lbl_Domaine.add_Click($handler_label1_Click)
$panel_InfoDomaine.Controls.Add($Lbl_Domaine)
$buttonCreer.TabIndex = 0
$buttonCreer.BackColor = [System.Drawing.Color]::FromArgb(255,255,0,0)
$buttonCreer.Name = \"buttonCreer\"
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Width = 168
$System_Drawing_Size.Height = 76
$buttonCreer.Size = $System_Drawing_Size
$buttonCreer.UseVisualStyleBackColor = $False
$buttonCreer.Text = \"Créer le Compte !\"
$buttonCreer.Font = New-Object System.Drawing.Font(\"Modern No. 20\",17.9999981,1,3,1)
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 427
$System_Drawing_Point.Y = 568
$buttonCreer.Location = $System_Drawing_Point
$buttonCreer.DataBindings.DefaultDataSourceUpdateMode = 0
$buttonCreer.add_Click($handler_button1_Click)
$form_Fond.Controls.Add($buttonCreer)
#endregion Generated Form Code
#######################################
## Création de la fonction Set-Popup ##
#######################################
Function Set-Popup
{
param([string]$message, [string]$titre)
$WshShell = New-Object -ComObject wscript.shell
$WshShell.Popup($message,0,$titre)
}
#Save the initial state of the form
$InitialFormWindowState = $form_Fond.WindowState
#Init the OnLoad event to correct the initial state of the form
$form_Fond.add_Load($OnLoadForm_StateCorrection)
#Show the Form
$form_Fond.ShowDialog()| Out-Null
} #End Function
#Call the Function
GenerateForm
[/code:1]
Voilà les messages d'erreurs :
[code:1]Impossible d'indexer dans un objet de type System.DirectoryServices.PropertyVal
ueCollection.
Au niveau de C:\Users\Administrateur\Documents\Projets\GIE\CreateADUserGIE_Prim
alForms_v0_Beta6.ps1 : 144 Caractère : 29
+ $objUser.userAccountControl[ <<<< 0] = $objUser.userAccountControl[0] -band (
-bnot 2)
+ CategoryInfo : InvalidOperation: (0:Int32) [], RuntimeException
+ FullyQualifiedErrorId : CannotIndex
Exception lors de l'appel de « SetInfo » avec « 0 » argument(s) : « Une syntaxe
DN non valide a été spécifiée.
»
Au niveau de C:\Users\Administrateur\Documents\Projets\GIE\CreateADUserGIE_Prim
alForms_v0_Beta6.ps1 : 145 Caractère : 17
+ $objUser.SetInfo <<<< ()
+ CategoryInfo : NotSpecified: (:«») [], MethodInvocationException
+ FullyQualifiedErrorId : CatchFromBaseAdapterMethodInvokeTI
Exception lors de l'appel de « SetPassword » avec « 1 » argument(s) : « Une syn
taxe DN non valide a été spécifiée.
»
Au niveau de C:\Users\Administrateur\Documents\Projets\GIE\CreateADUserGIE_Prim
alForms_v0_Beta6.ps1 : 146 Caractère : 21
+ $objUser.SetPassword <<<< ($M2p)
+ CategoryInfo : NotSpecified: (:«») [], MethodInvocationException
+ FullyQualifiedErrorId : CatchFromBaseAdapterMethodInvokeTI
[/code:1]
Biensur le compte n'est pas créé.
Pour info le script fonctionnait cette après midi mais comme un gros Kakos j'ai remodifier quelquechose (non je ne me rappelle plus quoi) et maintenant ca marche plus snif snif.......
Pouvez vous y jetter un coup d'oeil afin de voir ou vient le problème.....
Merci d'avance
EDIT 1 : Bon j'ai retrouvé mon erreur
Petit oubli en corrigeant 2 messages d'erreurs.....
Avant :
[code:1][string]$userCN=\"CN=$($Nom) $($Prenom)\"[/code:1]
Après :
[code:1][string]$userCN=\"CN=$($Nm) $($Prnom)\"[/code:1]
avec déjà 751 lignes de code je l'ai raté !
Bon sinon toujours pas moyen d'activer le compte mais bon je vais me replonger dans la base Tech de msdn.....Ca sent la nuit blanche......
EDIT 2 :
bon tout fonctionne.....Mais malheureusement je n'ai pas fini......
Voilà le code partie \"Programme\" :
[code:1]###################################
## Récupération des Champs Texte ##
###################################
[string]$CP = $Login.get_text()
[string]$M2p = $Mdp.get_text()
[string]$Prnom = $Prenom.get_text()
[string]$Nm = $Nom.get_text()
[string]$tel = $Phone.get_text()
[string]$Mail = $Email.get_text()
[string]$Domaine = $NomDomaine.get_text()
[string]$CtrlDomaine = $CtlDomaine.get_text()
[string]$userCN=\"CN=$($Nm) $($Prnom)\"
################################
## Code pour Active Directory ##
################################
$domaineLDAP = \"$Domaine\"
$domaineLDAP = $domaineLDAP.Replace('.',',DC=')
$domaineLDAP = \"DC=$domaineLDAP\"
$Organisme = $ComboBox_Organisme.SelectedItem
$TypePoste = $ComboBox_TypePoste.SelectedItem
$OU = \"OU=$Typeposte,OU=Utilisateurs,OU=$Organisme\"
$objOU = [ADSI]\"LDAP://$OU,$domaineLDAP\"
#########################################################
## On vérifie que l'utilisateur n'existe pas dans l'AD ##
#########################################################
$dom = [System.DirectoryServices.ActiveDirectory.Domain]::GetCurrentDomain()
$domainnb = \"DOMAIN\"
$root = $dom.GetDirectoryEntry()
$search = [System.DirectoryServices.DirectorySearcher]$root
$search.Filter = \"(samAccountName=$CP)\"
$result = $search.FindOne()
if ($result -ne $null) {
$user = $result.GetDirectoryEntry()
Set-Popup -titre 'Avertissement' -message \"L'utilisateur $CP Existe Déjà dans l'AD\"
Break
}
#########################################
## Création de l'utilisateur dans l'AD ##
#########################################
$objUser= $objOU.Create(\"user\",$userCN)
$objUser.put(\"sAMAccountName\", $CP)
$objUser.put(\"userPrincipalName\", \"$CP@$Domaine\"«»)
$objuser.Put(\"displayName\",\"$Prnom $Nm\"«»)
$objUser.put('givenName', $Prnom)
$objUser.put('sn', $Nm)
$objUser.put('Description', \"$Organisme - $Nm $Prnom\"«»)
$objUser.put(”userAccountControl”, 66080)
$objUser.SetInfo()
#######################################################
## Creation du Répertoire Privé avec les permissions ##
#######################################################
### Variables ###
$homeroot = \"\\$CtrlDomaine\share\$Organisme\Users\"
If ( !(Test-Path -Path \"$homeroot\$CP\" -PathType Container) ) {
## Doesn't exist so create it.
Set-Popup -titre 'Avertissement' -message \"Le répertoire Privé a été créer dans $homeroot\$CP !\"
## Create the directory
New-Item -path $homeroot -Name $CP -ItemType Directory
$homedir = \"$homeroot\$CP\"
## Modify Permissions on homedir
## Instead of using the .NET approach of setting NTFS permissions, using xcacls is quicker:
#cscript c:\xcacls.vbs $homedir /E /G `\"$nbdomain\$username`\":M
## The .NET approach - remmed out
## To list available rights options, run: [system.enum]::getnames([System.Security.AccessControl.FileSystemRights])
## To list available inheritance flags, run: [system.enum]::getnames([System.Security.AccessControl.InheritanceFlags])
## Idem for Propagation flags.
$newrights = [System.Security.AccessControl.FileSystemRights]\"FullControl\"
$InheritanceFlag = [System.Security.AccessControl.InheritanceFlags]::\"ContainerInherit\" -bor [System.Security.AccessControl.InheritanceFlags]::\"ObjectInherit\"
$PropagationFlag = [System.Security.AccessControl.PropagationFlags]::\"InheritOnly\"
$Typ = [System.Security.AccessControl.AccessControlType]::Allow
#$ID = new-object System.Security.Principal.NTAccount($domainnb + \"\\" + $CP)
#$SecRule = new-object System.Security.AccessControl.FileSystemAccessRule($ID, $newrights, $InheritanceFlag, $PropagationFlag, $Typ)
$ACL = Get-Acl -Path $homedir
$permission = \"$Domaine\$CP\",\"$newrights\",\"$InheritanceFlag\",\"$PropagationFlag\",\"$Typ\"
$accessRule = New-Object System.Security.AccessControl.FileSystemAccessRule $permission
$acl.SetAccessRule($accessRule)
$acl | Set-Acl $homedir
}
Else {
Set-Popup -titre 'Avertissement' -message \"Le répertoire Privé Existe déjà !\"
Break
}
Set-Popup -titre 'Avertissement' -message \"Compte Créé !\"
}
$OnLoadForm_StateCorrection=
{#Correct the initial state of the form to prevent the .Net maximized form issue
$form_Fond.WindowState = $InitialFormWindowState
}[/code:1]
Pour info Icacls ne fonctionne pas avec Windows 7 & Windows 2008 R2.....Donc j'ai du me pencher sur les ACL .....
En revanche pas moyen de trouver la commande pour récuperer le champ \"Mot de Passe\" et de l'affecter à l'utilisateur lors de la création du compte !!!
Et il faut que je remplace mes commandes Break à la suite de mes popups car j'ai un message d'erreur \"Windows\" pas dans la console PS lorsque l'on clique sur le bouton Ok
Donc Si vous pouvez m'éclairer là dessus ....
Message édité par: rootux, à: 23/06/10 22:35
Message édité par: rootux, à: 24/06/10 01:18
Message édité par: rootux, à: 24/06/10 07:16
Message édité par: rootux, à: 24/06/10 07:23
Message édité par: rootux, à: 24/06/10 07:24<br><br>Message édité par: rootux, à: 27/06/10 01:26
Connexion ou Créer un compte pour participer à la conversation.
- rootux
- Auteur du sujet
- Hors Ligne
- Nouveau membre
-
- Messages : 6
- Remerciements reçus 0
Ce que je n'arrive pas à faire :
- Définir les Options TS dans le profil de l'utilisateur (TSHomePath,...)
- Enlever la demande d'autorisation lors de la prise de contrôle à distance.
- Remplacer les commandes Break (popup d'avertissement) qui génèrent des messages d'erreur Windows
Ce que je cherche a faire maintenant :
- Mettre à jour mes CheckListBox depuis une OU de l'Active Directory soit au démarrage du script ou bien en cliquant sur un bouton \"Récupérer les groupes\"
- Ajouter l'utilisateur aux groupes sélectionnés
Encore quelques nuit blanches en prévision LoL
Pour ceux qui galère comme moi pour migrer de VB à PS je vous met mon code :
$handler_button1_Click=
{
#TODO: Place custom script here
###################################
## Récupération des Champs Texte ##
###################################
[string]$CP = $Login.get_text()
[string]$M2p = $Mdp.get_text()
[string]$Prnom = $Prenom.get_text()
[string]$Nm = $Nom.get_text()
[string]$Tel = $Phone.get_text()
[string]$Mail = $Email.get_text()
[string]$Domaine = $NomDomaine.get_text()
[string]$userCN=\"CN=$($Nm) $($Prnom)\"
################################
## Code pour Active Directory ##
################################
$domaineLDAP = \"$Domaine\"
$domaineLDAP = $domaineLDAP.Replace('.',',DC=')
$domaineLDAP = \"DC=$domaineLDAP\"
$Organisme = $ComboBox_Organisme.SelectedItem
$TypePoste = $ComboBox_TypePoste.SelectedItem
$OU = \"OU=$Typeposte,OU=Utilisateurs,OU=$Organisme\"
$objOU = [ADSI]\"LDAP://$OU,$domaineLDAP\"
#########################################################
## On vérifie que l'utilisateur n'existe pas dans l'AD ##
#########################################################
$dom = [System.DirectoryServices.ActiveDirectory.Domain]::GetCurrentDomain()
$domainnb = \"DOMAIN\"
$root = $dom.GetDirectoryEntry()
$search = [System.DirectoryServices.DirectorySearcher]$root
$search.Filter = \"(samAccountName=$CP)\"
$result = $search.FindOne()
if ($result -ne $null) {
$user = $result.GetDirectoryEntry()
Set-Popup -titre 'Avertissement' -message \"L'utilisateur $CP Existe Déjà dans l'AD\"
Break
}
#########################################
## Création de l'utilisateur dans l'AD ##
#########################################
$objUser= $objOU.Create(\"user\",$userCN)
$objUser.put(\"sAMAccountName\", $CP)
$objUser.put(\"userPrincipalName\", \"$CP@$Domaine\"«»)
$objuser.Put(\"displayName\",\"$Prnom $Nm\"«»)
$objUser.put('givenName', $Prnom)
$objUser.put('sn', $Nm)
$objUser.put('Description', \"$Organisme - $Nm $Prnom\"«»)
$objUser.put('telephoneNumber', \"$Tel\"«»)
$objUser.put('mail', \"$Mail\"«»)
$objUser.put(”userAccountControl”, 66080)
$objUser.SetInfo()
$objUser.psbase.Invoke(\"SetPassword\",$M2p)
$objUser.psbase.CommitChanges()
Set-Popup -titre 'Avertissement' -message \"Le compte $cp@$domaine a été créé !\"
################################################
## Selection du CIFS selon l'Organisme Choisi ##
################################################
Switch ($Organisme)
{
Org5 {cifs02}
Org4 {cifs01}
Org3 {cifs01}
Org2 {cifs02}
Org1 {cifs02}
}
}
#######################################
## Création de la fonction Set-Popup ##
#######################################
Function Set-Popup
{
param([string]$message, [string]$titre)
$WshShell = New-Object -ComObject wscript.shell
$WshShell.Popup($message,0,$titre)
}
####################################
## Création de la fonction cifs01 ##
####################################
Function cifs01
{
############################################################################
## Creation du Répertoire Privé avec les permissions pour Cifs01 ##
############################################################################
### Variables ###
$homeroot = \"\\cifs01\Prive$Organisme\"
If ( !(Test-Path -Path \"$homeroot\$CP\" -PathType Container) ) {
## Popup d'avertissement
Set-Popup -titre 'Avertissement' -message \"Le répertoire Privé a été créer dans $homeroot\$CP !\"
## Creation du répertoire Privé
New-Item -path $homeroot -Name $CP -ItemType Directory
$homedir = \"$homeroot\$CP\"
## Modification des Permissions du répertoire Privé
$newrights = [System.Security.AccessControl.FileSystemRights]\"FullControl\"
$InheritanceFlag = [System.Security.AccessControl.InheritanceFlags]::\"ContainerInherit\" -bor [System.Security.AccessControl.InheritanceFlags]::\"ObjectInherit\"
$PropagationFlag = [System.Security.AccessControl.PropagationFlags]::\"none\" #InheritOnly
$Typ = [System.Security.AccessControl.AccessControlType]::Allow
$ACL = Get-Acl -Path $homedir
$permission = \"$Domaine\$CP\",\"$newrights\",\"$InheritanceFlag\",\"$PropagationFlag\",\"$Typ\"
$accessRule = New-Object System.Security.AccessControl.FileSystemAccessRule $permission
$acl.SetAccessRule($accessRule)
$acl | Set-Acl $homedir
}
Else {
Set-Popup -titre 'Avertissement' -message \"Le répertoire Privé Existe déjà !\"
Break
}
Set-Popup -titre 'Résumé' -message \"Le compte s'appelle $CP@$Domaine & son répertoire privé se trouve dans $homeroot\$CP \"
}
####################################
## Création de la fonction cifs02 ##
####################################
Function cifs02
{
##########################################################################
## Creation du Répertoire Privé avec les permissions pour Cifs02##
##########################################################################
### Variables ###
$homeroot = \"\\cifs02\Prive$Organisme\"
If ( !(Test-Path -Path \"$homeroot\$CP\" -PathType Container) ) {
## Popup d'avertissement
Set-Popup -titre 'Avertissement' -message \"Le répertoire Privé a été créer dans $homeroot\$CP !\"
## Creation du répertoire Privé
New-Item -path $homeroot -Name $CP -ItemType Directory
$homedir = \"$homeroot\$CP\"
## Modification des Permissions du répertoire Privé
$newrights = [System.Security.AccessControl.FileSystemRights]\"FullControl\"
$InheritanceFlag = [System.Security.AccessControl.InheritanceFlags]::\"ContainerInherit\" -bor [System.Security.AccessControl.InheritanceFlags]::\"ObjectInherit\"
$PropagationFlag = [System.Security.AccessControl.PropagationFlags]::\"none\" #InheritOnly
$Typ = [System.Security.AccessControl.AccessControlType]::Allow
$ACL = Get-Acl -Path $homedir
$permission = \"$Domaine\$CP\",\"$newrights\",\"$InheritanceFlag\",\"$PropagationFlag\",\"$Typ\"
$accessRule = New-Object System.Security.AccessControl.FileSystemAccessRule $permission
$acl.SetAccessRule($accessRule)
$acl | Set-Acl $homedir
}
Else {
Set-Popup -titre 'Avertissement' -message \"Le répertoire Privé Existe déjà !\"
Break
}
Set-Popup -titre 'Résumé' -message \"Le compte s'appelle $CP@$Domaine & son répertoire privé se trouve dans $homeroot\$CP \"
}<br><br>Message édité par: rootux, à: 27/06/10 01:34
Connexion ou Créer un compte pour participer à la conversation.
- Laurent Dardenne
- Hors Ligne
- Modérateur
-
- Messages : 6311
- Remerciements reçus 68
rootux écrit:
Effectue une recherche sur le forum le sujet a déjà été traité.- Définir les Options TS dans le profil de l'utilisateur (TSHomePath,...)
rootux écrit:
Utilise l'instruction Return.- Remplacer les commandes Break (popup d'avertissement) qui génèrent des messages d'erreur Windows
Au lieu d'utiliser WSH pour Set-Popup, tu peux utiliser cette fonction PowerShell .
Tu devrais créer des fonctions spécialisés au lieu de tout placer dans les gestionnaires d'événements (cf. $handler_button1_Click)
Les cas d'erreurs ne sont pas gérés correctement, sur un PC standalone j'ai de nombreuses erreurs sur la console alors que l'interface m'indique, via des popup, que l'opération a réussie
Tutoriels PowerShell
Connexion ou Créer un compte pour participer à la conversation.
- rootux
- Auteur du sujet
- Hors Ligne
- Nouveau membre
-
- Messages : 6
- Remerciements reçus 0
Salut,
rootux écrit:Effectue une recherche sur le forum le sujet a déjà été traité.- Définir les Options TS dans le profil de l'utilisateur (TSHomePath,...)
J'ai tout testé mais je n'ai pas réussi à y arriver....Je pense qu'il faut que j'utilise \"Quest\" mais malgrès l'installation du produit la commande ne fonctionne pas......Même avec PowerGUI je n'arrive pas à mettre a jour la partie TS d'un utilisateur.....
j'obtiens ce message d'erreur :
[code:1] Nom inconnu. (Exception de HRESULT : 0x80020006 (DISP_E_UNKNOWNNAME)) (Set-QADUser)[/code:1]
rootux écrit:
Donc je crois que je vais resortir mon VBS et extraire la partie qui m'intéresse.....
Pour info je suis sur un domaine 2008 R2 ,peut etre que les commandes ne marches plus ? car dans tous les tutos que j'ai pu lire il était valable pour 2003 et pas testé sous 2008 R2
Utilise l'instruction Return.- Remplacer les commandes Break (popup d'avertissement) qui génèrent des messages d'erreur Windows
Merci ca marche mieux
Au lieu d'utiliser WSH pour Set-Popup, tu peux utiliser cette fonction PowerShell .
En même temps ca marche bien et je trouve que c'est plus simple.....
Est ce grave si j'utilise WSH ?
Tu devrais créer des fonctions spécialisés au lieu de tout placer dans les gestionnaires d'événements (cf. $handler_button1_Click)
Je comprend pas désolé...J'ai commencé les PowerShell il y a 5 jours et j'ai un peu de mal
Les cas d'erreurs ne sont pas gérés correctement, sur un PC standalone j'ai de nombreuses erreurs sur la console alors que l'interface m'indique, via des popup, que l'opération a réussie
Ouais mais bon en même temps c'est pas un script qui est fait pour travaillé en Standalone.....Mais tu as raison quand j'aurai fini d'intégré les dernieres fonctions je pourrai faire de la gestion d'erreur.....A moins que je le fasse faire par notre stagiaire hihihi...C'est bon sujet de stage
Pour faire mes tests je me suis monté un Controleur sous 2008 R2 et j'ai ajouter \"cifs01\" & \"cifs02\" dans le dns pour qu'il pointe dessus avec les partages qu'il faut (Prive[Organisme] & Profiltse[Organisme] pour chaque organismes) & L'Active Directory est structuré de la même façon pour tous les organismes :
Racine de l'AD
Organisme1
Groupes
Imprimantes
Postes
PC
Portable
Utilisateurs <<== Ecrit en dur dans le script
PC
Portable
Wyse
Sinon tu n'aurai pas une piste pour mettre a jour mes CheckedListBox depuis l'AD ? En passant par un csv si il faut .... En plus j'ai oublié le bouquin au Boulot donc il me reste que google mais c'est assez compliqué de trouver des infos claires sur powershell.....Contrairement à VB , mais PS est encore jeune et doit murir
Connexion ou Créer un compte pour participer à la conversation.
- rootux
- Auteur du sujet
- Hors Ligne
- Nouveau membre
-
- Messages : 6
- Remerciements reçus 0
J'avais bien installé le AdminPAK 2008 pour Windows7 mais j'avais oublié d'activer les fonctionnalités Windows (dans Programmes & Fonctionnalités\")...Quel andouille
Bon voilà la partie création est finie me reste plus que ces foutues checkedlistbox à nourir avec le contenu de l'OU qui correspond.....
Connexion ou Créer un compte pour participer à la conversation.
- rootux
- Auteur du sujet
- Hors Ligne
- Nouveau membre
-
- Messages : 6
- Remerciements reçus 0
[code:1]Function Get-ListBox
{
[System.Reflection.Assembly]::LoadWithPartialName(\"System.windows.forms\"«») |
out-null
$Form1 = new-object Windows.Forms.Form
$Form1.text = \"ListBox Control\"
$Form1.Size = new-object Drawing.Size(500,300)
$checkedListBox_Groupes1 = New-Object System.Windows.Forms.CheckedListBox
$checkedListBox_Groupes1.Size = new-object Drawing.Size(500,300)
$source = \"c:\groupes.txt\"
$Form1.controls.add($checkedListBox_Groupes1)
ForEach($i in (Get-Content $source))
{ $checkedListBox_Groupes1.items.add($i) | Out-Null }
$Form1.Add_Shown($Form1.Activate())
$Form1.showdialog() | out-null
$checkedListBox_Groupes1.SelectedItem
} #end function Get-ListBox
# *** Entry Point to Script ***
Get-ListBox[/code:1]
A la base c'est une ListBox j'ai juste modifié :
[code:1]New-Object System.Windows.Forms.ListBox[/code:1]
Par :
[code:1]New-Object System.Windows.Forms.CheckedListBox[/code:1]
Et ca marche nickel
Maintenant reste plus qu'à remplacer le TXT par une commande qui me renvoie les groupes d'une OU et c'est GOOD !! ....... Finalement c'est facile powershell
Connexion ou Créer un compte pour participer à la conversation.
- Vous êtes ici :
-
Accueil
-
forum
-
PowerShell
-
Entraide pour les débutants
- Projet Création User AD