Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #ERASE ALL THIS AND PUT XAML BELOW between the @" "@
- $inputXML = @"
- <Window x:Class="WpfApplication2.MainWindow"
- xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
- xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
- xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
- xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
- xmlns:local="clr-namespace:WpfApplication2"
- mc:Ignorable="d"
- Title="MainWindow" Height="542.708" Width="725.887">
- <Grid Margin="0,-26,0,0">
- <Grid.RowDefinitions>
- <RowDefinition Height="164*"/>
- <RowDefinition Height="155*"/>
- </Grid.RowDefinitions>
- <Grid.ColumnDefinitions>
- <ColumnDefinition Width="80"/>
- <ColumnDefinition/>
- </Grid.ColumnDefinitions>
- <Image x:Name="image" Grid.Column="1" HorizontalAlignment="Left" Height="100" Margin="528,42,0,0" VerticalAlignment="Top" Width="100" Source="C:\Users\18bmi\Downloads\ERSTA_LOGO_VERTIKAL_CMYK.jpg"/>
- <ComboBox x:Name="comboBox" Grid.ColumnSpan="2" HorizontalAlignment="Left" Margin="37,104,0,0" VerticalAlignment="Top" Width="120" IsEnabled="False"/>
- <TextBox x:Name="textBox" Grid.Column="1" HorizontalAlignment="Left" Height="23" Margin="128,103,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="120" IsEnabled="False"/>
- <TextBox x:Name="textBox1" Grid.Column="1" HorizontalAlignment="Left" Height="23" Margin="285,103,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="120" IsEnabled="False"/>
- <ListView x:Name="listView" HorizontalAlignment="Left" Height="340" Margin="37,162,0,0" Grid.RowSpan="2" VerticalAlignment="Top" Width="1152" Grid.ColumnSpan="2">
- <ListView.View>
- <GridView>
- <GridViewColumn Header="Computer" DisplayMemberBinding ="{Binding Computer}" Width="150"/>
- <GridViewColumn Header="Groupname" DisplayMemberBinding ="{Binding Groupname}" Width="150"/>
- <GridViewColumn Header="Members" DisplayMemberBinding ="{Binding Members}" Width="350"/>
- </GridView>
- </ListView.View>
- </ListView>
- <Button x:Name="button" Content="Go" Grid.Column="1" HorizontalAlignment="Left" Margin="426,103,0,0" VerticalAlignment="Top" Width="75"/>
- <CheckBox x:Name="checkBox" Content="OU" HorizontalAlignment="Left" Margin="37,72,0,0" VerticalAlignment="Top" Grid.ColumnSpan="2"/>
- <CheckBox x:Name="checkBox_Copy" Content="Group" HorizontalAlignment="Left" Margin="128,72,0,0" VerticalAlignment="Top" Grid.Column="1"/>
- <CheckBox x:Name="checkBox_Copy1" Content="Computer" Grid.Column="1" HorizontalAlignment="Left" Margin="285,72,0,0" VerticalAlignment="Top"/>
- </Grid>
- </Window>
- "@
- $inputXML = $inputXML -replace 'mc:Ignorable="d"','' -replace "x:N",'N' -replace '^<Win.*', '<Window'
- [void][System.Reflection.Assembly]::LoadWithPartialName('presentationframework')
- [xml]$XAML = $inputXML
- #Read XAML
- $reader=(New-Object System.Xml.XmlNodeReader $xaml)
- try{$Form=[Windows.Markup.XamlReader]::Load( $reader )}
- catch{Write-Host "Unable to load Windows.Markup.XamlReader. Double-check syntax and ensure .net is installed."}
- #===========================================================================
- # Load XAML Objects In PowerShell
- #===========================================================================
- $xaml.SelectNodes("//*[@Name]") | %{Set-Variable -Name "WPF$($_.Name)" -Value $Form.FindName($_.Name)}
- Function Get-FormVariables{
- if ($global:ReadmeDisplay -ne $true){Write-host "If you need to reference this display again, run Get-FormVariables" -ForegroundColor Yellow;$global:ReadmeDisplay=$true}
- write-host "Found the following interactable elements from our form" -ForegroundColor Cyan
- get-variable WPF*
- }
- Get-FormVariables
- #===========================================================================
- # Actually make the objects work
- #===========================================================================
- #Sample entry of how to add data to a field
- #$vmpicklistView.items.Add([pscustomobject]@{'VMName'=($_).Name;Status=$_.Status;Other="Yes"})
- #===========================================================================
- # Shows the form
- #===========================================================================
- #=============
- #combox
- #===========================================================================
- $OUcombos = Get-content c:\work\listbox\ou.txt
- $OUcombos | ForEach-object {$WPFcomboBox.AddChild($_)}
- #===========================================================================
- # Checkbox
- #===========================================================================
- $WPFcheckbox.Add_Checked({
- $WPFcombobox.IsEnabled=$true
- $WPFcheckbox_copy.IsEnabled=$False
- $WPFcheckbox_copy1.IsEnabled=$False
- })
- $WPFcheckbox_copy.Add_Checked({
- $WPFtextbox.IsEnabled=$true
- $WPFcheckbox.IsEnabled=$False
- $WPFcheckbox_copy1.IsEnabled=$False
- })
- $WPFcheckbox_copy1.Add_Checked({
- $WPFtextbox1.IsEnabled=$true
- $WPFcheckbox_copy.IsEnabled=$False
- $WPFcheckbox.IsEnabled=$False
- })
- $WPFcheckbox.Add_UnChecked({
- $WPFcombobox.IsEnabled=$False
- $WPFcheckbox_copy.IsEnabled=$True
- $WPFcheckbox_copy1.IsEnabled=$True
- })
- $WPFcheckbox_copy.Add_UnChecked({
- $WPFtextbox.IsEnabled=$False
- $WPFcheckbox.IsEnabled=$True
- $WPFcheckbox_copy1.IsEnabled=$True
- })
- $WPFcheckbox_copy1.Add_UnChecked({
- $WPFtextbox1.IsEnabled=$False
- $WPFcheckbox_copy.IsEnabled=$True
- $WPFcheckbox.IsEnabled=$True
- })
- #=========================================================================
- # Function
- #========================================================================
- function Get-LocalGroupMembers
- {
- param(
- [parameter(Mandatory=$true,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true)]
- [Alias("Name")]
- [string]$ComputerName,
- [string]$GroupName = "Administrators"
- )
- begin {}
- process
- {
- # If the account name of the computer object was passed in, it will
- # end with a $. Get rid of it so it doesn't screw up the WMI query.
- $ComputerName = $ComputerName.Replace("`$", '')
- # Initialize an array to hold the results of our query.
- $arr = @()
- # Get hostname of remote system. $computername could reference cluster/alias name. Need real hostname for subsequent WMI query.
- $hostname = (Get-WmiObject -ComputerName $ComputerName -Class Win32_ComputerSystem).Name
- $wmi = Get-WmiObject -ComputerName $ComputerName -Query "SELECT * FROM Win32_GroupUser WHERE GroupComponent=`"Win32_Group.Domain='$Hostname',Name='$GroupName'`""
- # Parse out the username from each result and append it to the array.
- if ($wmi -ne $null)
- {
- foreach ($item in $wmi)
- {
- $data = $item.PartComponent -split "\,"
- $domain = ($data[0] -split "=")[1]
- $name = ($data[1] -split "=")[1]
- $arr += ("$domain\$name").Replace("""","")
- [Array]::Sort($arr)
- }
- }
- if ($arr -ne $null)
- {
- #$hash = @{Computer=$ComputerName;Groupname=$groupname;Members=$arr}
- $WPFlistView.AddChild([pscustomobject]@{'Computer'=$ComputerName;'Groupname'=$groupname;'Members'=$arr})
- }
- }
- end{}
- }
- #=========================================================================
- # Button click
- #========================================================================
- $WPFbutton.Add_Click({
- $WPFlistView.Items.Clear()
- start-sleep -Milliseconds 840
- if ($WPFcheckbox.IsChecked -eq $true) {
- $OU = $WPFcomboBox.Text
- $Computersinou = Get-adcomputer -filter * -searchbase $OU | sort name | select -Expandproperty name
- $rtn = $null
- $computersinou | ForEach-Object {
- $rtn = Test-Connection -CN $_ -Count 1 -BufferSize 16 -Quiet
- IF ($rtn -match ‘True’) {
- $Computername = $_
- Get-LocalGroupMembers -ComputerName $computername -groupname "Administrators"
- Get-LocalGroupMembers -ComputerName $computername -groupname "Administratörer"
- }
- }
- }
- ElseIF ($WPFcheckbox_copy.IsChecked -eq $True){
- $Groupnametext = $WPFtextbox.Text
- $Computersingroup = get-adgroupmember $Groupnametext | sort name | select -expandproperty name
- $rtn1 = $null
- $Computersingroup | ForEach-Object{
- $rtn1 = Test-Connection -CN $_ -Count 1 -BufferSize 16 -Quiet
- IF ($rtn1 -match ‘True’) {
- $Computername2 = $_
- Get-LocalGroupMembers -ComputerName $computername2 -groupname "Administrators"
- Get-LocalGroupMembers -ComputerName $computername2 -groupname "Administratörer"
- }
- }
- }
- ElseIF ($WPFcheckbox_copy1.IsChecked -eq $True){
- $computername = $WPFtextbox1.Text
- get-localgroupmembers -ComputerName $computername -groupname "Administrators"
- get-localgroupmembers -ComputerName $computername -groupname "Administratörer"
- }
- })
- #====================================================================================
- write-host "To show the form, run the following" -ForegroundColor Cyan
- $Form.ShowDialog() | out-null
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement