Powershell duplicate image scanner So I have made this Duplicate image scanner using powershell. It will operate using the SHA256 hashes of the files.
Any tips or suggestions on making this more dynamic/robust/efficient or adding new features would be greatly appreciatied!
$sig=@'
public static void ShowConsoleWindow(int state)
{
  var handle = GetConsoleWindow();
  ShowWindow(handle,state);
}
[System.Runtime.InteropServices.DllImport(&quot;kernel32.dll&quot;)]
static extern IntPtr GetConsoleWindow();
[System.Runtime.InteropServices.DllImport(&quot;user32.dll&quot;)]
static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);
'@
$hc=Add-Type -mem $sig -name Hide -Names HideConsole -Ref System.Runtime.InteropServices -Pas
$hc::ShowConsoleWindow(0)
[console]::title=&quot;Duplicate Image Scanner (c) Wasif Hasan | Sep 2020&quot;
$eXt=@('.jpg','.png','.gif','.jpeg','.webp','.tiff','.psd','.raw','.bmp','.heif','indd','.svg')
@('system.windows.forms','system.drawing')|%{add-type -as $_}
$s=[windows.forms.form]::new();$s.size=[drawing.size]::new(400,850);$s.StartPosition=&quot;CenterScreen&quot;;$s.Text=&quot;Select drives to scan&quot;
$drives=gdr -p &quot;FileSystem&quot;|select -eXp name
$top=20;$left=50;$drives|%{
$c=$_.split(&quot; &quot;)-join&quot;_&quot;;$top += 20
iex &quot;`$$($c) = New-Object System.Windows.Forms.CheckBox;`$$($c).Top = $($top);`$$($c).Left = $($left);`$$($c).Anchor='Left,Top';`$$($c).Parent='';`$$($c).Text='$($_)';`$$($c).Autosize=`$true;if('$_' -in `$drives){`$$c.Checked=`$true};`$s.Controls.Add(`$$c)&quot;}
$ok=New-Object System.Windows.Forms.Button;$ok.Text='OK';$ok.Top=770;$ok.Left=290
$ok.add_click({$s.Close()});$s.Controls.AddRange($ok)
$sa=New-Object System.Windows.Forms.Button;$sa.Text='Select All';$sa.Top=770;$sa.Left=200
$sa.add_click({$s.Controls|?{($_.Checked) -or !($_.Checked)}|%{try{$_.Checked=$True}catch{}}});$s.Controls.AddRange($sa)
$null=$s.ShowDialog()
$choices=$s.Controls|?{$_.Checked}|select -eXp Text
$i=0;$choices|%{$choices[$i]=$_+':\';$i++}
$f=[windows.forms.form]::new();$f.Size=[drawing.size]::new(600,100);$f.StartPosition=&quot;CenterScreen&quot;;$f.Text=&quot;Please wait&quot;
$l=[windows.forms.label]::new();$l.Text=&quot;Please wait until the scan is complete........&quot;;$l.Font=&quot;Segoe UI,16&quot;;$l.AutoSize=$true;$f.Controls.AddRange($l)
$null=$f.ShowDialog()
$files=@();$hCols=@();$choices|%{
dir $_ -r|?{$_.eXtension-in$eXt}|%{
$h=get-filehash $_.fullname -a 'SHA256'|select -eXp hash
if($h-in$hCols){$files+=$_.fullName}else{$hCols+=$h}
}};$f.Close()
$del=$files|ogv -t &quot;Duplicate images (Hold CTRL and select the ones to delete)&quot; -p
$del|%{rm &quot;$_&quot; -fo}
[windows.forms.messagebox]::Show(&quot;Thanks for using!&quot;,&quot;Duplicate image scanner&quot;,&quot;OK&quot;,&quot;Information&quot;)
Let me give you some advice:

First of all you should make your code much more rideable. I am struggling to actually read this code. You should name your variables meaningfully, so the code can be read like English.

Don't write multiple commands on a single line. It is easier to keep track of code when single command per line is used.

When writing PowerShell scripts don't use cmdlet aliases, use full names of cmdlets. Different people use different aliases, but all of them know full names of similes.