Question
GUI recherche AD/DHCP
- Vlasto
- Auteur du sujet
- Hors Ligne
- Nouveau membre
-
Réduire
Plus d'informations
- Messages : 1
- Remerciements reçus 0
il y a 6 ans 8 mois #29039
par Vlasto
GUI recherche AD/DHCP a été créé par Vlasto
Bonjour,
Je me présente Benoît, admin systèmes et je débute un peu en powershell.
Je voudrais me faire une GUI afin de pourvoir chercher une description dans l'AD, en récupérer la MAC afin de récupérer la réservation correspondante.
Les points bloquants que je rencontre sont :
-je suis obligé de taper des étoiles pour encadrer ma recherche sinon rien ne m'ai retourné;
-si le get-dhcpserver4reservation retourne une erreur, car pas de réservation dans le scope rien ne s'affiche dans ma textbox.
Y a-t-il un moyen de passer outre ces erreurs afin de n'afficher que les réservations ?
Quelle est la syntaxe de ma description à mettre ? J'ai essayer moult expression avec des \"\", '' ... mais rien n'y fait
Voici mon code pour l'heure, si quelqu'un saurait où je pêche.
[code:1]Set-ExecutionPolicy unrestricted
Add-Type -AssemblyName System.Windows.Forms
[void][System.Reflection.Assembly]::LoadWithPartialName(\"System.Windows.Form\"«»)
[void][System.Reflection.Assembly]::LoadWithPartialName(\"System.drawing\"«»)
$form = New-Object Windows.Forms.Form
$form.FormBorderStyle = [System.Windows.Forms.FormBorderStyle]::FixedDialog
$form.MaximizeBox = $false
$form.MinimizeBox = $false
$form.text = \"Recherche Ordinateurs\"
$form.Size = New-Object System.Drawing.Size(1150,600)
$search = New-Object System.Windows.Forms.TextBox
$search.Location = New-Object System.Drawing.Point(200,20)
$search.Size = New-Object System.Drawing.Size(800,20)
$searchbut = New-Object System.Windows.Forms.Button
$searchbut.AutoSize = $false
$searchbut.Location = New-Object System.Drawing.Point(1020,20)
$searchbut.size = New-Object System.Drawing.Size(80,20)
$searchbut.text = \"Chercher\"
$showAD = New-Object System.Windows.Forms.TextBox
$showAD.Multiline = $true
$showAD.Location = New-Object System.Drawing.Point(50,80)
$showAD.Size = New-Object System.Drawing.Size(500,400)
$showAD.ScrollBars = 'vertical'
$showDHCP = New-Object System.Windows.Forms.TextBox
$showDHCP.Multiline = $true
$showDHCP.Location = New-Object System.Drawing.Point(600,80)
$showDHCP.Size = New-Object System.Drawing.Size(500,400)
$showDHCP.ScrollBars = 'vertical'
$quit_but = New-Object System.Windows.Forms.Button
$quit_but.AutoSize = $false
$quit_but.Location = New-Object System.Drawing.Point(1020,520)
$quit_but.Size = New-Object System.Drawing.Size(80,40)
$quit_but.Text = \"Quitter\"
$ADserveur = 'srvAD'
$DHCPserveur = 'srvDHCP'
if((Get-Module ActiveDirectory) -eq $null){
try{
Import-Module ActiveDirectory
}catch{
Write-Host \"Outils AD absent, script non utilisable.\"
return
}
}
if((Get-Module DhcpServer) -eq $null){
try{
Import-Module DhcpServer
}catch{
write-host \"Outils DHCP absent, script non utilisable.\"
return
}
}
$searchbut.add_click(
{
$description = $search.Text
$ordis = Get-ADComputer -Filter {description -like $description} -Server $ADserveur -properties name,description |Sort-Object {$_.Name} | ft @{label='Nom Ordinateur';e={$_.name}},@{label='Description';e={$_.description}} |Out-String
$macs = Get-ADComputer -Filter {description -like $description} -Server $ADserveur | Select -ExpandProperty Name
foreach ($ordi in $ordis){
$showAD.text = $ordis
$macs = $macs.replace(\"UC\",\"\"«»)
$scopes = (\"scope1\",\"scope2\",\"scope3\"«»)
foreach ($scope in $scopes) {
$reservation = Get-DhcpServerv4Reservation -ClientId $macs -ScopeId $scope -ComputerName $DHCPserveur | Sort-Object {$_.Name} | ft @{label=\"Adresse IP\";expression={$_.IPAddress}},@{label=\"Adresse MAC\";expression={$_.ClientID}},@{label=\"Descripstion\";expression={$_.Description}} | Out-String
$showDHCP.Text = $reservation
}
}
})
$quit_but.add_click(
{
$form.close();
})
$form.Controls.Add($search)
$form.Controls.Add($showAD)
$form.Controls.Add($showDHCP)
$form.Controls.Add($searchbut)
$form.Controls.Add($quit_but)
$form.ShowDialog()[/code:1]
Je me présente Benoît, admin systèmes et je débute un peu en powershell.
Je voudrais me faire une GUI afin de pourvoir chercher une description dans l'AD, en récupérer la MAC afin de récupérer la réservation correspondante.
Les points bloquants que je rencontre sont :
-je suis obligé de taper des étoiles pour encadrer ma recherche sinon rien ne m'ai retourné;
-si le get-dhcpserver4reservation retourne une erreur, car pas de réservation dans le scope rien ne s'affiche dans ma textbox.
Y a-t-il un moyen de passer outre ces erreurs afin de n'afficher que les réservations ?
Quelle est la syntaxe de ma description à mettre ? J'ai essayer moult expression avec des \"\", '' ... mais rien n'y fait
Voici mon code pour l'heure, si quelqu'un saurait où je pêche.
[code:1]Set-ExecutionPolicy unrestricted
Add-Type -AssemblyName System.Windows.Forms
[void][System.Reflection.Assembly]::LoadWithPartialName(\"System.Windows.Form\"«»)
[void][System.Reflection.Assembly]::LoadWithPartialName(\"System.drawing\"«»)
$form = New-Object Windows.Forms.Form
$form.FormBorderStyle = [System.Windows.Forms.FormBorderStyle]::FixedDialog
$form.MaximizeBox = $false
$form.MinimizeBox = $false
$form.text = \"Recherche Ordinateurs\"
$form.Size = New-Object System.Drawing.Size(1150,600)
$search = New-Object System.Windows.Forms.TextBox
$search.Location = New-Object System.Drawing.Point(200,20)
$search.Size = New-Object System.Drawing.Size(800,20)
$searchbut = New-Object System.Windows.Forms.Button
$searchbut.AutoSize = $false
$searchbut.Location = New-Object System.Drawing.Point(1020,20)
$searchbut.size = New-Object System.Drawing.Size(80,20)
$searchbut.text = \"Chercher\"
$showAD = New-Object System.Windows.Forms.TextBox
$showAD.Multiline = $true
$showAD.Location = New-Object System.Drawing.Point(50,80)
$showAD.Size = New-Object System.Drawing.Size(500,400)
$showAD.ScrollBars = 'vertical'
$showDHCP = New-Object System.Windows.Forms.TextBox
$showDHCP.Multiline = $true
$showDHCP.Location = New-Object System.Drawing.Point(600,80)
$showDHCP.Size = New-Object System.Drawing.Size(500,400)
$showDHCP.ScrollBars = 'vertical'
$quit_but = New-Object System.Windows.Forms.Button
$quit_but.AutoSize = $false
$quit_but.Location = New-Object System.Drawing.Point(1020,520)
$quit_but.Size = New-Object System.Drawing.Size(80,40)
$quit_but.Text = \"Quitter\"
$ADserveur = 'srvAD'
$DHCPserveur = 'srvDHCP'
if((Get-Module ActiveDirectory) -eq $null){
try{
Import-Module ActiveDirectory
}catch{
Write-Host \"Outils AD absent, script non utilisable.\"
return
}
}
if((Get-Module DhcpServer) -eq $null){
try{
Import-Module DhcpServer
}catch{
write-host \"Outils DHCP absent, script non utilisable.\"
return
}
}
$searchbut.add_click(
{
$description = $search.Text
$ordis = Get-ADComputer -Filter {description -like $description} -Server $ADserveur -properties name,description |Sort-Object {$_.Name} | ft @{label='Nom Ordinateur';e={$_.name}},@{label='Description';e={$_.description}} |Out-String
$macs = Get-ADComputer -Filter {description -like $description} -Server $ADserveur | Select -ExpandProperty Name
foreach ($ordi in $ordis){
$showAD.text = $ordis
$macs = $macs.replace(\"UC\",\"\"«»)
$scopes = (\"scope1\",\"scope2\",\"scope3\"«»)
foreach ($scope in $scopes) {
$reservation = Get-DhcpServerv4Reservation -ClientId $macs -ScopeId $scope -ComputerName $DHCPserveur | Sort-Object {$_.Name} | ft @{label=\"Adresse IP\";expression={$_.IPAddress}},@{label=\"Adresse MAC\";expression={$_.ClientID}},@{label=\"Descripstion\";expression={$_.Description}} | Out-String
$showDHCP.Text = $reservation
}
}
})
$quit_but.add_click(
{
$form.close();
})
$form.Controls.Add($search)
$form.Controls.Add($showAD)
$form.Controls.Add($showDHCP)
$form.Controls.Add($searchbut)
$form.Controls.Add($quit_but)
$form.ShowDialog()[/code:1]
Connexion ou Créer un compte pour participer à la conversation.
Temps de génération de la page : 0.037 secondes
- Vous êtes ici :
-
Accueil
-
forum
-
PowerShell
-
Entraide pour les débutants
- GUI recherche AD/DHCP