Mike's Profile Cleanup Tool
Mike's Profile Cleanup Tool
#Created by Michael J. Thomas
#Created on 12/27/2019
#Updated on 12/28/2019
# Use at your own risk. We are not responsible for any lost of data.
# Thomas IT Services. All Rights Reserved. (c) 2019-2020
$ErrorActionPreference = 0
Add-Type -AssemblyName System.Windows.Forms
[System.Windows.Forms.Application]::EnableVisualStyles()
$Form = New-Object system.Windows.Forms.Form
$Form.ClientSize = '446,256'
$Form.text = "Mike'`s Profile Cleaner Tool - PowerShellWeekly.com"
$Form.TopMost = $true
$Form.StartPosition = "CenterScreen"
$Form.FormBorderStyle = 'Fixed3D'
$Form.MaximizeBox = $false
#[Convert]::ToBase64String((Get-Content "C:\Users\mjt011\Desktop\Service Desk Install\favicon.ico" -Encoding Byte))
$iconBase64 = "AAABAAEAEBAAAAEAIABoBAAAFgAAACgAAAAQAAAAIAAAAAEAIAAAAAAAQAQAAAAAAAAAAAAAAAAAAAAAAAD8tV3//LVd//y0Xf/8tF3//LRd//y0Xf/8tF3//LRd//y0Xf/8tF3//LRd//y0Xf/8tV3//LVd//y0Xf/1tV3/+50b//udG//7nRv/+50b//udG//7nRv/+50b//udG//7nRv/+50b//udG//7nRv/+50b//udG//7nRv/+50b//uiJ//7oif/+6In//uiJ//7oiX/+6Il//uiJf/7oiX/+6Il//uiJf/7oiX/+6Il//uiJ//7oif/+6In//uiJ//7piv/+6Yr//umK//7piv/+6s1//utPf/7qi7/+6kt//utPP/7rT3/+609//uqMf/7piv/+6Yr//umK//7piv/+6ow//uqMP/7qSz/+7ld//jjyP/6w3j/+PLr//jx6f/5yYf/+siH//rHhP/46dT/+6ko//uqMP/7qjD/+6ow//uuNv/7rjb/+60x//u7XP/47+T/+rNF//uvM//55MX/+sN3//rAbP/6v2n/+efN//uuLv/7rjX/+642//uuNv/7sjv/+7I7//uwM//7vl7/+ff3//r28v/7z47/+7lF//rkw//6+/7/+vj3//nz6f/7sCz/+7E4//uyO//7sjv/+7U9//u2QP/7wFv/+9GK//v5+v/79/P/+/r7//vmxP/8xGP/+9mf//v39P/79vH/+8Zq//u+Vv/7tTz/+7Y+//vBW//8z37//M5+//zXlv/7+/v/+/j1//v49f/7/P///OCw//zKbf/89ez/+/j0//zOe//9z4H//Mx4//y9TP/91Yz//dWK//3UiP/925///P3+//z69//8/Pz//OzR//zPef/88dz//Pv8//z69v/904b//dSK//3Vi//81Yv//dqW//3alv/82ZT//OCp//39///9/Pv//fTk//zVhf/979b//f3///38+v/9+/j//NmT//3Zlv/82pb//dmW//3foP/936D//N+f//3ls//9/////f////zmtv/979T//f////3+///9/v///f39//zenv/936D//N+g//zfoP/95Kv//eSr//3kqv/95bP//fHW//3w0//98db//fHX//3w0//98NP//fDU//3w0//946r//eSr//3kq//95Kv//ee2//3ntv/957b//ee1//zmsv/85rL//Oay//zmsv/85rL//Oay//zmsv/95rL//ee2//3ntv/957b//ee2//zsv//87L///Ou///zrv//867///Ou///zrv//867///Ou///zrv//867///Ou///zrv//867///Ou///zrv//978j//e/I//3vyP/978j//e7I//3uyP/97sj//e7I//3uyP/97sj//e7I//3uyP/978j//e/I//3uyP/97sj/AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=="
$iconBytes = [Convert]::FromBase64String($iconBase64)
$stream = New-Object IO.MemoryStream($iconBytes, 0, $iconBytes.Length)
$stream.Write($iconBytes, 0, $iconBytes.Length);
$iconImage = [System.Drawing.Image]::FromStream($stream, $true)
$Form.Icon = [System.Drawing.Icon]::FromHandle((New-Object System.Drawing.Bitmap -Argument $stream).GetHIcon())
$ListBox1 = New-Object system.Windows.Forms.ListBox
$ListBox1.text = "listBox"
$ListBox1.width = 137
$ListBox1.height = 150
$listBox1.Sorted = $true
$ListBox1.location = New-Object System.Drawing.Point(18, 44)
$Users = Get-WmiObject Win32_UserProfile;
foreach ($User in $Users)
{
$UserPath = (Split-Path $User.LocalPath -Leaf).ToLower()
if ($UserPath -eq $env:Username)
{
continue;
}
if ($User.Special -eq $true)
{
continue;
}
[void]$ListBox1.Items.Add($UserPath)
}
$ListBox2 = New-Object system.Windows.Forms.ListBox
$ListBox2.text = "listBox"
$ListBox2.width = 140
$ListBox2.height = 150
$ListBox2.location = New-Object System.Drawing.Point(285, 44)
$Button1 = New-Object system.Windows.Forms.Button
$Button1.text = "Exclude"
$Button1.width = 80
$Button1.height = 30
$Button1.location = New-Object System.Drawing.Point(180, 122)
$Button1.Font = 'Microsoft Sans Serif,10'
$Button1.Add_Click({
If ($ListBox1.SelectedItem)
{
$ListBox2.Items.Add($ListBox1.SelectedItem)
$ListBox1.Items.Remove($ListBox1.SelectedItem)
}
})
$Button2 = New-Object system.Windows.Forms.Button
$Button2.text = "Clean Profiles"
$Button2.width = 122
$Button2.height = 30
$Button2.location = New-Object System.Drawing.Point(160, 214)
$Button2.Font = 'Microsoft Sans Serif,10'
$Button2.Add_Click({
$Users = Get-WmiObject Win32_UserProfile;
$Skip = @($ListBox2.Items);
Write-Host "Cleaning up User profiles..." -ForegroundColor Cyan;
foreach ($User in $Users)
{
$UserPath = (Split-Path $User.LocalPath -Leaf).ToLower()
If ($Skip -contains $UserPath)
{
Write-Host "Skipping $UserPath from ignore list.";
continue;
}
if ($UserPath -eq $env:Username)
{
Write-Host "Skipping $UserPath because it belongs to the current User.";
continue;
}
if ($User.Special -eq $true)
{
Write-Host "Skipping $UserPath because it is a special system account.";
continue;
}
Write-Host "Deleting profile for $UserPath..." -ForegroundColor Green;
$User.Delete();
}
})
$Label1 = New-Object system.Windows.Forms.Label
$Label1.text = "User Profiles"
$Label1.AutoSize = $true
$Label1.width = 25
$Label1.height = 10
$Label1.location = New-Object System.Drawing.Point(34, 22)
$Label1.Font = 'Microsoft Sans Serif,10'
$Label2 = New-Object system.Windows.Forms.Label
$Label2.text = "Skip Profiles"
$Label2.AutoSize = $true
$Label2.width = 25
$Label2.height = 10
$Label2.location = New-Object System.Drawing.Point(298, 22)
$Label2.Font = 'Microsoft Sans Serif,10'
$Form.controls.AddRange(@($ListBox1, $ListBox2, $Button1, $Button2, $Label1, $Label2))
[void]$Form.ShowDialog()
#Created on 12/27/2019
#Updated on 12/28/2019
# Use at your own risk. We are not responsible for any lost of data.
# Thomas IT Services. All Rights Reserved. (c) 2019-2020
$ErrorActionPreference = 0
Add-Type -AssemblyName System.Windows.Forms
[System.Windows.Forms.Application]::EnableVisualStyles()
$Form = New-Object system.Windows.Forms.Form
$Form.ClientSize = '446,256'
$Form.text = "Mike'`s Profile Cleaner Tool - PowerShellWeekly.com"
$Form.TopMost = $true
$Form.StartPosition = "CenterScreen"
$Form.FormBorderStyle = 'Fixed3D'
$Form.MaximizeBox = $false
#[Convert]::ToBase64String((Get-Content "C:\Users\mjt011\Desktop\Service Desk Install\favicon.ico" -Encoding Byte))
$iconBase64 = "AAABAAEAEBAAAAEAIABoBAAAFgAAACgAAAAQAAAAIAAAAAEAIAAAAAAAQAQAAAAAAAAAAAAAAAAAAAAAAAD8tV3//LVd//y0Xf/8tF3//LRd//y0Xf/8tF3//LRd//y0Xf/8tF3//LRd//y0Xf/8tV3//LVd//y0Xf/1tV3/+50b//udG//7nRv/+50b//udG//7nRv/+50b//udG//7nRv/+50b//udG//7nRv/+50b//udG//7nRv/+50b//uiJ//7oif/+6In//uiJ//7oiX/+6Il//uiJf/7oiX/+6Il//uiJf/7oiX/+6Il//uiJ//7oif/+6In//uiJ//7piv/+6Yr//umK//7piv/+6s1//utPf/7qi7/+6kt//utPP/7rT3/+609//uqMf/7piv/+6Yr//umK//7piv/+6ow//uqMP/7qSz/+7ld//jjyP/6w3j/+PLr//jx6f/5yYf/+siH//rHhP/46dT/+6ko//uqMP/7qjD/+6ow//uuNv/7rjb/+60x//u7XP/47+T/+rNF//uvM//55MX/+sN3//rAbP/6v2n/+efN//uuLv/7rjX/+642//uuNv/7sjv/+7I7//uwM//7vl7/+ff3//r28v/7z47/+7lF//rkw//6+/7/+vj3//nz6f/7sCz/+7E4//uyO//7sjv/+7U9//u2QP/7wFv/+9GK//v5+v/79/P/+/r7//vmxP/8xGP/+9mf//v39P/79vH/+8Zq//u+Vv/7tTz/+7Y+//vBW//8z37//M5+//zXlv/7+/v/+/j1//v49f/7/P///OCw//zKbf/89ez/+/j0//zOe//9z4H//Mx4//y9TP/91Yz//dWK//3UiP/925///P3+//z69//8/Pz//OzR//zPef/88dz//Pv8//z69v/904b//dSK//3Vi//81Yv//dqW//3alv/82ZT//OCp//39///9/Pv//fTk//zVhf/979b//f3///38+v/9+/j//NmT//3Zlv/82pb//dmW//3foP/936D//N+f//3ls//9/////f////zmtv/979T//f////3+///9/v///f39//zenv/936D//N+g//zfoP/95Kv//eSr//3kqv/95bP//fHW//3w0//98db//fHX//3w0//98NP//fDU//3w0//946r//eSr//3kq//95Kv//ee2//3ntv/957b//ee1//zmsv/85rL//Oay//zmsv/85rL//Oay//zmsv/95rL//ee2//3ntv/957b//ee2//zsv//87L///Ou///zrv//867///Ou///zrv//867///Ou///zrv//867///Ou///zrv//867///Ou///zrv//978j//e/I//3vyP/978j//e7I//3uyP/97sj//e7I//3uyP/97sj//e7I//3uyP/978j//e/I//3uyP/97sj/AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=="
$iconBytes = [Convert]::FromBase64String($iconBase64)
$stream = New-Object IO.MemoryStream($iconBytes, 0, $iconBytes.Length)
$stream.Write($iconBytes, 0, $iconBytes.Length);
$iconImage = [System.Drawing.Image]::FromStream($stream, $true)
$Form.Icon = [System.Drawing.Icon]::FromHandle((New-Object System.Drawing.Bitmap -Argument $stream).GetHIcon())
$ListBox1 = New-Object system.Windows.Forms.ListBox
$ListBox1.text = "listBox"
$ListBox1.width = 137
$ListBox1.height = 150
$listBox1.Sorted = $true
$ListBox1.location = New-Object System.Drawing.Point(18, 44)
$Users = Get-WmiObject Win32_UserProfile;
foreach ($User in $Users)
{
$UserPath = (Split-Path $User.LocalPath -Leaf).ToLower()
if ($UserPath -eq $env:Username)
{
continue;
}
if ($User.Special -eq $true)
{
continue;
}
[void]$ListBox1.Items.Add($UserPath)
}
$ListBox2 = New-Object system.Windows.Forms.ListBox
$ListBox2.text = "listBox"
$ListBox2.width = 140
$ListBox2.height = 150
$ListBox2.location = New-Object System.Drawing.Point(285, 44)
$Button1 = New-Object system.Windows.Forms.Button
$Button1.text = "Exclude"
$Button1.width = 80
$Button1.height = 30
$Button1.location = New-Object System.Drawing.Point(180, 122)
$Button1.Font = 'Microsoft Sans Serif,10'
$Button1.Add_Click({
If ($ListBox1.SelectedItem)
{
$ListBox2.Items.Add($ListBox1.SelectedItem)
$ListBox1.Items.Remove($ListBox1.SelectedItem)
}
})
$Button2 = New-Object system.Windows.Forms.Button
$Button2.text = "Clean Profiles"
$Button2.width = 122
$Button2.height = 30
$Button2.location = New-Object System.Drawing.Point(160, 214)
$Button2.Font = 'Microsoft Sans Serif,10'
$Button2.Add_Click({
$Users = Get-WmiObject Win32_UserProfile;
$Skip = @($ListBox2.Items);
Write-Host "Cleaning up User profiles..." -ForegroundColor Cyan;
foreach ($User in $Users)
{
$UserPath = (Split-Path $User.LocalPath -Leaf).ToLower()
If ($Skip -contains $UserPath)
{
Write-Host "Skipping $UserPath from ignore list.";
continue;
}
if ($UserPath -eq $env:Username)
{
Write-Host "Skipping $UserPath because it belongs to the current User.";
continue;
}
if ($User.Special -eq $true)
{
Write-Host "Skipping $UserPath because it is a special system account.";
continue;
}
Write-Host "Deleting profile for $UserPath..." -ForegroundColor Green;
$User.Delete();
}
})
$Label1 = New-Object system.Windows.Forms.Label
$Label1.text = "User Profiles"
$Label1.AutoSize = $true
$Label1.width = 25
$Label1.height = 10
$Label1.location = New-Object System.Drawing.Point(34, 22)
$Label1.Font = 'Microsoft Sans Serif,10'
$Label2 = New-Object system.Windows.Forms.Label
$Label2.text = "Skip Profiles"
$Label2.AutoSize = $true
$Label2.width = 25
$Label2.height = 10
$Label2.location = New-Object System.Drawing.Point(298, 22)
$Label2.Font = 'Microsoft Sans Serif,10'
$Form.controls.AddRange(@($ListBox1, $ListBox2, $Button1, $Button2, $Label1, $Label2))
[void]$Form.ShowDialog()
Thanks!
ReplyDelete