Greetings,
I have a line of code that goes something like:
$search = new-object System.directoryservices.directorysearcher
When I use the debugger and go through my code line by line, I get to this line and press F11 and it just hangs.
Any ideas why?
Thanks
David
debugging hang on AD directory seacher
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: debugging hang on AD directory seacher
Doesn't happen for me.
Here is how we usually do this
Here is how we usually do this
Code: Select all
$filter = '(objectclass=computer)'
$searcher = [adsisearcher]$filter
$searcher.FindAll()
Re: debugging hang on AD directory seacher
Yeh - its strange.
If I just highlight the code and select 'run selection in console' it works fine.
If I compile it into an exe and run it it doesnt work and neither does debugging.
If I just highlight the code and select 'run selection in console' it works fine.
If I compile it into an exe and run it it doesnt work and neither does debugging.
Re: debugging hang on AD directory seacher
If it works in the console then you need to contact Sapien support for assistance with this. I cannot reproduce your issue with the latest version of PSS.
Re: debugging hang on AD directory seacher
Looks like support cant work it out either.
Must be some weird group policy hardening setting.
I would have thought that good old adsisearcher was so benign...
Anyways - I've rewritten the AD bit to use adfind (from joeware) and all is well..
Must be some weird group policy hardening setting.
I would have thought that good old adsisearcher was so benign...
Anyways - I've rewritten the AD bit to use adfind (from joeware) and all is well..
Re: debugging hang on AD directory seacher
There is no GP setting that can do this. It is more likely that your workstation is not joined correctly to the domain or that you have a damaged Net Framework installation.
I have used this code on Windows from XP to the current versions under PS2 through PS5 with WinForms. It has never hung. I can also run it under PSS in the debugger with no issues. If the domain cannot be reached then the line will time out and throw an exception.
I can reproduce this but only in the debugger. Due to how debuggers work this is code that will hang when a breakpoint is set on the either of the two lines noted. Just don't try to breakpoint in this location and the code work fine. These lines work in any PS forms script with no issue.
This is not about PSS but is how the Windows debugger works when in a single threaded environment.
I have used this code on Windows from XP to the current versions under PS2 through PS5 with WinForms. It has never hung. I can also run it under PSS in the debugger with no issues. If the domain cannot be reached then the line will time out and throw an exception.
I can reproduce this but only in the debugger. Due to how debuggers work this is code that will hang when a breakpoint is set on the either of the two lines noted. Just don't try to breakpoint in this location and the code work fine. These lines work in any PS forms script with no issue.
Code: Select all
Add-Type -AssemblyName System.Windows.Forms
$form = New-Object System.Windows.Forms.Form
$button = New-Object System.Windows.Forms.Button
$form.Controls.Add($button)
$form.StartPosition = 'CenterScreen'
$form.Text = 'Basic Form Demo'
$button.Text = 'Run ADSI'
$button.add_Click({
Try{
$filter = '(objectclass=computer)'
# a breakpoint on either of the following two lines will
# cause the code to hang in the debugger.
$searcher = [adsisearcher]$filter
$searcher.FindAll()
}
Catch{
[System.Windows.Forms.MessageBox]::Show($_)
}
})
$form.ShowDialog()
Re: debugging hang on AD directory seacher
The exact same code in a PSF does not hang in the debugger. This is likely due to setting up the form more completely so that it is aware of the forms "state".
$form1.add_Load($Form_StateCorrection_Load)
The attached PSF does not hang in the debugger.
$form1.add_Load($Form_StateCorrection_Load)
The attached PSF does not hang in the debugger.
- Attachments
-
- Test-ADSIHanger.psf
- (23.19 KiB) Downloaded 108 times
Re: debugging hang on AD directory seacher
Yes. Adding the form state correction code allows the code to work correctly in the debugger.
Code: Select all
Add-Type -AssemblyName System.Windows.Forms
$form = New-Object System.Windows.Forms.Form
$button = New-Object System.Windows.Forms.Button
$InitialFormWindowState = New-Object System.Windows.Forms.FormWindowState
$Form_StateCorrection_Load = {
#Correct the initial state of the form to prevent the .Net maximized form issue
$form.WindowState = $InitialFormWindowState
}
$form.Controls.Add($button)
$form.StartPosition = 'CenterScreen'
$form.Text = 'Basic Form Demo'
$button.Text = 'Run ADSI'
$button.add_Click({
Try{
$filter = '(objectclass=computer)'
# a breakpoint on either of the following two lines will
# cause the code to hang in the debugger.
$searcher = [adsisearcher]$filter
$searcher.FindAll()
}
Catch{
[System.Windows.Forms.MessageBox]::Show($_)
}
})
$InitialFormWindowState = $form.WindowState
$form.add_Load($Form_StateCorrection_Load)
$form.ShowDialog()
- Attachments
-
- Test-ADSI.ps1
- (978 Bytes) Downloaded 115 times