Author Posts

August 25, 2016 at 1:41 pm

How can I pull, say, the name property to file from 'search-adaccount' as it appears on the object?

Instead of writing 'Aaron' it will write out like cn='Aaron',cn='users',cn='whatever..'

I tried just doing a split/replace but it yields the same results...

Add-Content out.txt (Search-ADAccount -LockedOut) | % {$($_.name.split(",")[0] -replace "cn=","")}

August 25, 2016 at 1:58 pm

I'm trying to add 2 properties to a listbox using:

function Load-ListBox 
	{
	
		Param (
			[ValidateNotNull()]
			[Parameter(Mandatory=$true)]
			[System.Windows.Forms.ListBox]$ListBox,
			[ValidateNotNull()]
			[Parameter(Mandatory=$true)]
			$Items,
		    [Parameter(Mandatory=$false)]
			[string]$DisplayMember,
			[switch]$Append
		)
		
		if(-not $Append)
		{
			$listBox.Items.Clear()	
		}
		
		if($Items -is [System.Windows.Forms.ListBox+ObjectCollection] -or $Items -is [System.Collections.ICollection])
		{
			$listBox.Items.AddRange($Items)
		}
		elseif ($Items -is [System.Collections.IEnumerable])
		{
			$listBox.BeginUpdate()
			foreach($obj in $Items)
			{
				$listBox.Items.Add($obj)
			}
			$listBox.EndUpdate()
		}
		else
		{
			$listBox.Items.Add($Items)	
		}
	
		$listBox.DisplayMember = $DisplayMember	
	}


$xyz = (Search-ADAccount -LockedOut) | % {"$($_.name), $($_.samaccountname)"}
Load-ListBox $LockedList $xyz

its loading the objects in the list box as

[ ] cn=aaron, cn=users, cn=amunson, cn=users

when i want it to look like..

[ ] Aaron, amunson

August 25, 2016 at 1:58 pm

Use the name? The distinguishename is cn=.. why are you trying to split the name property for characters it doesn't include?

(Search-ADAccount -LockedOut | select -First 5).name |tee lockedout.txt

August 25, 2016 at 2:06 pm

Why not do something like this:

Search-ADAccount -LockedOut -SearchBase "OU=xxx,OU=xx,OU=xxx,OU=xxx,DC=xxx,DC=com" | select name | Out-File C:\Test\ADlockout.txt

August 25, 2016 at 2:16 pm

You're going to have a really difficult time building gui's before learning powershell. Practice getting the results you want in the shell first.

$xyz = Search-ADAccount -LockedOut | select -First 5 | % { $_.name + ' —– ' + $_.samaccountname }
Load-ListBox $listbox1 $xyz

August 25, 2016 at 2:23 pm

I agree with Dan. Learn and understand PowerShell first before moving on.

August 25, 2016 at 3:09 pm

Well looks like I did have it all along...

		$xyz = (Search-ADAccount -LockedOut) | % {"$($_.name), $($_.samaccountname)"}
		Load-ListBox $LockedList $xyz

This worked, but only after closing/reopening my PS window

August 25, 2016 at 3:09 pm

Note: there are some people that will put you on their kill list for using % in script:D

August 25, 2016 at 9:03 pm

Add-KillList -Name ertuu85

🙂

August 25, 2016 at 10:44 pm

😀 using it twice moves you to the top of the list.