[GUI PowerShell] Get_UserACC - Get All User Accounts Info (Advanced Script) 12-04-2011, 03:50 AM
#1
Here's another script i've been working on for a little while today, probably one of the most advanced script's i've created yet. What this does is gets an array returned from WMI for UserAccounts, and splits those arrays into a very detailed view in a GUI form richtextbox control. Other features for exporting that data and events on form load and form close involving message box views and notification tooltips.
Preview:
![[Image: icfy4PaiUGmdv.png]](http://k.minus.com/icfy4PaiUGmdv.png)
Video:
Code:
#Get_UserACC Powershell Script
#Copyright AceInfinity - Tech.Reboot.Pro 2011
[Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms") | out-null
[Reflection.Assembly]::loadwithpartialname("System.Drawing") | Out-Null
function CreateForm {
$Form1 = New-Object System.Windows.Forms.Form
$btn1 = New-Object System.Windows.Forms.Button
$btn2 = New-Object System.Windows.Forms.Button
$rtb_text = New-Object System.Windows.Forms.RichTextBox
$label = New-Object System.Windows.Forms.Label
$btn1_click = {
$rtb_text.Text | Out-file "user_accounts.txt"
[Windows.Forms.MessageBox]::Show("Data has been successfully imported to > user_accounts.txt!", `
"Export Success",`
[Windows.Forms.MessageBoxButtons]::OK,`
[Windows.Forms.MessageBoxIcon]::Information) | out-null
}
$btn2_click = {
AppInfo
}
$Form1_Load = {
$rtb_text.Select()
Get_WinAccounts
}
$Form1_Closing = {
CloseMSG
}
$Form1.Name = 'Form1'
$Form1.Text = 'Get_UserACC PowerShell Script'
$Form1.Icon = [System.IconExt]::Extract("shell32.dll", 44, $true)
$Border_Style = New-Object System.Windows.Forms.FormBorderStyle
$Border_Style = 'FixedSingle'
#$Form1.ShowInTaskbar = $False
$Form1.FormBorderStyle = $Border_Style
$Form1.MaximizeBox = $False
$Form1.DataBindings.DefaultDataSourceUpdateMode = 0
$Form1.BackColor = [System.Drawing.Color]::FromArgb(255,227,227,227)
$Draw_Size = New-Object System.Drawing.Size
$Draw_Size.Width = 575
$Draw_Size.Height = 575
$Form1.ClientSize = $Draw_Size
$Form1.add_Load($Form1_Load)
$Form1.add_Closing($Form1_Closing)
$rtb_text.Text = ''
$rtb_text.TabIndex = 2
$rtb_text.Name = 'rtb_text'
$rtb_text.ReadOnly = $True
$rtb_text.Font = New-Object System.Drawing.Font("Courier New",10,0,3,0)
$rtb_text.DataBindings.DefaultDataSourceUpdateMode = 0
$Draw_Size = New-Object System.Drawing.Size
$Draw_Size.Width = 555
$Draw_Size.Height = 500
$rtb_text.Size = $Draw_Size
$Draw_Point = New-Object System.Drawing.Point
$Draw_Point.X = 10
$Draw_Point.Y = 10
$rtb_text.Location = $Draw_Point
$Form1.Controls.Add($rtb_text)
$btn1.UseVisualStyleBackColor = $True
$btn1.TabIndex = 0
$btn1.Name = 'btn1'
$btn1.Text = 'Export Data'
$Draw_Size = New-Object System.Drawing.Size
$Draw_Size.Width = 110
$Draw_Size.Height = 21
$btn1.Size = $Draw_Size
$Draw_Point = New-Object System.Drawing.Point
$Draw_Point.X = 165
$Draw_Point.Y = 525
$btn1.Location = $Draw_Point
$btn1.add_Click($btn1_click)
$Form1.Controls.Add($btn1)
$btn2.UseVisualStyleBackColor = $True
$btn2.TabIndex = 0
$btn2.Name = 'btn2'
$btn2.Text = 'About'
$Draw_Size = New-Object System.Drawing.Size
$Draw_Size.Width = 110
$Draw_Size.Height = 21
$btn2.Size = $Draw_Size
$Draw_Point = New-Object System.Drawing.Point
$Draw_Point.X = 295
$Draw_Point.Y = 525
$btn2.Location = $Draw_Point
$btn2.add_Click($btn2_click)
$Form1.Controls.Add($btn2)
$label.DataBindings.DefaultDataSourceUpdateMode = 0
$label.Name = 'label'
$label.Text = 'Scripted by AceInfinity'
$Draw_Size = New-Object System.Drawing.Size
$Draw_Size.Width = 125
$Draw_Size.Height = 21
$label.Size = $Draw_Size
$Draw_Point = New-Object System.Drawing.Point
$Draw_Point.X = 225
$Draw_Point.Y = 555
$label.Location = $Draw_Point
$Form1.Controls.Add($label)
$Form1.ShowDialog() | Out-Null
}
function Write_ {
param($text)
$rtb_text.Text += "$text`n"
}
function Get_WinAccounts {
$rtb_text.Text = ''
$User_Accounts = get-wmiobject -class "Win32_UserAccount" -namespace "root\CIMV2" `
-filter "LocalAccount = True" -computername "."
foreach ($obj in $User_Accounts) {
$AccountType = $obj.AccountType
$Caption = $obj.Caption
$Description = $obj.Description
$Disabled = $obj.Disabled
$Domain = $obj.Domain
$FullName = $obj.FullName
$InstallDate = $obj.InstallDate
$LocalAccount = $obj.LocalAccount
$Lockout = $obj.Lockout
$Name = $obj.Name
$PasswordChangeable = $obj.PasswordChangeable
$PasswordExpires = $obj.PasswordExpires
$PasswordRequired = $obj.PasswordRequired
$SID = $obj.SID
$SIDType = $obj.SIDType
$Status = $obj.Status
Write_ "Account Type: $AccountType"
Write_ "Caption: $Caption"
Write_ "Description: $Description"
Write_ "Disabled: $Disabled"
Write_ "Domain: $Domain"
Write_ "FullName: $FullName"
Write_ "Installation Date: $InstallDate"
Write_ "Local Account: $LocalAccount"
Write_ "Lockout: $Lockout"
Write_ "Name: $Name"
Write_ "Password Changeable: $PasswordChangeable"
Write_ "Password Expires: $PasswordExpires"
Write_ "Password Required: $PasswordRequired"
Write_ "SID: $SID"
Write_ "SID Type: $SIDType"
Write_ "Status: $Status"
Write_
}
}
function AppInfo {
[Windows.Forms.MessageBox]::Show("Get_UserACC Coded by AceInfinity (c)2011 `r`n`r`nhttp://Tech.Reboot.Pro", `
"About",`
[Windows.Forms.MessageBoxButtons]::OK,`
[Windows.Forms.MessageBoxIcon]::Information) | out-null
}
$IcnExtr = @"
using System;
using System.Drawing;
using System.Runtime.InteropServices;
namespace System
{
public class IconExt {
public static Icon Extract(string file, int number, bool largeIcon) {
IntPtr large;
IntPtr small;
ExtractIconEx(file, number, out large, out small, 1);
try {
return Icon.FromHandle(largeIcon ? large : small);
}
catch {
return null;
}
}
[DllImport("Shell32.dll", EntryPoint = "ExtractIconExW", CharSet = CharSet.Unicode, ExactSpelling = true, CallingConvention = CallingConvention.StdCall)]
private static extern int ExtractIconEx(string sFile, int iIndex, out IntPtr piLargeVersion, out IntPtr piSmallVersion, int amountIcons);
}
}
"@
Add-Type -TypeDefinition $IcnExtr -ReferencedAssemblies System.Drawing
function CloseMSG {
$objNotifyIcon = New-Object System.Windows.Forms.NotifyIcon
$objNotifyIcon.Icon = [System.IconExt]::Extract("shell32.dll", 52, $true)
$objNotifyIcon.BalloonTipIcon = "None"
$objNotifyIcon.BalloonTipText = "Get_UserACC Powershell Script Coded by AceInfinity"
$objNotifyIcon.BalloonTipTitle = "Information"
$objNotifyIcon.Visible = $True
$objNotifyIcon.ShowBalloonTip(10000)
}
CreateFormPreview:
Spoiler:
![[Image: icfy4PaiUGmdv.png]](http://k.minus.com/icfy4PaiUGmdv.png)
Video:
ArkPhaze
"Object oriented way to get rich? Inheritance"
Getting Started: C/C++ | Common Mistakes
[ Assembly / C++ / .NET / Haskell / J Programmer ]
"Object oriented way to get rich? Inheritance"
Getting Started: C/C++ | Common Mistakes
[ Assembly / C++ / .NET / Haskell / J Programmer ]


![[+]](https://sinister.li/images/modern/collapse_collapsed.png)