Quantcast
Channel: The Official Scripting Guys Forum! forum
Viewing all articles
Browse latest Browse all 15028

PowerShell WPF GUI - looping through datagrid

$
0
0

Hello,

I have a PowerShell script I am writing using a WPF user interface.  The scripts pulls up a window with options to import a csv file with active directory information (mail and mailnickname), along with an added "permissions" column into a wpf datagrid.

I am unable to figure out how to loop through the items in the datagrid as I normally would with an array in PS.

Below is the code for the form and import function.  I would like a function for my "Start" button that cycles through each row and checks to see if a single user has permissions (using get-mailboxpermission) to the account listed in the row.

function global:Generate-AllPermsForm
{
[xml]$GetAllPermsxaml = 
@"<Window 
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="Get All Permissions" Height="600" Width="650" Foreground="Black" BorderBrush="White"><Window.Background><LinearGradientBrush EndPoint="0.5,1" MappingMode="RelativeToBoundingBox" StartPoint="0.5,0"><GradientStop Color="Black" Offset="0.678"/><GradientStop Color="#FF00B9FF" Offset="0.045"/><GradientStop Color="#FF03284D" Offset="0.269"/></LinearGradientBrush></Window.Background><Grid><TextBox x:Name="addPermscsvPath" HorizontalAlignment="Left" Height="23" Margin="10,107,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="413" BorderThickness="1,1,2,2" IsEnabled="False" Text="Browse for CSv file" AllowDrop="True"/><Button x:Name="addPermsBrowseBtn" Content="Browse..." HorizontalAlignment="Left" Margin="10,131,0,0" VerticalAlignment="Top" Width="69" ToolTip="Browse for CSV file (AD dump)" Background="{DynamicResource {x:Static SystemColors.GradientActiveCaptionBrushKey}}" Height="22" BorderBrush="{x:Null}" Cursor="Hand" Focusable="False"/><Button x:Name="addPermsImportBtn" Content="Import" HorizontalAlignment="Left" Margin="84,131,0,0" VerticalAlignment="Top" Width="339" Height="22" ToolTip="Click to import selected CSV file" Background="#FFF9EE0A" BorderBrush="{x:Null}" Cursor="Hand" Focusable="False"/><DataGrid x:Name="addPermsDataGrid" HorizontalAlignment="Left" Height="380" Margin="10,180,0,0" VerticalAlignment="Top" Width="622" BorderThickness="1" BorderBrush="#FF040608" Background="#FFF0F0F0"/><Button x:Name="addPermsStartBtn" Content="Start" HorizontalAlignment="Left" Margin="428,107,0,0" VerticalAlignment="Top" Width="204" Height="46" ToolTip="Begin processing data from imported CSV" FontWeight="Bold" FontSize="22" Background="#FF17EA17" BorderBrush="{x:Null}" Cursor="Hand" Focusable="False"/><ProgressBar HorizontalAlignment="Left" Height="17" Margin="10,158,0,0" VerticalAlignment="Top" Width="622"/><Label Content="OFFICE 365 POWERSHELL INTERFACE" HorizontalAlignment="Center" Margin="0,10,0,0" VerticalAlignment="Top" Width="353" Height="43" FontFamily="Franklin Gothic Demi Cond" FontSize="20" Foreground="#FFFDFDFD"><Label.Effect><DropShadowEffect BlurRadius="7"/></Label.Effect></Label></Grid></Window>"@

$GetPermsreader=(New-Object System.Xml.XmlNodeReader $GetAllPermsxaml)
$GetAllPermsWindow=[Windows.Markup.XamlReader]::Load( $GetPermsreader )

#textBox
$CSVPathTxtbox = $GetAllPermsWindow.findname("addPermscsvPath")

#datagrid
$addPermsOutData = $GetAllPermsWindow.findname("addPermsDataGrid")

#buttons
$PermsBrowseBtn = $GetAllPermsWindow.findname("addPermsBrowseBtn")
$PermsBrowseBtn.Add_Click({get-csv})

$PermsImportBtn = $GetAllPermsWindow.findname("addPermsImportBtn")
$PermsImportBtn.Add_Click({import-csvfile})

$PermsStartBtn = $GetAllPermsWindow.findname("addPermsStartBtn")
$PermsStartBtn.Add_Click({get-allpermissions})

$GetAllPermsWindow.showDialog() | Out-Null
}

function global:Import-CSVFile
{

    $data = New-Object System.Collections.ArrayList
    $userInfo = import-csv $CSVPathTxtbox.Text | select mail, mailNickname, Permissions
    $data.AddRange($userInfo)
    $addpermsOutData.itemssource = $data
    $addpermsOutData.alternatingrowbackground = "whitesmoke"
}
Thank you for your help!

Viewing all articles
Browse latest Browse all 15028

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>