0

I am trying to get this powershell code to work, but to no avail. I get the following error:

Set-GPLink : Cannot validate argument on parameter 'Target'. The argument is null or empty. Provide an argument that is not null or empty, and then try the command again.

Here's the code :

 function gpo_order([string]$nom_gpo,[string]$nom_ou,[int]$nombre)

    {
        if ($nom_gpo.TEXT -eq "")
    {
 $erreur.Text = "Vous devez entrer un nom de gpo"
 }

Elseif ($nom_ou.TEXT -eq "")
 {
    $erreur.Text = "Vous devez entrer un nom de OU sous la forme 'ou=Bureautique,ou=Desjardins,dc=mvt,dc=desjardins,dc=com'"
 }

Elseif ($gpo_rang.TEXT -eq "") 
{
$erreur.Text = "Vous devez entrer un numéro de rang pour la gpo"
}

else
{
****Set-GPLink -Name $nom_gpo -Target $nom_ou -Order $nombre****

  
}
}

I cannot figure out the problem.

Daemon Painter
  • 3,208
  • 3
  • 29
  • 44
  • welcome to SO. Apparently $nom_ou is empty, try printing it out to see if it is indeed not-empty. – Daemon Painter Feb 15 '21 at 21:00
  • 2
    Show us how you call rhe function and especially what you are sending to parameter `$nom_ou` – Theo Feb 15 '21 at 21:23
  • Here's how i call the functions : $Bouton_gpo_ordre.Add_Click({ $erreur.text = "" ;gpo_order($nom_gpo.Text,$nom_ou.Text,$gpo_rang.Text) }) – Fausto Paquin Feb 16 '21 at 12:43
  • Here's the TextBox code : $nom_ou = New-Object system.Windows.Forms.TextBox $nom_ou.multiline = $True $nom_ou.text = "" $nom_ou.width = 228 $nom_ou.height = 20 $nom_ou.location = New-Object System.Drawing.Point(250,150) $nom_ou.Font = New-Object System.Drawing.Font('Microsoft Sans Serif',10) – Fausto Paquin Feb 16 '21 at 13:21
  • Remove the brackets when calling a function. PowerShell uses **space** characters on function parameters: `gpo_order($nom_gpo.Text,$nom_ou.Text,$gpo_rang.Text)` --> `gpo_order $nom_gpo.Text $nom_ou.Text $gpo_rang.Text)` – Theo Feb 17 '21 at 10:57

0 Answers0