Hi everyone,
I’m brand new to PowerShell Universal. I’m not a Powershell expert, but i’ve already written various PowerShell scripts, but I’m looking for a way to make them available via a website, so I’m currently testing PowerShell Universal.
I’ve created a first app that extracts all deactivated user accounts from Active Directory. Now, using the export function, I can either export all or, if I set a filter on a column, only the current view. What I can’t do is export only selected rows.
How can i do that?
Someone has already asked this question here, but there’s no answer.
https://forums.ironmansoftware.com/t/example-of-exporting-selected-rows-of-a-new-udtable-using-the-onexport-parameter/12203
In general, I’m still missing some understandable example code from practice.
New-UDApp -Content {
$Data = @()
$Data.Clear()
$SearchBase0 = "OU=ABC,OU=ABC,DC=DOMAIN,DC=LOCAL"
$OU = "USER"
$Filter = @('MYFILTER','MYFILTER2','MYFILTER3')
$OUs = Get-ADOrganizationalUnit -SearchBase $SearchBase0 -SearchScope OneLevel -Filter * | Where-Object {$_.Name -notin $Filter} | Select-Object Name
foreach ($item in $OUs){
$Amt = $item.Name
$SearchBase1 = "OU="+$OU+",OU="+$Amt+",OU=ABC,OU=ABC,DC=DOMAIN,DC=LOCAL"
if ($Amt -like "EGAL") {
$Users = Get-ADUser -SearchBase $SearchBase1 -SearchScope Subtree -Filter * -Properties Surname, GivenName, SamAccountName, Department, Enabled, DistinguishedName | Where-Object {$_.DistinguishedName -notlike $Filter -and ($_.Enabled -eq $false) } | Select-Object Surname, GivenName, SamAccountName, Department
$Data = $Data +$Users
} else {
$Users = Get-ADUser -SearchBase $SearchBase1 -SearchScope OneLevel -Filter * -Properties Surname, GivenName, SamAccountName, Department, Enabled, DistinguishedName | Where-Object {$_.DistinguishedName -notlike $Filter -and ($_.Enabled -eq $false) } | Select-Object Surname, GivenName, SamAccountName, Department
$Data = $Data +$Users
}
}
$Columns = @(
New-UDTableColumn -Property Surname -Title "Vorname" -ShowFilter -IncludeInExport
New-UDTableColumn -Property GivenName -Title "Nachname" -ShowFilter -IncludeInExport
New-UDTableColumn -Property SamAccountName -Title "Anmeldekürzel" -ShowFilter -IncludeInExport
New-UDTableColumn -Property Department -Title "Amt" -ShowFilter -IncludeInExport -DefaultSortColumn
)
New-UDTable -Id 'table1' -Data $Data -Columns $Columns -ShowFilter -ShowSort -ShowPagination -ShowSelection -PageSize 100 -ShowExport
}
Product: PowerShell Universal
Version: 5.5.2