Advertisement
Guest User

Getlocaladmin

a guest
Oct 11th, 2016
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. #ERASE ALL THIS AND PUT XAML BELOW between the @" "@
  3. $inputXML = @"
  4. <Window x:Class="WpfApplication2.MainWindow"
  5.        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  6.        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  7.        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
  8.        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
  9.        xmlns:local="clr-namespace:WpfApplication2"
  10.        mc:Ignorable="d"
  11.        Title="MainWindow" Height="542.708" Width="725.887">
  12.    <Grid Margin="0,-26,0,0">
  13.        <Grid.RowDefinitions>
  14.            <RowDefinition Height="164*"/>
  15.            <RowDefinition Height="155*"/>
  16.        </Grid.RowDefinitions>
  17.        <Grid.ColumnDefinitions>
  18.            <ColumnDefinition Width="80"/>
  19.            <ColumnDefinition/>
  20.        </Grid.ColumnDefinitions>
  21.        <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"/>
  22.        <ComboBox x:Name="comboBox" Grid.ColumnSpan="2" HorizontalAlignment="Left" Margin="37,104,0,0" VerticalAlignment="Top" Width="120" IsEnabled="False"/>
  23.        <TextBox x:Name="textBox" Grid.Column="1" HorizontalAlignment="Left" Height="23" Margin="128,103,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="120" IsEnabled="False"/>
  24.        <TextBox x:Name="textBox1" Grid.Column="1" HorizontalAlignment="Left" Height="23" Margin="285,103,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="120" IsEnabled="False"/>
  25.        <ListView x:Name="listView" HorizontalAlignment="Left" Height="340" Margin="37,162,0,0" Grid.RowSpan="2" VerticalAlignment="Top" Width="1152" Grid.ColumnSpan="2">
  26.            <ListView.View>
  27.                <GridView>
  28.                    <GridViewColumn Header="Computer" DisplayMemberBinding ="{Binding Computer}" Width="150"/>
  29.                    <GridViewColumn Header="Groupname" DisplayMemberBinding ="{Binding Groupname}" Width="150"/>
  30.                    <GridViewColumn Header="Members" DisplayMemberBinding ="{Binding Members}" Width="350"/>
  31.                </GridView>
  32.            </ListView.View>
  33.        </ListView>
  34.        <Button x:Name="button" Content="Go" Grid.Column="1" HorizontalAlignment="Left" Margin="426,103,0,0" VerticalAlignment="Top" Width="75"/>
  35.        <CheckBox x:Name="checkBox" Content="OU" HorizontalAlignment="Left" Margin="37,72,0,0" VerticalAlignment="Top" Grid.ColumnSpan="2"/>
  36.        <CheckBox x:Name="checkBox_Copy" Content="Group" HorizontalAlignment="Left" Margin="128,72,0,0" VerticalAlignment="Top" Grid.Column="1"/>
  37.        <CheckBox x:Name="checkBox_Copy1" Content="Computer" Grid.Column="1" HorizontalAlignment="Left" Margin="285,72,0,0" VerticalAlignment="Top"/>
  38.  
  39.    </Grid>
  40. </Window>
  41.  
  42.  
  43. "@      
  44.  
  45. $inputXML = $inputXML -replace 'mc:Ignorable="d"','' -replace "x:N",'N'  -replace '^<Win.*', '<Window'
  46.  
  47. [void][System.Reflection.Assembly]::LoadWithPartialName('presentationframework')
  48. [xml]$XAML = $inputXML
  49. #Read XAML
  50.  
  51.     $reader=(New-Object System.Xml.XmlNodeReader $xaml)
  52.   try{$Form=[Windows.Markup.XamlReader]::Load( $reader )}
  53. catch{Write-Host "Unable to load Windows.Markup.XamlReader. Double-check syntax and ensure .net is installed."}
  54.  
  55. #===========================================================================
  56. # Load XAML Objects In PowerShell
  57. #===========================================================================
  58.  
  59. $xaml.SelectNodes("//*[@Name]") | %{Set-Variable -Name "WPF$($_.Name)" -Value $Form.FindName($_.Name)}
  60.  
  61. Function Get-FormVariables{
  62. if ($global:ReadmeDisplay -ne $true){Write-host "If you need to reference this display again, run Get-FormVariables" -ForegroundColor Yellow;$global:ReadmeDisplay=$true}
  63. write-host "Found the following interactable elements from our form" -ForegroundColor Cyan
  64. get-variable WPF*
  65. }
  66.  
  67. Get-FormVariables
  68.  
  69. #===========================================================================
  70. # Actually make the objects work
  71. #===========================================================================
  72.  
  73. #Sample entry of how to add data to a field
  74.  
  75. #$vmpicklistView.items.Add([pscustomobject]@{'VMName'=($_).Name;Status=$_.Status;Other="Yes"})
  76.  
  77. #===========================================================================
  78. # Shows the form
  79. #===========================================================================
  80.  
  81. #=============
  82. #combox
  83. #===========================================================================
  84. $OUcombos = Get-content c:\work\listbox\ou.txt
  85. $OUcombos | ForEach-object {$WPFcomboBox.AddChild($_)}
  86.  
  87. #===========================================================================
  88. # Checkbox
  89. #===========================================================================
  90. $WPFcheckbox.Add_Checked({
  91.     $WPFcombobox.IsEnabled=$true
  92.     $WPFcheckbox_copy.IsEnabled=$False
  93.     $WPFcheckbox_copy1.IsEnabled=$False
  94.    })
  95. $WPFcheckbox_copy.Add_Checked({
  96.     $WPFtextbox.IsEnabled=$true
  97.     $WPFcheckbox.IsEnabled=$False
  98.     $WPFcheckbox_copy1.IsEnabled=$False
  99.    })
  100. $WPFcheckbox_copy1.Add_Checked({
  101.     $WPFtextbox1.IsEnabled=$true
  102.     $WPFcheckbox_copy.IsEnabled=$False
  103.     $WPFcheckbox.IsEnabled=$False
  104.    })
  105. $WPFcheckbox.Add_UnChecked({
  106.     $WPFcombobox.IsEnabled=$False
  107.     $WPFcheckbox_copy.IsEnabled=$True
  108.     $WPFcheckbox_copy1.IsEnabled=$True
  109.    })
  110. $WPFcheckbox_copy.Add_UnChecked({
  111.     $WPFtextbox.IsEnabled=$False
  112.     $WPFcheckbox.IsEnabled=$True
  113.     $WPFcheckbox_copy1.IsEnabled=$True
  114.    })
  115. $WPFcheckbox_copy1.Add_UnChecked({
  116.     $WPFtextbox1.IsEnabled=$False
  117.     $WPFcheckbox_copy.IsEnabled=$True
  118.     $WPFcheckbox.IsEnabled=$True
  119.    })
  120.  
  121.  
  122.  
  123. #=========================================================================
  124. # Function
  125. #========================================================================
  126. function Get-LocalGroupMembers  
  127. {  
  128.     param(  
  129.         [parameter(Mandatory=$true,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true)]  
  130.         [Alias("Name")]  
  131.         [string]$ComputerName,  
  132.         [string]$GroupName = "Administrators"  
  133.     )  
  134.      
  135.     begin {}  
  136.      
  137.     process  
  138.     {  
  139.         # If the account name of the computer object was passed in, it will  
  140.         # end with a $. Get rid of it so it doesn't screw up the WMI query.  
  141.         $ComputerName = $ComputerName.Replace("`$", '')  
  142.  
  143.         # Initialize an array to hold the results of our query.  
  144.         $arr = @()  
  145.  
  146.         # Get hostname of remote system.  $computername could reference cluster/alias name.  Need real hostname for subsequent WMI query.
  147.         $hostname = (Get-WmiObject -ComputerName $ComputerName -Class Win32_ComputerSystem).Name
  148.  
  149.         $wmi = Get-WmiObject -ComputerName $ComputerName -Query "SELECT * FROM Win32_GroupUser WHERE GroupComponent=`"Win32_Group.Domain='$Hostname',Name='$GroupName'`""  
  150.  
  151.         # Parse out the username from each result and append it to the array.  
  152.         if ($wmi -ne $null)  
  153.         {  
  154.             foreach ($item in $wmi)  
  155.             {  
  156.                 $data = $item.PartComponent -split "\,"
  157.                 $domain = ($data[0] -split "=")[1]
  158.                 $name = ($data[1] -split "=")[1]
  159.                 $arr += ("$domain\$name").Replace("""","")
  160.                 [Array]::Sort($arr)
  161.                             }  
  162.         }  
  163.         if ($arr -ne $null)
  164.         {
  165.  
  166.         #$hash = @{Computer=$ComputerName;Groupname=$groupname;Members=$arr}
  167.          $WPFlistView.AddChild([pscustomobject]@{'Computer'=$ComputerName;'Groupname'=$groupname;'Members'=$arr})
  168.    
  169.         }
  170.    
  171.          
  172.     }  
  173.      
  174.     end{}  
  175. }
  176.  
  177. #=========================================================================
  178. # Button click
  179. #========================================================================
  180.  
  181. $WPFbutton.Add_Click({
  182. $WPFlistView.Items.Clear()
  183. start-sleep -Milliseconds 840
  184.     if ($WPFcheckbox.IsChecked -eq $true) {
  185.     $OU = $WPFcomboBox.Text
  186.     $Computersinou = Get-adcomputer -filter * -searchbase $OU | sort name | select -Expandproperty name
  187.            $rtn = $null
  188.        $computersinou | ForEach-Object {
  189.        $rtn = Test-Connection -CN $_ -Count 1 -BufferSize 16 -Quiet
  190.        IF ($rtn -match ‘True’) {
  191.             $Computername = $_
  192.             Get-LocalGroupMembers -ComputerName $computername -groupname "Administrators"
  193.             Get-LocalGroupMembers -ComputerName $computername -groupname "Administratörer"
  194.             }
  195.             }
  196.         }
  197.  
  198.         ElseIF ($WPFcheckbox_copy.IsChecked -eq $True){
  199.         $Groupnametext = $WPFtextbox.Text
  200.         $Computersingroup = get-adgroupmember $Groupnametext | sort name | select -expandproperty name
  201.         $rtn1 = $null
  202.         $Computersingroup | ForEach-Object{
  203.             $rtn1 = Test-Connection -CN $_ -Count 1 -BufferSize 16 -Quiet
  204.             IF ($rtn1 -match ‘True’) {
  205.             $Computername2 = $_
  206.             Get-LocalGroupMembers -ComputerName $computername2 -groupname "Administrators"
  207.             Get-LocalGroupMembers -ComputerName $computername2 -groupname "Administratörer"
  208.                         }
  209.                                                }
  210.                                                         }
  211.         ElseIF ($WPFcheckbox_copy1.IsChecked -eq $True){
  212.         $computername = $WPFtextbox1.Text
  213.         get-localgroupmembers -ComputerName $computername -groupname "Administrators"
  214.         get-localgroupmembers -ComputerName $computername -groupname "Administratörer"
  215.         }
  216.  
  217.        
  218.    
  219. })
  220. #====================================================================================
  221.  
  222. write-host "To show the form, run the following" -ForegroundColor Cyan
  223. $Form.ShowDialog() | out-null
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement