xaml.ps1 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. function Show-XAMLWindow{
  2. [CmdletBinding(
  3. SupportsShouldProcess = $false,
  4. ConfirmImpact = "none",
  5. DefaultParameterSetName = ""
  6. )]
  7. param
  8. (
  9. [Parameter(
  10. HelpMessage = "Enter tbind xaml @`...`@ to load.",
  11. Position = 0,
  12. Mandatory = $true,
  13. ValueFromPipeline = $true,
  14. ValueFromPipelineByPropertyName = $true
  15. )]
  16. [ValidateNotNullOrEmpty()]
  17. [string]
  18. $xaml,
  19. [Alias("PassThru")]
  20. [switch]
  21. $PassThrough
  22. )
  23. begin
  24. {
  25. try
  26. {
  27. Add-Type -AssemblyName presentationframework
  28. }
  29. catch
  30. {
  31. }
  32. try
  33. {
  34. [xml]$xaml = $xaml
  35. }
  36. catch
  37. {
  38. }
  39. $reader=(New-Object System.Xml.XmlNodeReader $xaml)
  40. $Form=[Windows.Markup.XamlReader]::Load( $reader )
  41. #Setting al the fields to varialbe
  42. $cbCompanys = $Form.FindName("cbCompanys")
  43. $chkbMultiSelect = $Form.FindName("chkbMultiSelect")
  44. $dgUsers = $Form.FindName("dgUsers")
  45. $chkbBackupFiles = $Form.FindName("chkbBackupFiles")
  46. $chkbBackupMail = $Form.FindName("chkbBackupMail")
  47. $chkblocation = $Form.FindName("chkblocation")
  48. $btnSend = $Form.FindName("btnSend")
  49. }
  50. process
  51. {
  52. # Form setup
  53. #$Form.Background = $Global:BackColor
  54. # for now disable the multiselect button
  55. $chkbMultiSelect.IsEnabled = $false
  56. # Add scripts to Company Combobox
  57. #foreach ($Company in ($Global:Companys | sort Name)) {
  58. # [void] $cbCompanys.Items.Add($Company.Name)
  59. #}
  60. [void] $cbCompanys.Items.Add("A")
  61. [void] $cbCompanys.Items.Add("B")
  62. # Add on checked to CheckBox Multiselect
  63. $chkbMultiSelect.Add_Checked({
  64. $dgUsers.SelectionMode = "Extended"
  65. })
  66. # Add on UnChecked to CheckBox Multiselect
  67. $chkbMultiSelect.Add_UnChecked({
  68. $dgUsers.SelectionMode = "Single"
  69. })
  70. # Add onchange to Company Combobox
  71. $cbCompanys_Add_SelectionChanged = {
  72. # Disable User Combobox
  73. $cbCompanys.IsEnabled = $False
  74. # Clear the Users Combobox
  75. $dgUsers.Clear()
  76. # Get all users of company
  77. #$CompUsers = Get-CompanyUser -Company $cbCompanys.SelectedItem | select DisplayName, UserPrincipalName, SamAccountName | sort DisplayName
  78. $CompUsers =
  79. @(
  80. [pscustomobject]@{ DisplayName="Andy"; UserPrincipalName="Andy P"; SamAccountName="Andy S";}
  81. [pscustomobject]@{ DisplayName="Bob"; UserPrincipalName="Bob P"; SamAccountName="Bob S"; }
  82. [pscustomobject]@{ DisplayName="Casey"; UserPrincipalName="Casey P"; SamAccountName="Casey S"; }
  83. )
  84. # Add property for checkbox
  85. $CompUsers | ForEach-Object {
  86. $_ | Add-Member -MemberType NoteProperty -Name IsChecked -Value $False -TypeName System.Boolean;
  87. }
  88. # Add users to DataGrid
  89. $dgUsers.ItemsSource = $CompUsers
  90. # Allow sorting on all columns
  91. $dgUsers.Columns | ForEach-Object {
  92. $_.CanUserSort = $True
  93. $_.IsReadOnly = $True
  94. }
  95. # Set Columns ReadOnly of not
  96. $dgUsers.Columns[0].IsReadOnly = $False
  97. # Enable User Combobox
  98. $cbCompanys.IsEnabled = $True
  99. }
  100. # Add selectionchanged function to Combobox
  101. $cbCompanys.Add_SelectionChanged($cbCompanys_Add_SelectionChanged)
  102. # Set action to button
  103. $btnSend.Add_Click({
  104. # Get selected items
  105. $SelCompany = $cbCompanys.SelectedItem
  106. # Checking if all fiels contain value
  107. if (!($SelCompany)) {
  108. EmptyFormField -Field "Company"
  109. } else {
  110. write-host "----"
  111. $dgUsers.ItemsSource | Where-Object {$_.IsChecked -eq $True} | ForEach-Object {
  112. write-host $_
  113. }
  114. }
  115. })
  116. $Form.ShowDialog() | out-null
  117. }
  118. end
  119. {
  120. return $dgUsers.ItemsSource | Where-Object {$_.IsChecked -eq $True}
  121. }
  122. }
  123. $xaml =@'
  124. <Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  125. xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  126. x:Name="Window_GuiManagement" Title="Remove Company User" WindowStartupLocation = "CenterScreen"
  127. Width = "587.307" Height = "540.023" Visibility="Visible" WindowStyle="ToolWindow" ResizeMode="NoResize" Topmost="True">
  128. <Grid>
  129. <Label x:Name="lblCompany" Content="Company:" HorizontalAlignment="Left" Margin="11,10,0,0" Height="26" VerticalAlignment="Top"/>
  130. <ComboBox x:Name="cbCompanys" Margin="10,36,10,0" VerticalAlignment="Top"/>
  131. <Label x:Name="lbluser" Content="User:" HorizontalAlignment="Left" Margin="11,63,0,0" VerticalAlignment="Top"/>
  132. <CheckBox x:Name="chkbMultiSelect" Content="MultiSelect" Margin="481,69,10,0" VerticalAlignment="Top" Width="90"/>
  133. <DataGrid x:Name="dgUsers" Margin="11,94,10,0" VerticalAlignment="Top" Height="299" SelectionMode="Single" AlternationCount="1"
  134. AutoGenerateColumns="false">
  135. <DataGrid.Columns>
  136. <DataGridCheckBoxColumn Binding="{Binding Path=IsChecked,UpdateSourceTrigger=PropertyChanged}" ClipboardContentBinding="{x:Null}" CanUserSort="False" CanUserResize="False" IsReadOnly="False"
  137. Header="Check"/>
  138. <DataGridTextColumn Binding="{Binding Path=DisplayName}" ClipboardContentBinding="{x:Null}" CanUserSort="False" CanUserResize="False" IsReadOnly="True"
  139. Header="DisplayName"/>
  140. <DataGridTextColumn Binding="{Binding Path=UserPrincipalName}" ClipboardContentBinding="{x:Null}" CanUserSort="False" CanUserResize="False" IsReadOnly="True"
  141. Header="UserPrincipalName"/>
  142. <DataGridTextColumn Binding="{Binding Path=SamAccountName}" ClipboardContentBinding="{x:Null}" CanUserSort="False" CanUserResize="False" IsReadOnly="True"
  143. Header="SamAccountName"/>
  144. </DataGrid.Columns>
  145. </DataGrid>
  146. <CheckBox x:Name="chkbBackupFiles" Content="Backup Files" HorizontalAlignment="Left" Margin="11,398,0,0" VerticalAlignment="Top" IsChecked="True"/>
  147. <CheckBox x:Name="chkbmail" Content="Backup Mail" HorizontalAlignment="Left" Margin="11,418,0,0" VerticalAlignment="Top" IsChecked="True"/>
  148. <CheckBox x:Name="chkblocation" Content="Open backup location" HorizontalAlignment="Left" Margin="11,438,0,0" VerticalAlignment="Top" IsChecked="True"/>
  149. <Button x:Name="btnSend" Content="Send" Margin="491,469,10,0" VerticalAlignment="Top"/>
  150. <CheckBox x:Name="chkblocation_Copy" Content="Open backup location" HorizontalAlignment="Left" Margin="11,438,0,0" VerticalAlignment="Top" IsChecked="True"/>
  151. </Grid>
  152. </Window>
  153. '@
  154. $WPFresult = Show-XAMLWindow -xaml $xaml
  155. $WPFresult