Get-adobject doesn't work using GUI

Ask your PowerShell-related questions, including questions on cmdlet development!
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.
This topic is 10 years and 1 month old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Get-adobject doesn't work using GUI

Post by jvierra »

Works for me.

What is $input?

$input is a special variable. Perhaps you shouldn't use it.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Get-adobject doesn't work using GUI

Post by jvierra »

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.
User avatar
daviesg6
Posts: 49
Last visit: Tue Nov 25, 2014 1:23 pm

Re: Get-adobject doesn't work using GUI

Post by daviesg6 »

jvierra wrote:Works for me.

What is $input?

$input is a special variable. Perhaps you shouldn't use it.
$input is the text box where the user enters the name they are searching for. without this the entire form is useless
User avatar
daviesg6
Posts: 49
Last visit: Tue Nov 25, 2014 1:23 pm

Re: Get-adobject doesn't work using GUI

Post by daviesg6 »

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
User avatar
daviesg6
Posts: 49
Last visit: Tue Nov 25, 2014 1:23 pm

Re: Get-adobject doesn't work using GUI

Post by daviesg6 »

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.
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.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Get-adobject doesn't work using GUI

Post by jvierra »

$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.
User avatar
daviesg6
Posts: 49
Last visit: Tue Nov 25, 2014 1:23 pm

Re: Get-adobject doesn't work using GUI

Post by daviesg6 »

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.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Get-adobject doesn't work using GUI

Post by jvierra »

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.
This topic is 10 years and 1 month old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked