The script, when not included in a form/GUI, searches AD, including deleted items for a user object. You then have the option to restore the object if required.
The powershell created by PrimalForms is below, my script additions are in the Generated Event Script Blocks section. I have not added anything for the restore button.
PowerShell Code
Double-click the code block to select all.#Generated Form Function function GenerateForm { ######################################################################## # Code Generated By: SAPIEN Technologies PrimalForms (Community Edition) v1.0.10.0 # Generated On: 1/31/2014 3:18 PM # Generated By: gdavies ######################################################################## #region Import the Assemblies [reflection.assembly]::loadwithpartialname("System.Windows.Forms") | Out-Null [reflection.assembly]::loadwithpartialname("System.Drawing") | Out-Null #endregion #region Generated Form Objects $ADSearchandRestore = New-Object System.Windows.Forms.Form $Results = New-Object System.Windows.Forms.ListView $Instructions = New-Object System.Windows.Forms.Label $Input = New-Object System.Windows.Forms.TextBox $Exit = New-Object System.Windows.Forms.Button $Restore = New-Object System.Windows.Forms.Button $Search = 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. $Restore_OnClick= { } $loadmodule= {import-module activedirectory set-location ad: } $Exit_OnClick= {$ADSearchandRestore.Close()} $Search_OnClick= {Get-ADObject -Filter "displayName -eq '$input.text'" -IncludeDeletedObjects $Results.Focus()} $OnLoadForm_StateCorrection= {#Correct the initial state of the form to prevent the .Net maximized form issue $ADSearchandRestore.WindowState = $InitialFormWindowState } #---------------------------------------------- #region Generated Form Code $System_Drawing_Size = New-Object System.Drawing.Size $System_Drawing_Size.Height = 241 $System_Drawing_Size.Width = 289 $ADSearchandRestore.ClientSize = $System_Drawing_Size $ADSearchandRestore.DataBindings.DefaultDataSourceUpdateMode = 0 $ADSearchandRestore.Name = "ADSearchandRestore" $ADSearchandRestore.Text = "AD Search & Restore" $Results.DataBindings.DefaultDataSourceUpdateMode = 0 $System_Drawing_Point = New-Object System.Drawing.Point $System_Drawing_Point.X = 12 $System_Drawing_Point.Y = 125 $Results.Location = $System_Drawing_Point $Results.Name = "Results" $System_Drawing_Size = New-Object System.Drawing.Size $System_Drawing_Size.Height = 97 $System_Drawing_Size.Width = 265 $Results.Size = $System_Drawing_Size $Results.TabIndex = 5 $Results.UseCompatibleStateImageBehavior = $False $Results.View = 3 $ADSearchandRestore.Controls.Add($Results) $Instructions.DataBindings.DefaultDataSourceUpdateMode = 0 $Instructions.Font = New-Object System.Drawing.Font("Microsoft Sans Serif",9,0,3,0) $System_Drawing_Point = New-Object System.Drawing.Point $System_Drawing_Point.X = 12 $System_Drawing_Point.Y = 9 $Instructions.Location = $System_Drawing_Point $Instructions.Name = "Instructions" $System_Drawing_Size = New-Object System.Drawing.Size $System_Drawing_Size.Height = 49 $System_Drawing_Size.Width = 265 $Instructions.Size = $System_Drawing_Size $Instructions.TabIndex = 4 $Instructions.Text = "Enter the full Display Name you wish to search for/restore in the box below" $Instructions.TextAlign = 32 $ADSearchandRestore.Controls.Add($Instructions) $Input.DataBindings.DefaultDataSourceUpdateMode = 0 $Input.Font = New-Object System.Drawing.Font("Microsoft Sans Serif",8.25,2,3,0) $System_Drawing_Point = New-Object System.Drawing.Point $System_Drawing_Point.X = 12 $System_Drawing_Point.Y = 61 $Input.Location = $System_Drawing_Point $Input.Name = "Input" $System_Drawing_Size = New-Object System.Drawing.Size $System_Drawing_Size.Height = 20 $System_Drawing_Size.Width = 265 $Input.Size = $System_Drawing_Size $Input.TabIndex = 3 $Input.Text = "John Doe" $ADSearchandRestore.Controls.Add($Input) $Exit.DataBindings.DefaultDataSourceUpdateMode = 0 $Exit.FlatStyle = 1 $Exit.Font = New-Object System.Drawing.Font("Microsoft Sans Serif",8.25,1,3,0) $System_Drawing_Point = New-Object System.Drawing.Point $System_Drawing_Point.X = 202 $System_Drawing_Point.Y = 87 $Exit.Location = $System_Drawing_Point $Exit.Name = "Exit" $System_Drawing_Size = New-Object System.Drawing.Size $System_Drawing_Size.Height = 23 $System_Drawing_Size.Width = 75 $Exit.Size = $System_Drawing_Size $Exit.TabIndex = 2 $Exit.Text = "Exit" $Exit.UseVisualStyleBackColor = $True $Exit.add_Click($Exit_OnClick) $ADSearchandRestore.Controls.Add($Exit) $Restore.BackColor = [System.Drawing.Color]::FromArgb(255,255,0,0) $Restore.DataBindings.DefaultDataSourceUpdateMode = 0 $Restore.FlatStyle = 1 $Restore.Font = New-Object System.Drawing.Font("Microsoft Sans Serif",8.25,1,3,0) $Restore.ForeColor = [System.Drawing.Color]::FromArgb(255,0,0,0) $System_Drawing_Point = New-Object System.Drawing.Point $System_Drawing_Point.X = 108 $System_Drawing_Point.Y = 87 $Restore.Location = $System_Drawing_Point $Restore.Name = "Restore" $System_Drawing_Size = New-Object System.Drawing.Size $System_Drawing_Size.Height = 23 $System_Drawing_Size.Width = 75 $Restore.Size = $System_Drawing_Size $Restore.TabIndex = 1 $Restore.Text = "Restore" $Restore.UseVisualStyleBackColor = $False $Restore.add_Click($Restore_OnClick) $ADSearchandRestore.Controls.Add($Restore) $Search.BackColor = [System.Drawing.Color]::FromArgb(255,144,238,144) $Search.DataBindings.DefaultDataSourceUpdateMode = 0 $Search.FlatStyle = 1 $Search.Font = New-Object System.Drawing.Font("Microsoft Sans Serif",8.25,1,3,0) $System_Drawing_Point = New-Object System.Drawing.Point $System_Drawing_Point.X = 12 $System_Drawing_Point.Y = 87 $Search.Location = $System_Drawing_Point $Search.Name = "Search" $System_Drawing_Size = New-Object System.Drawing.Size $System_Drawing_Size.Height = 23 $System_Drawing_Size.Width = 75 $Search.Size = $System_Drawing_Size $Search.TabIndex = 0 $Search.Text = "Search" $Search.UseVisualStyleBackColor = $False $Search.add_Click($Search_OnClick) $ADSearchandRestore.Controls.Add($Search) #endregion Generated Form Code #Save the initial state of the form $InitialFormWindowState = $ADSearchandRestore.WindowState #Init the OnLoad event to correct the initial state of the form $ADSearchandRestore.add_Load($OnLoadForm_StateCorrection) #Show the Form $ADSearchandRestore.ShowDialog()| Out-Null } #End Function #Call the Function GenerateFormthe form loads fine, it allows me to enter a display name and hit search. It even loads the activedirectory module but then throws this error
Get-ADObject : A positional parameter cannot be found that accepts argument 'True'.
At H:zsearch.ps1:45 char:2
+ {Get-ADObject -Filter "displayName -eq '$input.text'" -IncludeDeletedObjects $Re ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [Get-ADObject], ParameterBindingException
+ FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.ActiveDirectory.Management.Commands.GetADObject
Please help! I'm going gray and tearing my hair out