Question [Résolu] Problème recherche et affichage textbox

Plus d'informations
il y a 7 ans 11 mois #25507 par Riblito
Salut !

j'appel à l'aide ! j'avais pour mon mémoire de fin d'étude réalisé une petite interface PowerShell pour lister les ordis sur le réseau avec leurs OS.

J'ai réussi.

Sauf que plusieurs mois plus tard, j'ai voulu tester un truc, j'ai supprimé des choses que j'aurais pas du et PowerShell ISE à planté, et donc ça a sauvegardé et plus rien fonctionne.
Vu que j'ai pas touché au PowerShell depuis longtemps je me souviens plus du tout se que j'avais écrie, et je dois rendre mon mémoire lundi prochain :sick:.

En gros, maintenant la recherche fonctionne plus, si vous pouviez regarder mon code ! merci beaucoup !

[code:1]# Windows form
[void][System.Reflection.Assembly]::LoadWithPartialName(\"System.Windows.Forms\"«»)
[void][System.Reflection.Assembly]::LoadWithPartialName(\"System.Drawing\"«»)

##########################################################################
# Les forms #
##########################################################################

#form accueil
$form = New-Object Windows.Forms.Form
$form.FormBorderStyle = [System.Windows.Forms.FormBorderStyle]::FixedDialog
$form.MaximizeBox = $false
$form.MinimizeBox = $false
$form.Text = \"Projet\"
$form.Size = New-Object System.Drawing.Size(600,379)
$form.StartPosition = \"CenterScreen\"

##########################################################################
# Composants #
##########################################################################

#combobox
$combo = New-Object System.Windows.Forms.ComboBox
$combo.Location = New-Object System.Drawing.Point(71,15)
$combo.Size = New-Object System.Drawing.Size(80, 310)
$ServNames = @(\"'*Windows 10 Enterprise*'\",\"'*Windows 7 Enterprise*'\",\"'*Windows XP*'\"«»)
foreach($Serv in $ServNames)
{
$combo.Items.add($Serv)
}

# Label nom
$label = New-Object System.Windows.Forms.Label
$label.AutoSize = $true
$label.Location = New-Object System.Drawing.Point(26,15)
$label.Size = New-Object System.Drawing.Size(100,20)
$label.Text = \"OS :\"

$ClickedFont = [System.Drawing.Font]::new('Courier New', 8, [System.Drawing.FontStyle]::Italic)
# TextBox nom
$textbox = New-Object System.Windows.Forms.RichTextBox
$textbox.Font = $ClickedFont
$textbox.WordWrap = $true
$textbox.Multiline = $true
$textbox.ReadOnly = $true
$textbox.Location = New-Object System.Drawing.Point(8,47)
$textbox.Name = 'textbox'
$textbox.Size = New-Object System.Drawing.Size(577,296)

#bouton
$bouton = New-Object System.Windows.Forms.Button
$bouton.Text = \"recherche\"
$bouton.Size = New-Object System.Drawing.Size(50,20)
$bouton.Location = New-Object System.Drawing.Size(200,15)

##########################################################################
# evenement #
##########################################################################
$bouton.Add_Click(
{
$textbox.Text = Get-ADComputer -Filter { OperatingSystem -Like $combo.Text } -Property * -SearchBase \"xxxx\" | Select-Object Name,OperatingSystem
})


##########################################################################
# affichage elements #
##########################################################################

$form.Controls.Add($textbox)
$form.Controls.Add($label)
$form.Controls.Add($combo)
$form.Controls.Add($bouton)

$form.ShowDialog()[/code:1]<br><br>Message édité par: Arnaud, à: 12/06/18 08:53

Connexion ou Créer un compte pour participer à la conversation.

Plus d'informations
il y a 7 ans 11 mois #25509 par Philippe
salut elemremy

j'ai trouver un vieux post de toi de janvier et je pense que ta solution est celle ci-dessous, je te donne que la partie modifier la fonction add_click :

[code:1]$bouton.Add_Click(
{
$result = Get-ADComputer -Filter { OperatingSystem -Like $combo.Text } -Property OperatingSystem | Select-Object Name,OperatingSystem
foreach ($item in $result)
{
$textbox.AppendText($item.name + ' ' + $item.OperatingSystem + \&quot;`r`n\&quot;«»)
}
})
[/code:1]

Connexion ou Créer un compte pour participer à la conversation.

Plus d'informations
il y a 7 ans 11 mois #25511 par Philippe
j'ai oublier de dire que j'ai aussi enlever les apostrophes dans les OS

[code:1]$ServNames = @(\&quot;*Windows 10 Enterprise*\&quot;,\&quot;*Windows 7 Enterprise*\&quot;,\&quot;*Windows XP*\&quot;«»)
[/code:1]

perso j'ai fait ceci pour avoir tous les OS presents

[code:1]$ServNames = Get-ADComputer -Filter * -Property OperatingSystem -SearchBase \&quot;xxxx\&quot; | Select-Object OperatingSystem -Unique
foreach($Serv in $ServNames)
{
[void]$combo.Items.add($Serv.OperatingSystem)
}
[/code:1]

pour info
pour que la requête Get-ADComputer soit moins lente dans la recherche, ne prend pas toutes les propriétés (-Property *)
ne sélectionne que celle dont tu a besoin (-Property OperatingSystem)<br><br>Message édité par: 6ratgus, à: 5/06/18 10:55

Connexion ou Créer un compte pour participer à la conversation.

Plus d'informations
il y a 7 ans 11 mois #25530 par Riblito
merci pour ta réponse.

J'ai pu corriger des erreurs.

Mais j'ai encore un problème.

J'avais réussi à l'afficher dans ma textbox, et bien aligné en colonne.

Mais maintenant j'ai ça :

Microsoft.PowerShell.Commands.Internal.Format.FormatEntryData Microsoft.PowerShell.Commands.Internal.Format.FormatEntryData Microsoft.PowerShell.Commands.Internal.Format.FormatEntryData Microsoft.PowerShell.Commands.Internal.Format.FormatEntryData Microsoft.PowerShell.Commands.Internal.Format.FormatEntryData Microsoft.PowerShell.Commands.Internal.Format.FormatEntryData Microsoft.PowerShell.Commands.Internal.Format.FormatEntryData Microsoft.PowerShell.Commands.Internal.Format.FormatEntryData Microsoft.PowerShell.Commands.Internal.Format.FormatEntryData


si j'avais su j'aurais fais une copie de mon script pff

Connexion ou Créer un compte pour participer à la conversation.

Plus d'informations
il y a 7 ans 11 mois #25533 par Arnaud Petitjean
Tu as du laisser trainer quelque part dans ton script une commande de formatage telle que Format-List ou Format-Table. Supprime là car celle-ci modifie tes objets dans le but de les afficher dans la console PowerShell et uniquement dans la console; ce qui n'est à priori pas ton objectif.

Arnaud

MVP PowerShell et créateur de ce magnifique forum :-)
Auteur de 6 livres PowerShell aux éditions ENI
Fondateur de la société Start-Scripting
Besoin d'une formation PowerShell ?

Connexion ou Créer un compte pour participer à la conversation.

Plus d'informations
il y a 7 ans 11 mois #25576 par Riblito
Ha mais oui effectivement :whistle: .... je suis bête.

merci beaucoup pour vos réponses, j'ai eu la trouille :laugh:


J'ai une question bonus, j'en ai pas besoin mais je suis curieux. Est il possible d'afficher qu'un morceau d'une recherche ?

par exemple si je recherche le managedby d'un PC il va m'indiquer le chemin complet :
CN=JEanLoui,OU=Users,OU=CXXXX,OU=XX,OU=FR,OU=EU,DC=XXX,DC=net

est-il possible d'afficher que \&quot;JeanLoui\&quot; ?<br><br>Message édité par: elemremy, à: 8/06/18 09:08

Connexion ou Créer un compte pour participer à la conversation.

Temps de génération de la page : 0.043 secondes
Propulsé par Kunena