No Results from AD Query

This forum can be browsed by the general public. Posting is limited to current SAPIEN license holders with active maintenance and does not offer a response time guarantee.
Forum rules
DO NOT POST LICENSE NUMBERS, ACTIVATION KEYS OR ANY OTHER LICENSING INFORMATION IN THIS FORUM.
Only the original author and our tech personnel can reply to a topic that is created in this forum. If you find a topic that relates to an issue you are having, please create a new topic and reference the other in your post.

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 5 years and 7 months 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.
User avatar
mqh77777
Posts: 252
Last visit: Mon Feb 26, 2024 10:07 am
Has voted: 1 time

No Results from AD Query

Post by mqh77777 »

PowerShell Studio 2018 v5.5.153
32 or 64 bit version of product: 64
Operating system: Win 10
32 or 64 bit OS: 64

From within PowerShell ISE the following code works.

Code: Select all

$GetName = Read-Host "Enter a serial number to search for"
$Value = "*$GetName*"
Get-ADComputer -Filter{ name -like $Value} -Properties * | Select-Object name, lastlogondate
The output shows all machines that share a partial name. i.e. HR- when I run this from within PowerShell Studio I get no results.

I have this in my script:

Code: Select all

$buttonSearch_Click={
	$statusbar1.text = 'Searching AD for partial machine name, please wait...'
	$richtextbox_Output.Clear()
	$richtextbox_Output.SelectionColor = 'Blue'
	$GetName = $PCNameBox.Text
	$Value = "*$GetName*"
	
	if ($GetName -eq "")
	{
		$richtextbox_Output.AppendText("You did not specify a PC name.  No action taken.")
	}
	
	ELSE
	{
		$Results1 = Get-ADComputer -Filter { name -like $Value } -Properties * | Select-Object Name, LastLogonDate 
		$richtextbox_Output.Text($Results1)
	}
	
}
Why would it find nothing?
User avatar
mqh77777
Posts: 252
Last visit: Mon Feb 26, 2024 10:07 am
Has voted: 1 time

Re: No Results from AD Query

Post by mqh77777 »

Yes, I've tried Append.Text on my output and that too returns no results.
User avatar
Alexander Riedel
Posts: 8479
Last visit: Thu Mar 28, 2024 9:29 am
Answers: 19
Been upvoted: 37 times

Re: No Results from AD Query

Post by Alexander Riedel »

Are you running this elevated? ISE is usually elevated. Correct platform?
Alexander Riedel
SAPIEN Technologies, Inc.
User avatar
mqh77777
Posts: 252
Last visit: Mon Feb 26, 2024 10:07 am
Has voted: 1 time

Re: No Results from AD Query

Post by mqh77777 »

Yes, I am running this as Administrator. What is funny is this: In ISE if I search for HVP it returns 3 computers that have HVP in their name. But when run from PowerShell Studio it returns nothing when I enter HVP. if I enter the full name of a machine then it does return that 1 machine. How do I make this mimic what ISE returns?
User avatar
mqh77777
Posts: 252
Last visit: Mon Feb 26, 2024 10:07 am
Has voted: 1 time

Re: No Results from AD Query

Post by mqh77777 »

Fixed !!!! $Results1 = Get-ADComputer -Filter { name -like $Value } -Properties * | Select-Object Name, LastLogonDate | Out-String
User avatar
Alexander Riedel
Posts: 8479
Last visit: Thu Mar 28, 2024 9:29 am
Answers: 19
Been upvoted: 37 times

Re: No Results from AD Query

Post by Alexander Riedel »

I was about to say ... :D
Alexander Riedel
SAPIEN Technologies, Inc.
This topic is 5 years and 7 months 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.