none
Powershell script Active Directory gui RRS feed

  • Question

  • I found the below script and it seems to fit the bill.

    I have been trying to post the question on their site but I recently added a new Gmail account and it thinks it is the primary so long story short I have to fix that before posting on their form.

    I hope one of the folks on here can answer the 2 questions as I bet they are not difficult.

    Thanks

    Two very simple questions I am sure.

    I want to use this as a function in my scripts but how to I use the variable.  So if I select OU Computers OU TopFloor how do I then use that OU selected in my script.

    Second what if I only want to show OU's or only Users in OUs or Computers in OUs is that possible? Really OUs is mainly what I am after if the other 2 are not possible.

    Thanks again.

    # ActiveDirectoryBrowser.Ps1 
    # 
    # This script does show a GUI to browse ActiveDirectory in a Treeview 
    # and Returns the DirectoryEntry Selected for use in PowerShell 
    # or if LoadOnly Parameter is given it just loads the Browse-ActiveDirectory function, 
    # and does set the alias bad, for loading the function for interactive use by dotsourcing the script 
    # 
    # /\/\o\/\/ 2006 
    # 
    # http://mow001.blogspot.com 
    
    
    # the Main function that can be loaded or gets started at the end of the script 
    
    Function Browse-ActiveDirectory { 
     $root=[ADSI]''
    
     # Try to connect to the Domain root 
    
     &{trap {throw "$($_)"};[void]$Root.psbase.get_Name()} 
    
     # Make the form 
     # add a reference to the forms assembly
     [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")
    
     $form = new-object Windows.Forms.form 
     $form.Size = new-object System.Drawing.Size @(800,600) 
     $form.text = "/\/\o\/\/'s PowerShell ActiveDirectory Browser" 
    
     # Make TreeView to hold the Domain Tree 
    
     $TV = new-object windows.forms.TreeView 
     $TV.Location = new-object System.Drawing.Size(10,30) 
     $TV.size = new-object System.Drawing.Size(770,470) 
     $TV.Anchor = "top, left, right" 
    
     # Add the Button to close the form and return the selected DirectoryEntry 
    
     $btnSelect = new-object System.Windows.Forms.Button 
     $btnSelect.text = "Select" 
     $btnSelect.Location = new-object System.Drawing.Size(710,510) 
     $btnSelect.size = new-object System.Drawing.Size(70,30) 
     $btnSelect.Anchor = "Bottom, right" 
    
     # If Select button pressed set return value to Selected DirectoryEntry and close form 
    
     $btnSelect.add_Click({ 
     $script:Return = new-object system.directoryservices.directoryEntry("LDAP://$($TV.SelectedNode.text)") 
     $form.close() 
     }) 
    
     # Add Cancel button 
    
     $btnCancel = new-object System.Windows.Forms.Button 
     $btnCancel.text = "Cancel" 
     $btnCancel.Location = new-object System.Drawing.Size(630,510) 
     $btnCancel.size = new-object System.Drawing.Size(70,30) 
     $btnCancel.Anchor = "Bottom, right" 
    
     # If cancel button is clicked set returnvalue to $False and close form 
    
     $btnCancel.add_Click({$script:Return = $false ; $form.close()}) 
    
     # Create a TreeNode for the domain root found 
    
     $TNRoot = new-object System.Windows.Forms.TreeNode("Root") 
     $TNRoot.Name = $root.name 
     $TNRoot.Text = $root.distinguishedName 
     $TNRoot.tag = "NotEnumerated" 
    
     # First time a Node is Selected, enumerate the Children of the selected DirectoryEntry 
    
     $TV.add_AfterSelect({ 
     if ($this.SelectedNode.tag -eq "NotEnumerated") { 
    
     $de = [ADSI]"LDAP://$($this.SelectedNode.text)"
    
     # Add all Children found as Sub Nodes to the selected TreeNode 
    
     $de.psBase.get_Children() | 
     foreach { 
     $TN = new-object System.Windows.Forms.TreeNode 
     $TN.Name = $_.name 
     $TN.Text = $_.distinguishedName 
     $TN.tag = "NotEnumerated" 
     $this.SelectedNode.Nodes.Add($TN) 
     } 
    
     # Set tag to show this node is already enumerated 
    
     $this.SelectedNode.tag = "Enumerated" 
     } 
     }) 
    
     # Add the RootNode to the Treeview 
    
     [void]$TV.Nodes.Add($TNRoot) 
    
     # Add the Controls to the Form 
    
     $form.Controls.Add($TV) 
     $form.Controls.Add($btnSelect ) 
     $form.Controls.Add($btnCancel ) 
    
     # Set the Select Button as the Default 
    
     $form.AcceptButton = $btnSelect 
    
     $Form.Add_Shown({$form.Activate()}) 
     [void]$form.showdialog() 
    
     # Return selected DirectoryEntry or $false as Cancel Button is Used 
     Return $script:Return 
    } 
    
    # If used as a script start the function 
    
    Set-PSDebug -Strict:$false # Otherwise Checking the Switch parmeter does fail (Bug ?) 
    
    if ($LoadOnly.IsPresent) { 
    
     # Only load the Function for interactive use 
    
     if (-not $MyInvocation.line.StartsWith('. ')) { 
     Write-Warning "LoadOnly Switch is given but you also need to 'dotsource' the script to load the function in the global scope" 
     Write-Host "To Start a script in the global scope (dotsource) put a dot and a space in front of path to the script" 
     Write-Host "If the script is in the current directory this would look like this :" 
     Write-Host ". .\ActiveDirectoryBrowser.Ps1" 
     Write-Host "then :" 
     } 
     Write-Host "The Browse-ActiveDirectory Function is loaded and can be used like this :" 
     Write-Host '$de = Browse-ActiveDirectory' 
     Set-alias bad Browse-ActiveDirectory 
    } 
    Else { 
    
     # start Function 
    
     . Browse-ActiveDirectory $root 
    
    }


    <g class="gr_ gr_47 gr-alert gr_spell ContextualSpelling ins-del multiReplace" data-gr-id="47" id="47">Lishron</g>






    • Edited by Lishron Tuesday, June 16, 2015 2:02 PM
    Tuesday, June 16, 2015 1:56 PM

Answers

  • I ran that form and it was very fast.  You have other issues to fix. 

    If you have a very large domain with many objects at the root then anything will be slow,

    This one only expands one level on command and only displays OUs and not the contents:

    #------------------------------------------------------------------------
    # Source File Information (DO NOT MODIFY)
    # Source ID: 0e3c2774-8550-4dd2-a457-8f55790e998f
    #------------------------------------------------------------------------
    
    <#
        .NOTES
        --------------------------------------------------------------------------------
         Code generated by:  SAPIEN Technologies, Inc., PowerShell Studio 2015 v4.2.85
         Generated on:       6/16/2015 1:49 PM
         Generated by:        
         Organization:        
        --------------------------------------------------------------------------------
        .DESCRIPTION
            GUI script generated by PowerShell Studio 2015
    #>
    #----------------------------------------------
    #region Application Functions
    #----------------------------------------------
    
    function OnApplicationLoad {
    	#Note: This function is not called in Projects
    	#Note: This function runs before the form is created
    	#Note: To get the script directory in the Packager use: Split-Path $hostinvocation.MyCommand.path
    	#Note: To get the console output in the Packager (Windows Mode) use: $ConsoleOutput (Type: System.Collections.ArrayList)
    	#Important: Form controls cannot be accessed in this function
    	#TODO: Add snapins and custom code to validate the application load
    	
    	return $true #return true for success or false for failure
    }
    
    function OnApplicationExit {
    	#Note: This function is not called in Projects
    	#Note: This function runs after the form is closed
    	#TODO: Add custom code to clean up and unload snapins when the application exits
    	
    	$script:ExitCode = 0 #Set the exit code for the Packager
    }
    
    #endregion Application Functions
    
    #----------------------------------------------
    # Generated Form Function
    #----------------------------------------------
    function Call-Demo-ADSITreeView_pff {
    
    	#----------------------------------------------
    	#region Import the Assemblies
    	#----------------------------------------------
    	[void][reflection.assembly]::Load('System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089')
    	#endregion Import Assemblies
    
    	#----------------------------------------------
    	#region Generated Form Objects
    	#----------------------------------------------
    	[System.Windows.Forms.Application]::EnableVisualStyles()
    	$form1 = New-Object 'System.Windows.Forms.Form'
    	$nodepath = New-Object 'System.Windows.Forms.TextBox'
    	$nodename = New-Object 'System.Windows.Forms.TextBox'
    	$treeview1 = New-Object 'System.Windows.Forms.TreeView'
    	$buttonOK = New-Object 'System.Windows.Forms.Button'
    	$InitialFormWindowState = New-Object 'System.Windows.Forms.FormWindowState'
    	#endregion Generated Form Objects
    
    	#----------------------------------------------
    	# User Generated Script
    	#----------------------------------------------
    	
    	
    	function OnApplicationLoad {
    		#Note: This function is not called in Projects
    		#Note: This function runs before the form is created
    		#Note: To get the script directory in the Packager use: Split-Path $hostinvocation.MyCommand.path
    		#Note: To get the console output in the Packager (Windows Mode) use: $ConsoleOutput (Type: System.Collections.ArrayList)
    		#Important: Form controls cannot be accessed in this function
    		#TODO: Add snapins and custom code to validate the application load
    		
    		return $true #return true for success or false for failure
    	}
    	
    	
    	function OnApplicationExit {
    		#Note: This function is not called in Projects
    		#Note: This function runs after the form is closed
    		#TODO: Add custom code to clean up and unload snapins when the application exits
    		
    		$script:ExitCode = 0 #Set the exit code for the Packager
    	}
    	
    	$FormEvent_Load={
    		$rootCN=[adsi]''
    		$nodeName=$rootCN.Name
    		$key="LDAP://$($rootCN.DistinguishedName)"
    		$treeview1.Nodes.Add($key,$nodeName)	
    	}
    	
    	
    	$treeview1_NodeMouseClick=[System.Windows.Forms.TreeNodeMouseClickEventHandler]{
    		$thisOU=[adsi]$_.Node.Name
    		$nodename.Text = $thisOU.Name
    		if( -not $_.Node.Nodes){
    			$nodepath.Text=$thisOU.DistinguishedName
    			$searcher=[adsisearcher]'objectClass=organizationalunit'
    			$searcher.SearchRoot=$_.Node.Name
    			$searcher.SearchScope='OneLevel'
    			$searcher.PropertiesToLoad.Add('name')
    			$OUs=$searcher.Findall()
    			foreach($ou in $OUs){
    				$_.Node.Nodes.Add($ou.Path,$ou.Properties['name'])
    			}
    		}
    		$_.Node.Expand()
    	}
    	
    	function Get-Ous{
    		$sb={
    			function Parse-Tree{
    			    param(
    			        $CurrentNode
    			    )
    			    Write-Host "$($CurrentNode.DistinguishedName)" -fore green
    			    Get-ADOrganizationalUnit -Filter * -SearchScope OneLevel -SearchBase $CurrentNode.distinguishedName |
    			        ForEach-Object{
    			            $node=[pscustomobject]@{        
    			                Name=$_.Name
    			                DistinguishedName=$_.DistinguishedName
    			                Children=@()
    			            }
    			            $CurrentNode.Children+=$node
    			            Parse-Tree -CurrentNode $node
    			        }
    			}
    	
    			$root=(Get-AdDomain).DistinguishedName
    			$node=[pscustomobject]@{        
    			    Name='Root'
    			    DistinguishedName=$root
    			    Children=@()
    			}
    			Import-Module ActiveDirectory
    			Parse-Tree -CurrentNode $node
    			$node
    		}
    	
    	}
    	# --End User Generated Script--
    	#----------------------------------------------
    	#region Generated Events
    	#----------------------------------------------
    	
    	$Form_StateCorrection_Load=
    	{
    		#Correct the initial state of the form to prevent the .Net maximized form issue
    		$form1.WindowState = $InitialFormWindowState
    	}
    	
    	$Form_Cleanup_FormClosed=
    	{
    		#Remove all event handlers from the controls
    		try
    		{
    			$treeview1.remove_NodeMouseClick($treeview1_NodeMouseClick)
    			$form1.remove_Load($FormEvent_Load)
    			$form1.remove_Load($Form_StateCorrection_Load)
    			$form1.remove_FormClosed($Form_Cleanup_FormClosed)
    		}
    		catch [Exception]
    		{ }
    	}
    	#endregion Generated Events
    
    	#----------------------------------------------
    	#region Generated Form Code
    	#----------------------------------------------
    	$form1.SuspendLayout()
    	#
    	# form1
    	#
    	$form1.Controls.Add($nodepath)
    	$form1.Controls.Add($nodename)
    	$form1.Controls.Add($treeview1)
    	$form1.Controls.Add($buttonOK)
    	$form1.AcceptButton = $buttonOK
    	$form1.ClientSize = '622, 389'
    	$form1.FormBorderStyle = 'FixedDialog'
    	$form1.MaximizeBox = $False
    	$form1.MinimizeBox = $False
    	$form1.Name = "form1"
    	$form1.StartPosition = 'CenterScreen'
    	$form1.Text = "Form"
    	$form1.add_Load($FormEvent_Load)
    	#
    	# nodepath
    	#
    	$nodepath.Location = '287, 38'
    	$nodepath.Name = "nodepath"
    	$nodepath.Size = '323, 20'
    	$nodepath.TabIndex = 3
    	#
    	# nodename
    	#
    	$nodename.Location = '287, 12'
    	$nodename.Name = "nodename"
    	$nodename.Size = '323, 20'
    	$nodename.TabIndex = 2
    	#
    	# treeview1
    	#
    	$treeview1.Location = '12, 12'
    	$treeview1.Name = "treeview1"
    	$treeview1.Size = '172, 334'
    	$treeview1.TabIndex = 1
    	$treeview1.add_NodeMouseClick($treeview1_NodeMouseClick)
    	#
    	# buttonOK
    	#
    	$buttonOK.Anchor = 'Bottom, Right'
    	$buttonOK.DialogResult = 'OK'
    	$buttonOK.Location = '535, 354'
    	$buttonOK.Name = "buttonOK"
    	$buttonOK.Size = '75, 23'
    	$buttonOK.TabIndex = 0
    	$buttonOK.Text = "OK"
    	$buttonOK.UseVisualStyleBackColor = $True
    	$form1.ResumeLayout()
    	#endregion Generated Form Code
    
    	#----------------------------------------------
    
    	#Save the initial state of the form
    	$InitialFormWindowState = $form1.WindowState
    	#Init the OnLoad event to correct the initial state of the form
    	$form1.add_Load($Form_StateCorrection_Load)
    	#Clean up the control events
    	$form1.add_FormClosed($Form_Cleanup_FormClosed)
    	#Show the Form
    	return $form1.ShowDialog()
    
    } #End Function
    
    #Call OnApplicationLoad to initialize
    if((OnApplicationLoad) -eq $true)
    {
    	#Call the form
    	Call-Demo-ADSITreeView_pff | Out-Null
    	#Perform cleanup
    	OnApplicationExit
    }
    


    \_(ツ)_/

    • Marked as answer by Lishron Tuesday, June 16, 2015 7:37 PM
    Tuesday, June 16, 2015 5:52 PM

All replies

  • There is no variable.  It is a very old MOW script from PS V1.  Just run it.  It lets you browse AD.


    \_(ツ)_/

    Tuesday, June 16, 2015 2:36 PM
  • MOW?

    Is there a function available you might recommend <g class="gr_ gr_111 gr-alert gr_gramm Grammar multiReplace" data-gr-id="111" id="111">to allow</g> me to select <g class="gr_ gr_70 gr-alert gr_gramm Grammar multiReplace" data-gr-id="70" id="70">a OU</g> from a GUI for my scripts. 

    Up to this <g class="gr_ gr_100 gr-alert gr_gramm Punctuation only-ins replaceWithoutSep" data-gr-id="100" id="100">point</g> I simply copy and paste in my OU path.

    I did search the gallery but did not find one.


    Thanks


    Lishron

    Tuesday, June 16, 2015 4:47 PM
  • PS I tried this one and WOW is it slow.

    Like over a minute to load.

    https://itmicah.wordpress.com/2013/10/29/active-directory-ou-picker-in-powershell/


    <g class="gr_ gr_8 gr-alert gr_spell ContextualSpelling ins-del multiReplace sel" data-gr-id="8" id="8">Lishron</g>


    • Edited by Lishron Tuesday, June 16, 2015 4:49 PM
    Tuesday, June 16, 2015 4:48 PM
  • No one can read what you are posting because you are pasting broken HTML.


    \_(ツ)_/

    Tuesday, June 16, 2015 5:01 PM
  • PS I tried this one and WOW is it slow.

    Like over a minute to load.

    https://itmicah.wordpress.com/2013/10/29/active-directory-ou-picker-in-powershell/


    • Edited by Lishron Tuesday, June 16, 2015 5:31 PM
    Tuesday, June 16, 2015 5:30 PM
  • MOW?

    Is there a function available you might recommend to allow me to select a OU from a GUI for my scripts. 

    Up to this point  I simply copy and paste in my OU path.

    I did search the gallery but did not find one.

    Thanks for the tip about the HTML when i refreshed the page i saw it.  It was from a spellchecker i had installed in chrome 

    Thanks


    Lishron

    Tuesday, June 16, 2015 5:35 PM
  • I ran that form and it was very fast.  You have other issues to fix. 

    If you have a very large domain with many objects at the root then anything will be slow,

    This one only expands one level on command and only displays OUs and not the contents:

    #------------------------------------------------------------------------
    # Source File Information (DO NOT MODIFY)
    # Source ID: 0e3c2774-8550-4dd2-a457-8f55790e998f
    #------------------------------------------------------------------------
    
    <#
        .NOTES
        --------------------------------------------------------------------------------
         Code generated by:  SAPIEN Technologies, Inc., PowerShell Studio 2015 v4.2.85
         Generated on:       6/16/2015 1:49 PM
         Generated by:        
         Organization:        
        --------------------------------------------------------------------------------
        .DESCRIPTION
            GUI script generated by PowerShell Studio 2015
    #>
    #----------------------------------------------
    #region Application Functions
    #----------------------------------------------
    
    function OnApplicationLoad {
    	#Note: This function is not called in Projects
    	#Note: This function runs before the form is created
    	#Note: To get the script directory in the Packager use: Split-Path $hostinvocation.MyCommand.path
    	#Note: To get the console output in the Packager (Windows Mode) use: $ConsoleOutput (Type: System.Collections.ArrayList)
    	#Important: Form controls cannot be accessed in this function
    	#TODO: Add snapins and custom code to validate the application load
    	
    	return $true #return true for success or false for failure
    }
    
    function OnApplicationExit {
    	#Note: This function is not called in Projects
    	#Note: This function runs after the form is closed
    	#TODO: Add custom code to clean up and unload snapins when the application exits
    	
    	$script:ExitCode = 0 #Set the exit code for the Packager
    }
    
    #endregion Application Functions
    
    #----------------------------------------------
    # Generated Form Function
    #----------------------------------------------
    function Call-Demo-ADSITreeView_pff {
    
    	#----------------------------------------------
    	#region Import the Assemblies
    	#----------------------------------------------
    	[void][reflection.assembly]::Load('System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089')
    	#endregion Import Assemblies
    
    	#----------------------------------------------
    	#region Generated Form Objects
    	#----------------------------------------------
    	[System.Windows.Forms.Application]::EnableVisualStyles()
    	$form1 = New-Object 'System.Windows.Forms.Form'
    	$nodepath = New-Object 'System.Windows.Forms.TextBox'
    	$nodename = New-Object 'System.Windows.Forms.TextBox'
    	$treeview1 = New-Object 'System.Windows.Forms.TreeView'
    	$buttonOK = New-Object 'System.Windows.Forms.Button'
    	$InitialFormWindowState = New-Object 'System.Windows.Forms.FormWindowState'
    	#endregion Generated Form Objects
    
    	#----------------------------------------------
    	# User Generated Script
    	#----------------------------------------------
    	
    	
    	function OnApplicationLoad {
    		#Note: This function is not called in Projects
    		#Note: This function runs before the form is created
    		#Note: To get the script directory in the Packager use: Split-Path $hostinvocation.MyCommand.path
    		#Note: To get the console output in the Packager (Windows Mode) use: $ConsoleOutput (Type: System.Collections.ArrayList)
    		#Important: Form controls cannot be accessed in this function
    		#TODO: Add snapins and custom code to validate the application load
    		
    		return $true #return true for success or false for failure
    	}
    	
    	
    	function OnApplicationExit {
    		#Note: This function is not called in Projects
    		#Note: This function runs after the form is closed
    		#TODO: Add custom code to clean up and unload snapins when the application exits
    		
    		$script:ExitCode = 0 #Set the exit code for the Packager
    	}
    	
    	$FormEvent_Load={
    		$rootCN=[adsi]''
    		$nodeName=$rootCN.Name
    		$key="LDAP://$($rootCN.DistinguishedName)"
    		$treeview1.Nodes.Add($key,$nodeName)	
    	}
    	
    	
    	$treeview1_NodeMouseClick=[System.Windows.Forms.TreeNodeMouseClickEventHandler]{
    		$thisOU=[adsi]$_.Node.Name
    		$nodename.Text = $thisOU.Name
    		if( -not $_.Node.Nodes){
    			$nodepath.Text=$thisOU.DistinguishedName
    			$searcher=[adsisearcher]'objectClass=organizationalunit'
    			$searcher.SearchRoot=$_.Node.Name
    			$searcher.SearchScope='OneLevel'
    			$searcher.PropertiesToLoad.Add('name')
    			$OUs=$searcher.Findall()
    			foreach($ou in $OUs){
    				$_.Node.Nodes.Add($ou.Path,$ou.Properties['name'])
    			}
    		}
    		$_.Node.Expand()
    	}
    	
    	function Get-Ous{
    		$sb={
    			function Parse-Tree{
    			    param(
    			        $CurrentNode
    			    )
    			    Write-Host "$($CurrentNode.DistinguishedName)" -fore green
    			    Get-ADOrganizationalUnit -Filter * -SearchScope OneLevel -SearchBase $CurrentNode.distinguishedName |
    			        ForEach-Object{
    			            $node=[pscustomobject]@{        
    			                Name=$_.Name
    			                DistinguishedName=$_.DistinguishedName
    			                Children=@()
    			            }
    			            $CurrentNode.Children+=$node
    			            Parse-Tree -CurrentNode $node
    			        }
    			}
    	
    			$root=(Get-AdDomain).DistinguishedName
    			$node=[pscustomobject]@{        
    			    Name='Root'
    			    DistinguishedName=$root
    			    Children=@()
    			}
    			Import-Module ActiveDirectory
    			Parse-Tree -CurrentNode $node
    			$node
    		}
    	
    	}
    	# --End User Generated Script--
    	#----------------------------------------------
    	#region Generated Events
    	#----------------------------------------------
    	
    	$Form_StateCorrection_Load=
    	{
    		#Correct the initial state of the form to prevent the .Net maximized form issue
    		$form1.WindowState = $InitialFormWindowState
    	}
    	
    	$Form_Cleanup_FormClosed=
    	{
    		#Remove all event handlers from the controls
    		try
    		{
    			$treeview1.remove_NodeMouseClick($treeview1_NodeMouseClick)
    			$form1.remove_Load($FormEvent_Load)
    			$form1.remove_Load($Form_StateCorrection_Load)
    			$form1.remove_FormClosed($Form_Cleanup_FormClosed)
    		}
    		catch [Exception]
    		{ }
    	}
    	#endregion Generated Events
    
    	#----------------------------------------------
    	#region Generated Form Code
    	#----------------------------------------------
    	$form1.SuspendLayout()
    	#
    	# form1
    	#
    	$form1.Controls.Add($nodepath)
    	$form1.Controls.Add($nodename)
    	$form1.Controls.Add($treeview1)
    	$form1.Controls.Add($buttonOK)
    	$form1.AcceptButton = $buttonOK
    	$form1.ClientSize = '622, 389'
    	$form1.FormBorderStyle = 'FixedDialog'
    	$form1.MaximizeBox = $False
    	$form1.MinimizeBox = $False
    	$form1.Name = "form1"
    	$form1.StartPosition = 'CenterScreen'
    	$form1.Text = "Form"
    	$form1.add_Load($FormEvent_Load)
    	#
    	# nodepath
    	#
    	$nodepath.Location = '287, 38'
    	$nodepath.Name = "nodepath"
    	$nodepath.Size = '323, 20'
    	$nodepath.TabIndex = 3
    	#
    	# nodename
    	#
    	$nodename.Location = '287, 12'
    	$nodename.Name = "nodename"
    	$nodename.Size = '323, 20'
    	$nodename.TabIndex = 2
    	#
    	# treeview1
    	#
    	$treeview1.Location = '12, 12'
    	$treeview1.Name = "treeview1"
    	$treeview1.Size = '172, 334'
    	$treeview1.TabIndex = 1
    	$treeview1.add_NodeMouseClick($treeview1_NodeMouseClick)
    	#
    	# buttonOK
    	#
    	$buttonOK.Anchor = 'Bottom, Right'
    	$buttonOK.DialogResult = 'OK'
    	$buttonOK.Location = '535, 354'
    	$buttonOK.Name = "buttonOK"
    	$buttonOK.Size = '75, 23'
    	$buttonOK.TabIndex = 0
    	$buttonOK.Text = "OK"
    	$buttonOK.UseVisualStyleBackColor = $True
    	$form1.ResumeLayout()
    	#endregion Generated Form Code
    
    	#----------------------------------------------
    
    	#Save the initial state of the form
    	$InitialFormWindowState = $form1.WindowState
    	#Init the OnLoad event to correct the initial state of the form
    	$form1.add_Load($Form_StateCorrection_Load)
    	#Clean up the control events
    	$form1.add_FormClosed($Form_Cleanup_FormClosed)
    	#Show the Form
    	return $form1.ShowDialog()
    
    } #End Function
    
    #Call OnApplicationLoad to initialize
    if((OnApplicationLoad) -eq $true)
    {
    	#Call the form
    	Call-Demo-ADSITreeView_pff | Out-Null
    	#Perform cleanup
    	OnApplicationExit
    }
    


    \_(ツ)_/

    • Marked as answer by Lishron Tuesday, June 16, 2015 7:37 PM
    Tuesday, June 16, 2015 5:52 PM
  • Thank you


    Lishron

    Tuesday, June 16, 2015 7:38 PM
  • Hi, i want to use this inside a form, is it possible to search by User Groups ?

    How can i get the result of the function and save in a variable ?

    many thanks.

    Tuesday, February 21, 2017 11:22 PM
  • Ramses (the 147 little kid of the family who can't spell Ramesses)

    You can not piggyback on another users topic.  Please start your own question with an example of your script and your issue.


    \_(ツ)_/

    Tuesday, February 21, 2017 11:31 PM
  • It returns the selected value in: $Script:return.Path
    Friday, June 16, 2017 1:59 PM