Works for me.
What is $input?
$input is a special variable. Perhaps you shouldn't use it.
Get-adobject doesn't work using GUI
Forum rules
Do not post any licensing information in this forum.
Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
Do not post any licensing information in this forum.
Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
Re: Get-adobject doesn't work using GUI
Here it is working for me:
PowerShell Code
Double-click the code block to select all.PS C:scripts> Get-ADObject -Filter "DisplayName -eq '$($test.Name)'" DistinguishedName Name ObjectClass ObjectGUID ----------------- ---- ----------- ---------- CN=Test User01,OU=Admins,... Test User01 user c2977457-41c6-4ba7-9d14-3e.
Re: Get-adobject doesn't work using GUI
$input is the text box where the user enters the name they are searching for. without this the entire form is uselessjvierra wrote:Works for me.
What is $input?
$input is a special variable. Perhaps you shouldn't use it.
Re: Get-adobject doesn't work using GUI
The script, without the variables created by primalforms to identify the various form elements, works fine for me. The thing is this ONLY breaks when I use the powershell code created by primalforms. that's why I'm getting frustrated with the code, it works if I don't use the form but I need to create the form so I can give this to someone else to use without having them enter code or giving them direct access to PS
Re: Get-adobject doesn't work using GUI
Here is what I previously had, this creates a menu in the Powershell window. It works fine, but I have been asked to make it a form rather than "a command line operation"
This works perfectly.
Using the original menu version works, using the primalforms version does not.
This works perfectly.
PowerShell Code
Double-click the code block to select all.Import-Module ActiveDirectory $prompt = @" ************************************************************************************************************************ ** Please select from the options below ** ** ** ** s = Search AD for deleted users ** ** r = Restore user account ** ** x = exit ** ** ** ************************************************************************************************************************ "@ Clear-host Do{ $originalcolor = $host.UI.RawUI.ForegroundColor $host.UI.RawUI.ForegroundColor = "Yellow" $choice = Read-Host -Prompt $prompt $host.UI.RawUI.ForegroundColor = $originalcolor Switch($choice){ s {$user = Read-Host 'Enter the display name to search for' ; Get-ADObject -Filter "displayName -eq '$user'" -IncludeDeletedObjects} r {$user = Read-Host 'Enter the display name to restore' ; Get-ADObject -Filter "displayName -eq '$user'" -IncludeDeletedObjects | Restore-ADObject} x {break} default {write-host "Invalid selection, please try again." -ForegroundColor Red} } }Until($choice -eq "x")I have had to modify the code from this to use the form, that is where it breaks. The code primalforms created does not like either Get-ADObject or the -Filter, it lists both as things it does not understand.
Using the original menu version works, using the primalforms version does not.
Re: Get-adobject doesn't work using GUI
$input is a reserved variable. It cannot be used as a form control name. Use a different name.
Outside of a form or outside of a packaged file $input might work but should not be used.
This could be the source of your problem.
I will try and duplicate you form issue later when I get done with some projects I am in the middle of.
Outside of a form or outside of a packaged file $input might work but should not be used.
This could be the source of your problem.
I will try and duplicate you form issue later when I get done with some projects I am in the middle of.
Re: Get-adobject doesn't work using GUI
Thank you!
I changed $input to $object, and it worked! thank you very much for pointing me in the direction of this, I wasn't aware it was a reserved variable.
I changed $input to $object, and it worked! thank you very much for pointing me in the direction of this, I wasn't aware it was a reserved variable.
Re: Get-adobject doesn't work using GUI
YOu also should not use $object. Try not to use words that are likely to be reserved or that are too general.
Controls should be named by their function. In this case the control should be named something like $DisplayName which tells us its use in the larger scheme of things.
Controls should be named by their function. In this case the control should be named something like $DisplayName which tells us its use in the larger scheme of things.