Hi,
I firstly request your patience and politeness as I haven't used message boards before & also I'm not a super expert at PowerShell. So if I post something wrong, apologies, but please be nice.
I created a form on Powershell Studio 2018.
(I'm using the Quest ActiveRoles Management Shell to work with Active Directory.)
I type in the name of a Active Directory user in a richtextbox and click 'Go' (e.g. Sam)
On the 'Go' button I've added this code:
$username = $richtextbox1.Text
$usernameresults = get-qaduser $username | Select-Object ntaccountname, accountislockedout
In a normal Powershell ISE console, running the second line of the above script replacing $username with an actual name found in Active Directory returns a table in the output section with the headings 'NTAccountName' and 'AccountisLockedOut'.
This displays all users with the name I inputted (e.g. Sam) with the account name and locked status. Similar table below:
NTAccountName AccountIsLockedOut
------------- ------------------
Domain1\SamJohn False
Domain1\SammyJohn True
I put this into a $usernameresults variable in my Sapien Form because I want to push this table into a ListView. Similar to this image:
I experimented with the line:
$listview1.Items.Add($usernameresults)
But obviously as it was an experiment it didn't work.
My question is, how do I get that table above (which is put into variable $usernameresults) into a box in Sapien Powershell so that I can then mouse click which user I want to select and do the rest of the code from there? When I click select the username I want to feed the "NTAccountName" for the rest of my script.
I hope this makes sense... I thought ListView is the way but it may or may not be.
Thanks in advance.
Select-Object output into ListView?
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: Select-Object output into ListView?
Try this to understand how to use a ListView: https://info.sapien.com/index.php/guis/ ... ew-control
To add items use the provided function:
Add-ListViewItem -ListView $listview1 -Items $usernameresults -Group $listview1.Groups[0] -SubItems ntaccountname, accountislockedout
To add items use the provided function:
Add-ListViewItem -ListView $listview1 -Items $usernameresults -Group $listview1.Groups[0] -SubItems ntaccountname, accountislockedout
-
- Posts: 18
- Last visit: Thu Apr 18, 2019 7:07 am
Re: Select-Object output into ListView?
Hi, Thank you for the very quick reply.
I have my ListView set to SmallIcon and checkbox on.
I added the line you mentioned below and it's getting there. I had to remove the
| select-object ntaccountname, accountislockedout
for the listview to display properly.
This is what it looks like (code behind)
It's so very close to what I wanted. I would really like to know how to create two columns "NTaccountname" and "Accountislockedout" populated with the information piped in from $usernameresults (just like in the screenshot of the first post).
The -Subitems ntaccountname, accountislockedout doesn't make a different to the current output in the listview.
I tried reading the link but either I missed it or I don't understand how to do it from reading that page.
This help is very much appreciated.
Thanks!
I have my ListView set to SmallIcon and checkbox on.
I added the line you mentioned below and it's getting there. I had to remove the
| select-object ntaccountname, accountislockedout
for the listview to display properly.
This is what it looks like (code behind)
It's so very close to what I wanted. I would really like to know how to create two columns "NTaccountname" and "Accountislockedout" populated with the information piped in from $usernameresults (just like in the screenshot of the first post).
The -Subitems ntaccountname, accountislockedout doesn't make a different to the current output in the listview.
I tried reading the link but either I missed it or I don't understand how to do it from reading that page.
This help is very much appreciated.
Thanks!
-
- Posts: 18
- Last visit: Thu Apr 18, 2019 7:07 am
Re: Select-Object output into ListView?
Thank you my friend! I got it working exactly how I wanted it by actually spending time reading the spotlight
I will post screenshots and what I did in a bit, in case anyone else needs some assistance...
I will post screenshots and what I did in a bit, in case anyone else needs some assistance...
-
- Posts: 18
- Last visit: Thu Apr 18, 2019 7:07 am
Re: Select-Object output into ListView?
So to conclude this topic, this is what I did to make the above code work.
I read on the spotlight link mentioned above:
"In the Details view the Subitems will be displayed only if Columns are defined."
That was a critical piece I was missing from my form.
So I added 2 columns in Powershell studio, and modified the script line to read:
Add-ListViewItem -ListView $listview1 -Items $usernameresults.ntaccountname -Group $listview1.Groups[0] -SubItems $usernameresults.accountislockedout
I realised that "-Items" appends to the first defined column and "-Subitems" appends to the column after.
Thus resulting in the following:
Thanks for the assistance.
I read on the spotlight link mentioned above:
"In the Details view the Subitems will be displayed only if Columns are defined."
That was a critical piece I was missing from my form.
So I added 2 columns in Powershell studio, and modified the script line to read:
Add-ListViewItem -ListView $listview1 -Items $usernameresults.ntaccountname -Group $listview1.Groups[0] -SubItems $usernameresults.accountislockedout
I realised that "-Items" appends to the first defined column and "-Subitems" appends to the column after.
Thus resulting in the following:
Thanks for the assistance.
-
- Posts: 18
- Last visit: Thu Apr 18, 2019 7:07 am
Re: Select-Object output into ListView?
Hmm,
It seems I spoke to soon. I actually need more assistance.
It seems -Subitems only takes the first result and displays it in the column. It does not take all the rows into account. It only takes the first row and shows the whole column with the first row only.
What I mean by this -
If I add the line like this, so the first column shows the username and second column shows locked out status, it looks like this:
Add-ListViewItem -ListView $listview1 -Items $usernameresults.ntaccountname -Group $listview1.Groups[0] -SubItems $usernameresults.accountislockedout
Looks like everything is working... however, one of those users account is locked so it should return as "True".
How can I confirm this, I swapped -Items with -Subitems so the line now reads:
Add-ListViewItem -ListView $listview1 -Items $usernameresults.accountislockedout -Group $listview1.Groups[0] -SubItems $usernameresults.ntaccountname
As you can see, the first column (-Item) displays each row independently taken from the results and shows a "True" result. But the second column (-Subitems) shows only the first username from the result, copying the 1st line into all the lines in that column.
My question is, how can I get -Subitems to act like -Items? Each row displaying the result and not copying the first row to all rows?
I've read the spotlight many times but I just cant see what I'm doing wrong
After this is solved, my entire script will be complete!
It seems I spoke to soon. I actually need more assistance.
It seems -Subitems only takes the first result and displays it in the column. It does not take all the rows into account. It only takes the first row and shows the whole column with the first row only.
What I mean by this -
If I add the line like this, so the first column shows the username and second column shows locked out status, it looks like this:
Add-ListViewItem -ListView $listview1 -Items $usernameresults.ntaccountname -Group $listview1.Groups[0] -SubItems $usernameresults.accountislockedout
Looks like everything is working... however, one of those users account is locked so it should return as "True".
How can I confirm this, I swapped -Items with -Subitems so the line now reads:
Add-ListViewItem -ListView $listview1 -Items $usernameresults.accountislockedout -Group $listview1.Groups[0] -SubItems $usernameresults.ntaccountname
As you can see, the first column (-Item) displays each row independently taken from the results and shows a "True" result. But the second column (-Subitems) shows only the first username from the result, copying the 1st line into all the lines in that column.
My question is, how can I get -Subitems to act like -Items? Each row displaying the result and not copying the first row to all rows?
I've read the spotlight many times but I just cant see what I'm doing wrong
After this is solved, my entire script will be complete!
Re: Select-Object output into ListView?
This is one reason why I never use the function. It is not well behaved and doesn't work as advertised.
Here is an example of how to use it in a way that works.
Here is an example of how to use it in a way that works.
- Attachments
-
- Test-AddListItems.psf
- (21.99 KiB) Downloaded 161 times
Re: Select-Object output into ListView?
Here is a more complete demo of how to use a ListBox.
- Attachments
-
- Demo-ListViewIcons.psf
- (22.84 KiB) Downloaded 181 times