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=","")}
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
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
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
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
I agree with Dan. Learn and understand PowerShell first before moving on.
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
Note: there are some people that will put you on their kill list for using % in script:D
Add-KillList -Name ertuu85

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