2024-03-11 22:45:37 +08:00
start " ScanPC " /D " %~dp0 " powershell.exe " $comp= " " " %1 " " " ; $a= Get-Content '.\ %~nx0 ' -Encoding Oem | Select-Object -Skip 3; Invoke-Expression ($a -join " " " `r`n" " " ) "
EXIT /B
2024-03-17 21:55:18 +08:00
# Fixed exclude symbolic link from scan C:\$Recycle.Bin (ReparsePoint)
2024-03-11 22:45:37 +08:00
# https://github.com/Sync1er/ChernigovEugeniyUtilities
# https://habr.com/ru/users/Sync1er/
# Chernigov Eugeniy 2024. For non commercial use only
[void] [System.Reflection.Assembly]::LoadWithPartialName(" System.Windows.Forms " )
Add-Type -Name Window -Namespace Console -MemberDefinition '
[DllImport(" Kernel32.dll " )]
public static extern IntPtr GetConsoleWindow();
[DllImport(" user32.dll " )]
public static extern bool ShowWindow(IntPtr hWnd, Int32 nCmdShow);
'
[Console.Window]::ShowWindow(( $consolePtr = [Console.Window]::GetConsoleWindow()), 0)
2024-03-17 21:55:18 +08:00
Function Prompt {$host.ui.RawUI.WindowTitle = $(get-location); " :: " }
2024-03-11 22:45:37 +08:00
if (-not $ c o m p ) { $ c o m p = $ e n v : C O M P U T E R N A M E }
$jobCount=4
$excl=" GENUINEINTEL " ," PRINTENUM " ," MSRRAS " ," }\ "
$hide=" RAS Async Adapter " ," WAN Miniport " ," Virtual Adapter " ," FAX " ," Microsoft XPS " ," OneNote " ," ����� ���।� ������ " ," PDF " ," Microsoft Kernel Debug Network Adapter " ," HTREE "
$repl=" Intel(R) Core(TM) " ," 11th Gen Intel(R) Core(TM) " ," Intel(R) " ," System Product Name " ," 82371AB/EB PCI Bus Master " ," To be filled by O.E.M. " ," Virtual Platform " ," Express Chipset Family " ," Express Chipset " ," \(��௮����� ���������� - WDDM 1.1\) " ," ����� ������奬 " ," ������⢮ ���� ������奬 " ," /C200 Series 6 Port " ," 6th Generation Core Processor Family Platform " ," Family Controller " ," APU with Radeon(tm) HD Graphics " ," Storage Controllers " ," Universal Host Controller " ," \(����������\) " ," Series/C200 Series Chipset Family USB " ," ����� " ," ������⥫���� ���� " ," �����७��� " ," ������塞�� " ," �⠭������� " ," Enhanced Host Controller " ," Storage Controller " ," Chipset Family " ," LaserJet Professional "
$sprtr=" ------------------------------------------------- "
$list= @()
$SlctnStrt= 0
$global:usrSz= @()
function txt($txt) {$ListBox3.AppendText(" $txt " )}
function Output($txt=" `r`n " , $color=" black " , $font=$font){
$start=$ListBox3.TextLength
$ListBox3.AppendText($txt)
$ListBox3.SelectionStart = $start
$ListBox3.SelectionLength = $txt.Length
$ListBox3.SelectionFont = $font
$ListBox3.SelectionColor = $color
$start=$ListBox3.TextLength
$ListBox3.AppendText('')
$ListBox3.SelectionLength = 0
$ListBox3.SelectionColor = 'Black'
}
$help="
Buttons:
Devices - show devices
Scan - show hardware information and users
Scan option:
Print - show printers
Size - Scan and show system and users files sizes
HW - show CPU, memory, HDD, vendor
Usr - chek users now logged-in and *last logon (Gray: full list)
*last logon time not always correct
CR button - clean C:\`$Recycle.Bin by deleting files older than 2 month
CR button to show if size of C:\`$Recycle.Bin is more than 500MB
2024-03-18 15:18:01 +08:00
Don't forget to run as administrator for scanning local computer
2024-03-11 22:45:37 +08:00
2024-03-18 15:18:01 +08:00
Author is not liable for any loss or claim
2024-03-17 21:55:18 +08:00
2024-03-11 22:45:37 +08:00
https://github.com/Sync1er/ChernigovEugeniyUtilities
https://habr.com/ru/users/Sync1er/
Chernigov Eugeniy 2024. For non commercial use only
2024-03-17 21:55:18 +08:00
17.03.2024
2024-03-11 22:45:37 +08:00
"
$ScriptBlock= {
$usrDir=" $input " -split ';'
$fldrs='Downloads;Pictures;Desktop;Videos;Documents;Music;AppData\Local\Temp;AppData\Local\Microsoft\Outlook' -split ';'
$tmp=$fldrs | ForEach {
$a=$($(Get-ChildItem -Path " $($usrDir -join '\')\$_ " -Recurse -Force | ForEach {$_.Length}) 2 > $null | Measure-Object -Sum).Sum / 1MB
if ($a - g t 1 0 0 ) { @ { u s r D i r = $ u s r D i r [ 1 ] ; D i r = $ _ ; S i z e = $ a } }
}
if ($tmp){$tmp}
}
function PrProgres { $job=$((Get-Job | Where { $_.State -eq " Running " }).count)
if ($job){$job= " J $ j o b " } e l s e { $ j o b = " " }
$Label.Text= " $job $prcnt "
}
function OutputSize ($usrSz){
( $usrSz.usrDir | Sort-Object -Unique | ForEach {$usrDir=$_; @{usrDir=$usrDir;Sum= $(($usrSz | Where {$_.usrDir -eq $usrDir}) .Size | Measure-Object -Sum).Sum}} | `
` Sort-Object {$_.sum} -Descending).usrDir | ForEach {
$usrDir=$_
$out= $usrSz | Where {$_.usrDir -eq $usrDir} | ForEach {" `r`n " +$($_.Dir).PadRight(22," " )+$(" {0:n0} " -f $_.Size+" MB " ).PadLeft(10," " )}
$usrSz | Where {$_.usrDir -eq $usrDir} | ForEach { $global:sum+=$_.Size}
$usr= $null; $usr= $usrs | Where {$_.Login -eq $usrDir} | Select-Object -First 1
$dep=(($usr.DistinguishedName -split ',OU=')[1] -split ',')[0]
$fullname= Shrt " $($usr.fullname) "
$clr=" SlateBlue " ; if(-not($usr.Enabled) -and $usr.fullname){$clr=" red " }
$txt1=$(addSp " $usrDir $($usr.LastLogin) " 22)
$txt2=''; if($dep){$txt2=" /$dep " }
$bar=(0..(" $txt1$fullname$txt2 " .Length + 3) | ForEach {'-'}) -join ''
Output " `n$txt1 "
Output " $fullname " $clr
Output $(" $txt2`r`n$bar-$out`r`n`r`n " )
}
}
2024-03-17 21:55:18 +08:00
function Stop { Get-Job | Remove-Job -Force; ScanButton {Chek} 'Scan'; if($global:wrm -eq 'Stopped'){Get-Service -Name WinRM -ComputerName $compAdr | Stop-service}; $global:wrm=$null}
2024-03-11 22:45:37 +08:00
$step=0
$tmrTick=10
if ($timer){$timer.Dispose()}
$timer = New-Object System.Windows.Forms.Timer
$timer.Interval = 200
$timer.add_tick({
$prcnt=" "
if ($step - e q 6 ) {
if ($sum){
$sum=[int](($sum | Measure-Object -Sum).Sum /1024)
Output " `n`n All summary - $sum GB "
}
2024-03-17 21:55:18 +08:00
Output " `n`n -= Done =-`n`n " ; $global:step=$false; ScanButton {Chek} 'Scan'; if($global:wrm -eq 'Stopped'){Get-Service -Name WinRM -ComputerName $compAdr | Stop-service}; $global:wrm=$null; $timer.Stop()
2024-03-11 22:45:37 +08:00
}
if ($step - e q 5 ) {
$job= Get-Job | Where { $_.Name -eq 'GetSize' -and $_.State -eq " Completed " }
if ($job){$global:jobCnt+= $ j o b . C o u n t ; $ t m p = $ ( $ j o b | R e c e i v e - J o b ) 2 > $ n u l l ; $ j o b | R e m o v e - J o b - f o r c e }
if ($drs.Count){$prcnt= " { 0 : P 0 } " - f ( $ g l o b a l : j o b C n t / $ ( $ d r s . C o u n t ) ) }
if ($global:usrSz){OutputSize $ g l o b a l : u s r S z ; $ g l o b a l : u s r S z = @ ( ) }
if ($tmp){OutputSize $ t m p ; $ t m p = @ ( ) }
if (-not((Get-Job | W h e r e { $ _ . N a m e - e q ' G e t S i z e ' } ) - o r $ c n t ) ) { $ g l o b a l : s t e p = 6 }
}
if ($cnt){
$run=(Get-Job | Where {$_.Name -eq 'GetSize' -and $_.State -eq " Running " }).count
if ($run - l e $ j o b C o u n t - a n d $ c n t ) { $ g l o b a l : c n t - - ; S t a r t - J o b - I n p u t O b j e c t " \ \ $ c o m p A d r \ C $ \ U s e r s ; $ ( $ d r s [ $ c n t ] ) " - S c r i p t B l o c k $ S c r i p t B l o c k - N a m e G e t S i z e }
}
if ($step - e q 4 . 5 ) {
if (Get-Job | W h e r e { $ _ . N a m e - e q ' S y s t e m f i l e s ' } ) {
$job= Get-Job | Where { $_.Name -eq 'System files' -and $_.State -eq 'Completed'}
if ($job){$out= $ ( $ j o b | R e c e i v e - J o b ) ; $ j o b | R e m o v e - J o b - f o r c e ; O u t p u t $ o u t ; S h C R B u t t o n $ o u t }
if (-not(Get-Job | W h e r e { $ _ . N a m e - e q ' S y s t e m f i l e s ' } ) ) {
$global:step=5
if ($os - a n d $ C h e c k B o x 2 . C h e c k e d ) { O u t p u t " ` n S c a n u s e r s f o l d e r s s i z e m o r e t h a n 1 0 0 M B . . . ` n ` n " }
}
}else{$global:step=5}
}
if ($step - e q 4 . 2 ) {
if (Get-Job | W h e r e { $ _ . N a m e - e q ' U s e r s f i l e s I n v o k e ' } ) {
$job= Get-Job | Where { $_.Name -eq 'Users files Invoke' -and $_.State -eq " Completed " }
if ($job){
$out= $job | Receive-Job; $job | Remove-Job -force
if ($out){$global:usrSz= $ o u t ; $ g l o b a l : s t e p = 4 . 5 }
else{
$global:drs= $(Get-ChildItem -Path " \\$compAdr\C$\Users " -Directory -name) 2 > $null
$global:cnt= $drs.Count
$global:step=4.5
}
}
}else{$global:step=6}
}
if ($step - e q 4 . 1 ) {
if (Get-Job | W h e r e { $ _ . N a m e - e q ' S y s t e m f i l e s I n v o k e ' } ) {
$job= Get-Job | Where { $_.Name -eq 'System files Invoke' -and $_.State -eq " Completed " }
if ($job){$out= $ j o b | R e c e i v e - J o b ; $ j o b | R e m o v e - J o b - f o r c e }
if ($out){Output $ o u t ; $ g l o b a l : s t e p = 4 . 2 ; S h C R B u t t o n $ o u t ; O u t p u t " ` n ` n S c a n u s e r s f o l d e r s s i z e m o r e t h a n 1 0 0 M B . . . ` n ` n " }
else{GetSizeSys; $global:step=4.2}
}else{$global:step=6}
}
if ($step - e q 3 ) {
if ($CheckBox4.Checked){
$job= Get-Job | Where { $_.name -eq " Get date " -and $_.State -eq " Completed " }
if ($job.count - e q ( G e t - J o b | W h e r e { $ _ . n a m e - e q " G e t d a t e " } ) . c o u n t ) {
$shrt=0
$global:usrs= $($job | Receive-Job | Sort-Object {$_.LastLogin -as [datetime]} -Descending) 2 > $null; Get-Job | Where { $_.name -eq " Get date " } | Remove-Job -force
if ($usrs){
if ($CheckBox4.CheckState - n e " I n d e t e r m i n a t e " ) { $ s h r t = $ u s r s . C o u n t - 1 0 ; $ u s r s = $ u s r s [ 0 . . 9 ] }
Output $(" `r`nUsers last logget-in " )
Output " `n------------------------------------------------------------------------------- "
$usrs | ForEach {
if ($_.fullname.Length - g t 4 0 ) { $ _ . f u l l n a m e = ( $ _ . f u l l n a m e ) . S u b s t r i n g ( 0 , 3 9 ) + " > " }
Output $(" `n " +(addSp $($(addSp $_.Login 22) + $_.fullname) 62)+$_.LastLogin)
}
if ($shrt - g t 0 ) { O u t p u t " ` n + $ s h r t u s e r s . . " " S l a t e B l u e " }
Output " `n-------------------------------------------------------------------------------`n "
}else{Output " `r`n Can't read C:\Users folder`n " " SaddleBrown " }
$global:step=4.1
}
}else{$global:step=4.1}
}
if ($step - e q 2 . 5 ) {
if (-not $ C h e c k B o x 4 . C h e c k e d ) { $ g l o b a l : s t e p = 3 }
$job= Get-Job | Where { $_.Name -eq " ShowUsr " -and $_.State -eq " Completed " }
if ($job){
Output " `r`nlogged-in user - "
$out= $($job | Receive-Job) 2 > $null; $job | Remove-Job -Force
$out | ForEach {$a=$( $_ -split ';'); Output $a[0] $a[1]}
$global:step=3
}
}
if ($step - e q 2 . 2 ) {
$job= Get-Job | Where { $_.Name -eq " Get Printers " -and $_.State -eq " Completed " }
if ($job.count - e q ( G e t - J o b | W h e r e { $ _ . N a m e - e q " G e t P r i n t e r s " } ) . c o u n t ) {
$printTabl= $($job | Receive-Job)
$job | Remove-Job -Force
$printrs= PrintTabl $printTabl
if ($printrs){PrintersOut $ ( $ p r i n t r s ) }
$global:step=2.5
}
}
if ($step - e q 2 ) {
$job= Get-Job | Where { $_.Name -eq 'Get Printers Invoke' -and $_.State -eq 'Completed'}
if ($job){
$global:printTabl= $($job | Receive-Job)
$job | Remove-Job -Force
if ($printTabl){$printrs= P r i n t T a b l $ p r i n t T a b l } e l s e { G e t P r i n t e r s ; $ g l o b a l : s t e p = 2 . 2 ; r e t u r n }
if ($printrs){PrintersOut $ p r i n t r s }
}
if ( - n o t ( G e t - J o b | W h e r e { $ _ . N a m e - e q ' G e t P r i n t e r s I n v o k e ' } ) ) { $ g l o b a l : s t e p = 2 . 5 }
}
if ($step - e q 1 ) {
if ($os - a n d $ C h e c k B o x 1 . C h e c k e d ) {
$global:step=2
}else{$global:step=2.5}
}
PrProgres
})
function ChkCmp ($comp){
if ( [ s y s t e m . N e t . S o c k e t s . T c p C l i e n t ] : : n e w ( ) . B e g i n C o n n e c t ( $ c o m p , 4 5 5 , $ n u l l , $ n u l l ) . A s y n c W a i t H a n d l e . W a i t O n e ( 1 5 0 , $ f a l s e ) ) { r e t u r n $ t r u e }
$cnt=0; do {$cnt++; if($(ping -4 $comp -n 1 -w 200 | Select-String -Pattern 'TTL=')){return $True}} while ($cnt -lt 4)
}
function GetIP ($cmp){return $([System.Net.Dns]::GetHostAddresses(" $cmp " ) | where {$_.AddressFamily -eq " InterNetwork " } | ForEach {[string]$_}) 2 > $nul}
$ping={ping.exe $compAdr -n 1 -4 -w 300 | Where {$_} | Select-Object -First 1 -Skip 1}
function ChkPrt ($cmp, $prt){[system.Net.Sockets.TcpClient]::new().BeginConnect($cmp,$prt,$null,$null).AsyncWaitHandle.WaitOne(500,$false)}
function ChkOS ($comp){ ((Get-WmiObject -Class Win32_OperatingSystem -ComputerName $comp).name -split" \| " )[0]}
function addSp([string]$word, $len){ for ($i = $word.Length; $i -lt $len; $i++){$word+=" " }; return [string]$word }
function Exclude ($Id) {$a=$True; $excl | ForEach {if (" $Id " -like " *$_* " ){$a=$False}}; return $a}
function Replace ($word) {$repl | ForEach {$word=$word -replace " $_ " ," " }; return $word}
function Hide ($word) {$a=$True; $hide | ForEach { if (" $word " -like " *$_* " ){$a=$False}}; return $a}
function Fltr ($id){
if ($id - l i k e " * \ * " - a n d $ i d - n o t l i k e " ? : \ * " ) {
$id= ($id -split '\\') -replace " ___ " ," "
$id[1]=($id[1] -split " & " )[0..1] -join " & "
return $id[0]+" \ " +$id[1]
} else{ return $id}
}
function Shrt($adUsr){ $adUsrSh=$adUsr; $a=($adUsr.trim() -split ' '); if($a[1] -and $a[2]){$adUsrSh=$a[0]+" " +($a[1])[0]+" . " +($a[2])[0]+" . " }; return $adUsrSh}
function SMBchk ($cmp) {
[system.Net.Sockets.TcpClient]::new().BeginConnect($cmp,445,$null,$null).AsyncWaitHandle.WaitOne(500,$false)
}
function Chek {
Get-Job | Remove-Job -Force
if ($global:CRButton){$global:CRButton.Dispose()}; $ g l o b a l : C R B u t t o n = $ n u l l
2024-03-17 21:55:18 +08:00
ScanButton {Stop} 'Stop'
$ListBox2.Select(0,0)
2024-03-11 22:45:37 +08:00
$global:sum=@()
$global:os=$null
$global:compAdr= ($ListBox2.Text).trim()
if (-not $ g l o b a l : c o m p A d r ) { $ g l o b a l : c o m p A d r = $ e n v : C O M P U T E R N A M E ; $ L i s t B o x 2 . T e x t = $ g l o b a l : c o m p A d r }
$ListBox3.text=" `r`n "
$ip= GetIP $compAdr
$cnt=2; while($cnt) {$cnt--; $a= $(.$ping); Output " $a`r`n " $(if($a -like '*TTL=*'){" green " ; $png=$true}else{" red " })}
if (-not $ i p ) { O u t p u t " ` r ` n C o m p u t e r $ c o m p A d r u n a c c e s s i b l e . . " ; r e t u r n }
2024-03-17 21:55:18 +08:00
if (-not $ p n g ) { 4 4 5 , 3 3 8 9 , 5 9 0 0 , 2 2 , 8 0 , 8 0 8 0 | F o r E a c h { i f ( C h k P r t $ c o m p A d r $ _ ) { $ p n g = $ t r u e ; O u t p u t " P o r t $ _ o p e n ` r ` n " " g r e e n " } } }
2024-03-11 22:45:37 +08:00
if (-not $ p n g ) { O u t p u t " ` r ` n C o m p u t e r $ c o m p A d r u n a c c e s s i b l e . . " ; r e t u r n }
2024-03-15 22:18:04 +08:00
if ($global:compAdr - n e $ e n v : C O M P U T E R N A M E ) {
$global:wrm=(Get-Service -Name WinRM -ComputerName $compAdr).Status
if ($global:wrm - e q ' S t o p p e d ' ) { G e t - S e r v i c e - N a m e W i n R M - C o m p u t e r N a m e $ c o m p A d r | S t a r t - s e r v i c e }
}
2024-03-11 22:45:37 +08:00
if ($CheckBox4.Checked){GetUsers}
PrProgres
GetSizeInvoke
PrProgres
$global:os=ChkOS $compAdr
PrProgres
if ($os - a n d $ C h e c k B o x 1 . C h e c k e d ) { G e t P r i n t e r s I n v o k e }
PrProgres
if ($os - a n d $ C h e c k B o x 4 . C h e c k e d ) { S h o w U s r }
$ListBox3.text=" `r`n "
Output " `n$($os)`n`n "
PrProgres
$dt= ((Get-WmiObject Win32_OperatingSystem -ComputerName $compAdr -ErrorVariable err).LastBootUpTime)
if ($dt){
$curTm= Get-Date -date $(Get-WmiObject -Class Win32_CurrentTime -ComputerName $compAdr | Where {$_.__CLASS -eq 'Win32_LocalTime'} | select Day,Hour,Minute,Month,Year | ForEach {" $($_.Year,$_.Month,$_.Day -join '.') $($_.Hour,$_.Minute -join ':') " })
$dt= Get-Date -date $($dt.Substring(0,4)+'.'+$dt.Substring(4,2)+'.'+$dt.Substring(6,2)+' '+$dt.Substring(8,2)+':'+$dt.Substring(10,2))
$tmUp=$curTm - $dt
if ($dt){Output " S y s t e m b o o t u p d a t e U p t i m e ` r ` n - - - - - - - - - - - - - - - - - - - - � � � � � - - - - - - - - - - - ` r ` n $ ( $ d t . T o S t r i n g ( ' d d M M M y y y y H H : m m ' ) ) $ ( $ t m U p . D a y s ) d $ ( $ t m U p . H o u r s ) : $ ( " { 0 : d 2 } " - f $ t m U p . M i n u t e s ) ` r ` n ` r ` n " }
}
if ($os){
$a= Get-WmiObject win32_logicaldisk -Computername $compAdr | select DeviceID, FreeSpace, Size, VolumeName | Where {$_.Size}
if ($a){
Output " `n�Drive����Size��FreeSpace����Usage���Volume�Name`n------------------------------------------------`n "
$a | ForEach {
$free=$($(100-[int](100*($_.FreeSpace�/�$_.Size)))); $clr=" DarkGreen " ; if($free -ge 80){$clr=" Chocolate " }; if($free -ge 90){$clr=" Crimson " }
Output " ��$($_.DeviceID.PadRight(3, " �" ))�$( " $([int]($_.Size�/�1GB))GB" .PadLeft(8, " �" )) $( " $([int]($_.FreeSpace�/�1GB))GB" .PadLeft(10, " �" )) " ; Output " �$( " $free%" .PadLeft(8, " �" )) " $clr; Output�" ���$($_.VolumeName)`n "
}
Output " ------------------------------------------------`n "
}
}
PrProgres
if ($os - a n d $ C h e c k B o x 3 . C h e c k e d ) { C o m p H w }
PrProgres
if (ChkPrt $ c o m p A d r 3 3 8 9 ) { O u t p u t " ` n R D P p o r t 3 3 8 9 " " D a r k B l u e " }
if (ChkPrt $ c o m p A d r 5 9 0 0 ) { O u t p u t " ` n V N C p o r t 5 9 0 0 " " S e a G r e e n " }
if (ChkPrt $ c o m p A d r 4 4 5 ) { O u t p u t " ` n S M B p o r t 4 4 5 " " M e d i u m V i o l e t R e d " }
if (ChkPrt $ c o m p A d r 2 2 ) { O u t p u t " ` n S S H p o r t 2 2 " " V i o l e t " }
if (ChkPrt $ c o m p A d r 8 0 ) { O u t p u t " ` n H T T P p o r t 8 0 " " D a r k O r a n g e " }
if (ChkPrt $ c o m p A d r 8 0 8 0 ) { O u t p u t " ` n H T T P p o r t 8 0 8 0 " " B l u e " }
if (ChkPrt $ c o m p A d r 1 5 4 1 ) { O u t p u t " ` n 1 C p o r t 1 5 4 1 " " S e a G r e e n " }
if (ChkPrt $ c o m p A d r 1 0 0 5 0 ) { O u t p u t " ` n Z a b b i x p o r t 1 0 0 5 0 " " D a r k V i o l e t " }
PrProgres
Output " `n "
$global:step=1
$timer.Start()
}
function CompHw {
if (-not $ i p ) { r e t u r n }
$hst= ((get-wmiobject -list " StdRegProv " -computername $compAdr -namespace root\default).GetStringValue(2147483650," SOFTWARE\Microsoft\Virtual Machine\Guest\Parameters " ," HostName " )).sValue
$memSum=0; $model=" " ; $memModule=" "
$cpu=(Get-WmiObject -Class CIM_Processor -ComputerName $compAdr).Name | Select-Object -first 1
$cpu=$cpu -replace ' ',' '; $cpu=$cpu -replace ' ',' '; $cpu=$cpu -replace ' ',' ' ;$cpu=$cpu -replace ' ',' '
$cpu=$cpu -replace ' CPU ',' '
$cpu=$cpu -replace 'Intel\(R\) Core\(TM\)2 Duo','Core2Duo'
$cpu=$cpu -replace 'Intel\(R\) Pentium\(R\)','Pentium'
$cpu=$cpu -replace 'Intel\(R\) Core\(TM\)','Core'
$cpu=$cpu -replace 'Intel\(R\) Celeron\(R\)','Celeron'
$cpu=$cpu -replace 'Intel\(R\) Xeon\(R\)','Xeon'
$cpu=$cpu -replace 'Pentium\(R\) Dual-Core','Pentium'
$cpu=$cpu -replace ' with Radeon\(tm\) HD Graphics',''
$cpu=$cpu -replace ' with Radeon Vega Mobile Gfx',''
$cpu=$cpu -replace ' with Radeon Vega Graphics',''
$cpu=$cpu -replace ' @ ',' '
if (" $cpu " - n e " " ) {
$memModule=((Get-WmiObject -Class CIM_PhysicalMemory -ComputerName $compAdr).Capacity | ForEach {$mem=[int]($_*10/1073741824)/10; if($mem -ge 0.5){$mem; $memSum=$memSum+$mem}}) -join ' '
$sys=Get-WmiObject -Class CIM_ComputerSystem -ComputerName $compAdr
$model=$sys.model
$model=(" $model " ).Trim()
$model=$model -replace 'System Product Name','Noname'
$model=$model -replace 'To be filled by O.E.M.','Noname'
$model=$model -replace 'VMware Virtual Platform','VMware'
$cores=$sys.NumberOfLogicalProcessors
$compName=$sys.Name+$(if($sys.Domain){" . " +$sys.Domain})
$hdd=" " ; Get-WmiObject -Class CIM_diskdrive -ComputerName $compAdr | ForEach {if($_.Size -gt 0){$hdd+=[string]($_.Model+" " +[int]($_.Size / (1000000000)))+" GB`r`n " }}
Output " `r`n $(addSp $compName 23) $ip`r`n-------------------------------------------------------`r`n$(addSp " CPU" 15) : $cpu($cores core) `r`n$(addSp " Memory" 15) : $memModule (Sum:$memSum`GB) `r`n$(addSp " Manufacturer" 15) : $model "
$(if($hst){Output " ( " ; Output " $hst " " MediumVioletRed " ; Output " ) " }); Output " `r`n "
if ($hdd){Output " ` r ` n H a r d D i s k D r i v e : " ; O u t p u t " ` r ` n $ h d d " " D a r k B l u e " }
}
}
function ShowUsr {
Start-Job -InputObject " $(1*$CheckBox5.Checked);$compAdr " -Name 'ShowUsr' -ScriptBlock {
$srch = New-Object -TypeName System.DirectoryServices.DirectorySearcher
function Shrt($adUsr){ $adUsrSh=$adUsr; $a=($adUsr.trim() -split ' '); if($a[1] -and $a[2]){$adUsrSh=$a[0]+" " +($a[1])[0]+" . " +($a[2])[0]+" . " }; return $adUsrSh}
$in=" $input " -split ';'
$compAdr=$in[1]
$cnt=0; $job=@(); $act=@(); $usrs=@(); $col=" SaddleBrown "
$getNm={$nm=Shrt ([string]$($srch.Filter = " (&(objectCategory=person)(sAMAccountName=$a)) " ; $srch.FindOne().Properties.displayname) 2 > $null); if($nm){$nm}else{" ($a) " }}
$query=$null
$job = Start-Job -ScriptBlock {Start-Sleep -Milliseconds 4500; Get-Process -ProcessName " quser " | Stop-Process}
$query= quser.exe /SERVER:$compAdr 2 >& 1
$job | Remove-Job -force
if (-not $ q u e r y . T a r g e t O b j e c t - a n d $ q u e r y ) {
$usrs=@(); $act=@(); $list=@(); $col=" SaddleBrown "
$query | Select-Object -Skip 1 | ForEach {
$a=($_ -split " " | Where {$_})[0]
if ($_ - l i k e " * c o n s o l e * " ) { $ a c t + = " $ ( . $ g e t N m ) ( c o n s o l e ) " }
elseif($_ -like " *rdp-tcp* " ){$act+=" $(.$getNm) (rdp) " }
else{$usrs+=$(.$getNm)}
}
}
if ($query.TargetObject - o r - n o t $ q u e r y ) {
$job = Start-Job -ScriptBlock {Start-Sleep -Milliseconds 7500; Get-Process -ProcessName " tasklist " | Stop-Process}
$query= $(tasklist.exe /S $compAdr /FO " CSV " /V /FI " IMAGENAME eq explorer.exe " 2 >& 1 )
$job | Remove-Job -force
if ($query.TargetObject){$err= $ q u e r y . T a r g e t O b j e c t ; $ c o l = " r e d " }
elseif(-not $query){$usrs=" computer not responding " ; $col=" black " }
else{$list=@(); $usrs= $query -replace '" ' | Select-Object -Skip 1 | ForEach {
$qr= $_ -split ','; $indx=5; if($qr.count -gt 7){$indx=6}
$a= ($qr[$indx] -split '\\')[1]
if ($a - n o t i n $ l i s t ) {
$list+=$a
if ($qr[2]){$act+= " $ ( . $ g e t N m ) ( $ ( ( $ q r [ 2 ] - s p l i t ' - ' ) [ 0 ] ) ) " } e l s e { $ ( . $ g e t N m ) }
}
}
if (-not $ a c t - a n d - n o t $ u s r s ) { $ u s r s = " n o b o d y " ; $ c o l = " b l a c k " }
}
}
$cnt=0; $lmt=7; $all=$act.Count+$usrs.Count; if($all -gt 7){$lmt=5};
if (" 1 " - e q $ i n [ 0 ] ) { $ l m t = $ a l l }
$act | ForEach {if($cnt -lt $lmt){" $_`r`n ;SlateBlue " ; $cnt++}}
$usrs | ForEach {if($cnt -lt $lmt){" $_`r`n ;$col " ; $cnt++}}
if ($all-$cnt){" ..+$($all -$cnt)`r`n;SlateBlue " }
" `r`n ;black "
}
}
function GetSizeInvoke {
if (-not $ C h e c k B o x 2 . C h e c k e d ) { r e t u r n }
Start-Job -InputObject " $compAdr " -Name 'System files Invoke' -ScriptBlock {
$compAdr=" $input "
$ScriptBlock= {
$cnt=0
'C:\Windows\Temp','C:\$Recycle.Bin','C:\ProgramData\Microsoft\Diagnosis','C:\ProgramData\Microsoft\Search\Data\Applications\Windows\Windows.edb' | ForEach {
$cnt++;$tmp=" " ; $a=[int](($(Get-ChildItem -Path " $_ " -Recurse -force | ForEach {$_.Length}) 2 > $null | Measure-Object -Sum).Sum / 1MB)
if ($a - g e 5 0 0 - o r $ c n t - l e 2 ) { $ ( " ` n $ _ " ) . P a d R i g h t ( 2 2 , " " ) + $ ( " { 0 : n 0 } " - f $ a + " M B ` n " ) . P a d L e f t ( 9 , " " ) }
}
$fls='C:\hiberfil.sys','C:\pagefile.sys'
$fls | ForEach {
$fl=$_; $tmp=" " ; $a=$(Get-ChildItem -Path 'C:\' -Force | Where {$_.FullName -eq $fl}).Length / 1MB 2 > $null
if ($a - g e 1 ) { $ ( " ` n $ f l " ) . P a d R i g h t ( 2 2 , " " ) + $ ( " { 0 : n 0 } " - f $ a + " M B ` n " ) . P a d L e f t ( 9 , " " ) }
}
}
2024-03-17 21:55:18 +08:00
if ($env:COMPUTERNAME - e q $ c o m p A d r ) { . $ S c r i p t B l o c k }
else{$(Invoke-Command -ComputerName $compAdr -ScriptBlock $ScriptBlock -ErrorVariable err) 2 > $null}
2024-03-11 22:45:37 +08:00
}
Start-Job -InputObject " $compAdr " -Name 'Users files Invoke' -ScriptBlock {
$compAdr=" $input "
2024-03-17 21:55:18 +08:00
$ScriptBlock= {
2024-03-11 22:45:37 +08:00
$fldrs='Downloads;Pictures;Desktop;Videos;Documents;Music;AppData\Local\Temp;AppData\Local\Microsoft\Windows\INetCache;AppData\Local\Google\Chrome\User Data\Default\Cache;AppData\Local\Microsoft\Outlook' -split ';'
$(Get-ChildItem -Path " C:\Users " | Where {$_.Mode -like " d????* " }) 2 > $null | ForEach {
$usrDir=$_.Name
$tmp= $fldrs | ForEach {
$a=[int](($(Get-ChildItem -Path " C:\Users\$usrDir\$_ " -Recurse -Force | ForEach {$_.Length}) 2 > $null | Measure-Object -Sum).Sum / 1MB)
2024-03-17 21:55:18 +08:00
$trhld=100; if($_ -like " *Cache* " ){$trhld= 500}
if ($a - g t $ t r h l d ) { @ { u s r D i r = $ u s r D i r ; D i r = $ _ ; S i z e = $ a } }
2024-03-11 22:45:37 +08:00
}
if ($tmp){$tmp}
}
}
2024-03-17 21:55:18 +08:00
if ($env:COMPUTERNAME - e q $ c o m p A d r ) { . $ S c r i p t B l o c k }
else{$(Invoke-Command -ComputerName $compAdr -ScriptBlock $ScriptBlock -ErrorVariable err) 2 > $null}
2024-03-11 22:45:37 +08:00
}
}
function GetSizeSys {
$global:jobCnt=0
if ($CheckBox2.Checked - a n d ( T e s t - P a t h " \ \ $ c o m p A d r \ c $ \ U s e r s " ) ) {
$Script={
$tmp=" " ; $a=$(($(Get-ChildItem -Path " $input " -Recurse -force | ForEach {$_.Length}) 2 > $null | Measure-Object -Sum).Sum / 1MB)
$(" `nC:\Windows\Temp " ).PadRight(22," " )+$(" {0:n0} " -f $a+" MB`n " ).PadLeft(9," " )
}
Start-Job -InputObject " \\$compAdr\c$\Windows\Temp " -ScriptBlock $Script -Name 'System files'
$Script={
$tmp=" " ; $a=$(($(Get-ChildItem -Path " $input " -Recurse -force | ForEach {$_.Length}) 2 > $null | Measure-Object -Sum).Sum / 1MB)
if ($a - g e 1 G B ) { $ ( " ` n C : \ P r o g r a m D a t a \ M i c r o s o f t \ D i a g n o s i s " ) . P a d R i g h t ( 3 6 , " " ) + $ ( " { 0 : n 0 } " - f $ a + " M B ` n " ) . P a d L e f t ( 9 , " " ) }
}
Start-Job -InputObject " \\$compAdr\c$\ProgramData\Microsoft\Diagnosis " -ScriptBlock $Script -Name 'System files'
$Script={
$tmp=" " ; $a=$(Get-ChildItem -Path " $input " -Force | Where {$_.Name -eq 'hiberfil.sys'}).Length / 1MB 2 > $null
if ($a - g e 1 ) { $ ( " ` n C : \ h i b e r f i l . s y s " ) . P a d R i g h t ( 2 2 , " " ) + $ ( " { 0 : n 0 } " - f $ a + " M B ` n " ) . P a d L e f t ( 9 , " " ) }
}
Start-Job -InputObject " \\$compAdr\c$ " -ScriptBlock $Script -Name 'System files'
$Script={
$tmp=" " ; $a=$(Get-ChildItem -Path " $input " -Force | Where {$_.Name -eq 'pagefile.sys'}).Length / 1MB 2 > $null
$(" `nC:\pagefile.sys " ).PadRight(22," " )+$(" {0:n0} " -f $a+" MB`n " ).PadLeft(9," " )
}
Start-Job -InputObject " \\$compAdr\c$ " -ScriptBlock $Script -Name 'System files'
$Script={
$tmp=" " ; $a=$(($(Get-ChildItem -Path " $input " -Recurse -force | ForEach {$_.Length}) 2 > $null | Measure-Object -Sum).Sum / 1MB)
$(" `nC:\`$Recycle.Bin " ).PadRight(22," " )+$(" {0:n0} " -f $a+" MB`n " ).PadLeft(9," " )
}
Start-Job -InputObject " \\$compAdr\c$\`$Recycle.Bin " -ScriptBlock $Script -Name 'System files'
$Script={
$tmp=" " ; $a=($(Get-ChildItem -Path " $input " -force) 2 > $null ).Length / 1MB
if ($a - g e 1 0 2 4 ) { " ` n C : \ P r o g r a m D a t a \ M i c r o s o f t \ S e a r c h \ D a t a \ A p p l i c a t i o n s \ W i n d o w s \ W i n d o w s . e d b " + $ ( " { 0 : n 0 } " - f $ a + " M B ` n " ) . P a d L e f t ( 9 , " " ) }
}
Start-Job -InputObject " \\$compAdr\c$\ProgramData\Microsoft\Search\Data\Applications\Windows\Windows.edb " -ScriptBlock $Script -Name 'System files'
}
}
function GetUsers {
$usrDir=@()
if (SMBchk $ c o m p A d r ) { i f ( T e s t - P a t h " \ \ $ c o m p A d r \ C $ \ U s e r s " ) { G e t - C h i l d I t e m - P a t h " \ \ $ c o m p A d r \ C $ \ U s e r s \ " - D i r e c t o r y - n a m e - E x c l u d e $ e x l d | F o r E a c h { $ u s r D i r + = @ ( $ _ ) } } }
$Script={
$usrDir= @($input)
$srch = New-Object -TypeName System.DirectoryServices.DirectorySearcher
$usrDir | ForEach {
$usr=($_ -split '\\')[-1]; $acces=" " ; $adu=@()
$acces=$(((Get-ChildItem -Path " $_\AppData\Local\Temp " -force).LastAccessTime | Sort-Object {$_ -as [datetime]} -Descending)[0].ToString('dd.MM.yyyy')) 2 > $null
if (-not $ a c c e s ) { $ a c c e s = $ ( ( ( G e t - C h i l d I t e m - P a t h " $ _ \ N T U S E R . D A T " - f o r c e ) . L a s t W r i t e T i m e ) . T o S t r i n g ( ' d d . M M . y y y y ' ) ) 2 > $ n u l l }
$adu= $($srch.Filter = " (&(objectCategory=person)(sAMAccountName=$usr)) " ; $srch.FindOne()).Properties 2 > $null
if (-not $ a d u - a n d $ a c c e s ) {
$sid=$(((Get-Acl " $_\NTUSER.DAT " ).Sddl -split 'G:')[0] -replace 'O:','') 2 > $null
if ($sid){$adu= $ ( $ s r c h . F i l t e r = " ( & ( o b j e c t C a t e g o r y = p e r s o n ) ( o b j e c t S I D = $ s i d ) ) " ; $ s r c h . F i n d O n e ( ) ) . P r o p e r t i e s 2 > $ n u l l }
}
@ {Login=$usr;fullname=$adu.displayname;LastLogin=$acces;DistinguishedName=[string]$adu.distinguishedname;Enabled=-not [bool]($($adu[" useraccountcontrol " ]) -band 0x000002)}
}
}
$jobCnt=[int]($usrDir.Count/40)+1
$usrsCount=[int](($usrDir.Count/$jobCnt)+.5)
$a=@()
if ($usrDir - n e $ n u l ) {
$usrDir | ForEach {
$a+=" \\$compAdr\C$\Users\$_ "
if ($a.Count - g e $ u s r s C o u n t ) { $ a | S t a r t - J o b - S c r i p t B l o c k $ S c r i p t - N a m e " G e t d a t e " ; $ a = @ ( ) }
}
if ($a){$a | S t a r t - J o b - S c r i p t B l o c k $ S c r i p t - N a m e " G e t d a t e " }
}
}
function GetPrintersInvoke {
Start-Job -InputObject " $compAdr " -Name 'Get Printers Invoke' -ScriptBlock {
Invoke-Command -ComputerName " $input " -ScriptBlock {
function GetIP ($cmp){return $([System.Net.Dns]::GetHostAddresses(" $cmp " ) | where {$_.AddressFamily -eq " InterNetwork " } | ForEach {[string]$_}) 2 > $nul}
$pth= 'SYSTEM\ControlSet001\Control\Print\Monitors'
$key1=" Ports " ," $pth\Standard TCP/IP Port\Ports " ," HostName "
$key2=" Ports " ," $pth\HP Standard TCP/IP Port\Ports " ," IPAddress "
$key3=" Ports " ," $pth\Advanced TCP/IP Port Monitor\Ports " ," IPAddress "
$key4=" Ports " ," $pth\WSD Port\Ports " ," Printer UUID "
$pth= 'SOFTWARE\Microsoft\Windows NT\CurrentVersion\Print'
$key5=" Printers " ," $pth\Printers " ," port "
$key6=" UsrPrinters " ," $pth\Providers\Client Side Rendering Print Provider " ," Printers\Connections "
$gtReg= {(Get-ChildItem -Path " HKLM:\$pth\$pth2 " ).PSChildName 2 > $null}
$key1,$key2,$key3,$key4,$key5 | foreach {
$class=$_[0]; $pth=$_[1]; $vl=$_[2];$pth2=''
.$gtReg | Where {$_} | Where {$_ -notlike " *:OneNote* " } | ForEach {
2024-03-12 16:49:38 +08:00
$prt=$_;$pth2=" $prt\ " ; $prtIP=''; $prtIP=(get-ItemProperty " HKLM:\$pth\$pth2 " ).$vl
2024-03-11 22:45:37 +08:00
$ip=''; if($prtIP -notmatch '^\ d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$'){ $ip= GetIP $prtIP}
@ {Class=$class; Name=$prt;Value=$prtIP; IP=$ip}
}
}
$pth=$key6[1];$class=$key6[0];$vl=$key6[2];$pth2=''
.$gtReg | Where {$_ -notlike " *:OneNote* " } | Where {$_}| ForEach {$name=$_;$pth2=" $_\$vl " ; $prnr= .$gtReg; if($prnr -or $name){@{Class=$class; Name=$name; Value=$prnr}}}
}
}
}
function GetPrinters {
$compName=$compAdr
$reg1='get-wmiobject -list " StdRegProv " -computername $compAdr -namespace root\default'
$reg2='(($reg1).EnumKey(2147483650," $key " )).snames'
$key1=" Ports " ," SYSTEM\ControlSet001\Control\Print\Monitors\Standard TCP/IP Port\Ports\ " ,'(($reg1).GetStringValue(2147483650," $($key+ " \" +$_) " ," HostName " )).sValue',$compAdr
$key2=" Ports " ," SYSTEM\ControlSet001\Control\Print\Monitors\HP Standard TCP/IP Port\Ports\ " ,'(($reg1).GetStringValue(2147483650," $($key+ " \" +$_) " ," IPAddress " )).sValue',$compAdr
$key3=" Ports " ," SYSTEM\ControlSet001\Control\Print\Monitors\Advanced TCP/IP Port Monitor\Ports\ " ,'(($reg1).GetStringValue(2147483650," $($key+ " \" +$_) " ," IPAddress " )).sValue',$compAdr
$key4=" Ports " ," SYSTEM\ControlSet001\Control\Print\Monitors\WSD Port\Ports " ,'(($reg1).GetStringValue(2147483650," $($key+ " \" +$_) " ," Printer UUID " )).sValue',$compAdr
$key5=" Printers " ," SOFTWARE\Microsoft\Windows NT\CurrentVersion\Print\Printers\ " ,'(($reg1).GetStringValue(2147483650," $($key+ " \" +$_) " ," Port " )).sValue',$compAdr
$key6=" UsrPrinters " ," SOFTWARE\Microsoft\Windows NT\CurrentVersion\Print\Providers\Client Side Rendering Print Provider\ " ,'(($reg1).EnumKey(2147483650,(" $($key+$_+ " \Printers\Connections" ) " ))).sNames',$compAdr
$out=@();
$Script={
$inpt=@($input); $class=$inpt[0]; $key=$inpt[1]; $code=$inpt[2];$compAdr=$inpt[3]
function Get-Reg ($code){Invoke-Expression $ExecutionContext.InvokeCommand.ExpandString($code)}
$reg1='get-wmiobject -list " StdRegProv " -computername $compAdr -namespace root\default'
$reg2='(($reg1).EnumKey(2147483650," $key " )).snames'
Get-Reg $reg2 | foreach {$vl=Get-Reg $code; @{CompName=$compAdr;Name=$_; Value=$vl; Class=$class}} #) 2 > $nul
}
$key1,$key2,$key3,$key4,$key5,$key6 | foreach { $_ | Start-Job -ScriptBlock $Script -Name " Get Printers " }
}
function PrintTabl ($printTabl){
$srch = New-Object -TypeName System.DirectoryServices.DirectorySearcher
$printersOut=@()
$printTabl | Where {$_.Class -eq " Printers " } | foreach {
$prName=$null; $Port=$null; $prPort=$null; $dhcpName=$null; $prName=$_.Name; $prPort=$_.Value
if ($prPort){
if ($prPort - l i k e " U S B * " - o r $ p r P o r t - l i k e " D O T 4 _ 0 * " - o r $ p r P o r t - l i k e " C N M * " ) { " $ p r N a m e ; U S B " }
else{
$Port= $printTabl | Where {$_.Class -eq " Ports " -and $_.Name -eq $prPort};
if ($Port){
$prPort= $Port.Value;
if ($Port.Name - l i k e " W S D - * " ) {
$a=''; $reg= 'LocalMachine'," SYSTEM\CurrentControlSet\Enum\SWD\DAFWSDProvider\uuid:$($Port.Name) " ,'LocationInformation'
$reg2= 'LocalMachine'," SYSTEM\CurrentControlSet\Enum\SWD\DAFWSDProvider\urn:uuid:$($Port.Name) " ,'LocationInformation'
$reg, $reg2 | ForEach {if(-not $a){$a= $([Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey($_[0], $compName).OpenSubKey($_[1], $true).GetValue($_[2])) 2 > $null}}
if ($a){$prPort= " W S D : " + ( $ a - r e p l a c e ' h t t p : / / ' - s p l i t ' : ' ) [ 0 ] ; i f ( $ a - l i k e " * ` ` [ * : : * ] * " ) { $ p r P o r t = " W S D : " + ( $ a - r e p l a c e ' h t t p : / / \ [ ' - s p l i t ' ] : ' ) [ 0 ] } } e l s e { $ p r P o r t = $ P o r t . N a m e }
}
" $prName;$prPort;$($Port.IP) "
}
}
}
}
$printersSort=@()
$printTabl | Where {$_.Class -eq " UsrPrinters " -and $_.Value -ne $nul} | foreach {
$sid=$_.Name; $adUser=$nul; $adUser= [string]$($srch.Filter = " (&(objectCategory=person)(objectSID=$sid)) " ; $srch.FindOne()).Properties.displayname 2 > $null
if ($adUser){$_.Value | F o r E a c h { $ p r i n t e r s S o r t + = " $ ( S h r t $ a d U s e r ) ; $ ( $ _ - r e p l a c e ' , ' , ' \ ' ) " } }
}
$printersSort | Sort-Object | Get-Unique | foreach {$a=($_ -split ';'); $a[1]+" ; " +$a[0]}
}
function PrintersOut ($printersOut){
$compName=(@($printersOut)[0] -split ';')[0]
$compCol=" Red " ; if (($printersOut[0] -split ';')[1]){$compCol=" Green " };
Output " `r`n`r`nPrinters "
Output " `n------------------------------------------------------------------------`n "
$printersOut | foreach {
$a=($_ -split ';')
$clr=" Blue " ; if([string]$a[0] -like '\\*'){$clr=" black " }
$a[0]=$a[0] -replace 'LaserJet','LJ'
$a[0]=$a[0] -replace 'Professional','Pro'
if ($a[0].Length - g t 4 3 ) { $ a [ 0 ] = $ a [ 0 ] . S u b s t r i n g ( 0 , 4 2 ) + " > " }
Output $(addSp $a[0] 45) $clr
Output $(addSp $a[1] 17); Output $($a[2]) $clr; Output " `n "
}
Output " ------------------------------------------------------------------------`n "
}
function PrintOut ($dev){
$list=@(); $ListBox3.text=" `r`n "
$cl=@(); $($dev.Class | ForEach { if($_ -notin $cl){$cl+=$_; $_}}) | ForEach {
$Class=$_
$dev | Where {$_.Class -eq $Class} | Where {Hide $_.FriendlyName} | Sort-Object {$_.FriendlyName} | ForEach-Object{
$Id=" " ; if( (exclude $_.InstanceId) ){$Id= $_.InstanceId}
$list+=@{Class=$Class;dev=(" " +(addSp (Replace $_.FriendlyName) 24)+" " )+" ; " +(Fltr $ID)+" `r`n " }
}
}
If (-not($global:list)){$global:list= $ l i s t }
$list.Class | Get-Unique | ForEach {
$Class=$_; $out=@();$outOff=@(); $dev=@()
txt " $Class`r`n$sprtr`r`n "
$dev= ($list | Where {$_.Class -eq $Class}).dev
( $global:list | Where {$_.Class -eq $Class}) .dev | ForEach {if ($_ -in $dev){$Out+=$_}else{$outOff+=$_}}
$out | ForEach {$a=$_ -split " ; " ; Output $a[0] " blue " ; Output $a[1] " green " }
$dev | Where { $_ -notin $Out} | ForEach {$a=$_ -split " ; " ; Output $a[0] " blue " $fontBold ; Output $a[1] " green " $font}
$outOff | ForEach {$a=$_ -split " ; " ; Output $a[0] " red " ; Output $a[1] " green " }
txt " `r`n "
}
txt " `r`n`r`n " ;
$ListBox3.SelectionStart=0
$global:list=$list
}
function ClrRecycle {
$code='$comp=" '+ " $compAdr" +' "
2024-03-17 21:55:18 +08:00
2024-03-11 22:45:37 +08:00
$ScriptBlock= {
2024-03-18 15:18:01 +08:00
function txt ($txt){ Write-Host $txt -n}
2024-03-17 21:55:18 +08:00
if (-not$dir){$dir= " $ I n p u t " }
2024-03-18 15:18:01 +08:00
$GetDir={$(ls -Path $dir -Force | Where {$_.Attributes -like " *Directory* " -and $_.Attributes -notlike " *ReparsePoint* " }) | ForEach {$_.FullName}}
2024-03-17 21:55:18 +08:00
function GetFile ($dir){
2024-03-18 15:18:01 +08:00
ls -Path $dir -Force | Where {$_.Attributes -notlike " *Directory* " -and $_.Attributes -notlike " *ReparsePoint* " } | select Length,LastWriteTime,FullName
.$GetDir | ForEach {GetFile $_}
2024-03-17 21:55:18 +08:00
}
2024-03-18 15:18:01 +08:00
cls ; $mnth=2; $expr= (Get-Date).AddMonths(-$mnth);
txt " `n`n Script run on $env:COMPUTERNAME`n "
txt " `n`n Clean directory by delete files older than $mnth month `n`n Folder - $dir Scan.. "
$fl= $(GetFile $dir) 2 > $null; txt " .. "
if (-not $ f l . c o u n t ) { r e t u r n $ f a l s e }
$all= [int]$((($fl | Where {$_.Length} | ForEach {$_.Length}) | Measure-Object -Sum).Sum / 1MB)
$del= $fl | Where {$_.LastWriteTime -le $expr}
$old= [int]$((( $del | ForEach {$_.Length}) | Measure-Object -Sum).Sum / 1MB)
2024-03-11 22:45:37 +08:00
$prcnt=" {0:P0} " -f ($old/(1+$all))
2024-03-18 15:18:01 +08:00
txt " . Done `n`n Folder $dir, size - $all MB`n "
txt " `r Files to delete - $(( " {0:n0}" -f $old+ " MB" ).PadLeft(9, " " )), $($del.Count) files ($prcnt)`n "
if ($old){$txt = " ` n C l e a n $ d i r f o l d e r ? n "
$ask= " `nAre you sure you want to proceed?`n "
$a=" Management.Automation.Host.ChoiceDescription "
$answr= New-Object Collections.ObjectModel.Collection[$a]
$answr.Add((New-Object $a -ArgumentList " &Yes " ))
$answr.Add((New-Object $a -ArgumentList " &No " ))
$do= $Host.UI.PromptForChoice($txt, $ask,$answr, 0)
if ($do - e q 0 ) {
txt " `n`n Execute deleting files... "
$time= Measure-Command {$($del | ForEach-Object { Remove-Item $_.FullName -Force}) 2 > $null}
txt " .. Done in $([int]$time.TotalSeconds) seconds `n "
txt " `n`n Delete empty folders... "
function ChkFldr ($dir){if($(ls -Path $dir -Recurse -Force | Where {$_.Mode -like " -????* " }) 2 > $null){$true; return};$false}
function DelFldr ($dir){if(ChkFldr $dir){.$GetDir | ForEach {DelFldr $_}}else{$(Remove-Item $_ -Force -Recurse) 2 > $null}}
.$GetDir | ForEach {DelFldr $_}
Write-Host " .. Done`n "
$all= [int]$((($(ls -Path $dir -File -Recurse -Force) 2 > $null | Where {$_.Length} | ForEach {$_.Length}) | Measure-Object -Sum).Sum / 1MB)
txt " `n Folder $dir, size - $all MB`n "
}else{txt " `n Abort!`n`n " }
}
return " OK "
2024-03-11 22:45:37 +08:00
}
$dir= " C:\`$Recycle.Bin "
$out=$(Invoke-Command -ComputerName $comp -ScriptBlock $ScriptBlock -InputObject $dir) 2 > $null
if ($out - n e " O K " ) {
$err=$null
$dir= " \\$comp\C$\`$Recycle.Bin "
$err; timeout 3 > $null
2024-03-17 21:55:18 +08:00
$(.$ScriptBlock) 2 > $null
2024-03-11 22:45:37 +08:00
}
2024-03-18 15:18:01 +08:00
Write-Host " `n -= Press any key =- `n "
2024-03-11 22:45:37 +08:00
timeout 300 > $null
2024-03-18 15:18:01 +08:00
'
2024-03-11 22:45:37 +08:00
Start-Process cmd -ArgumentList " /C powershell.exe -EncodedCommand $([Convert]::ToBase64String([System.Text.Encoding]::Unicode.GetBytes($code))) "
}
function GetDev ($comp){
$class=" Win32_OperatingSystem " ," Win32_VideoController " ," Win32_DesktopMonitor " ," Win32_DiskDrive " ," Win32_Share " ," Win32_IDEController " ," Win32_SoundDevice " ," Win32_Processor " ," Win32_USBController " ," Win32_USBControllerDevice " ," Win32_USBHub " ," Win32_Printer " ," Win32_NetworkAdapter "
$dev=@();txt " `r`n`r`n`r`n "
$class | ForEach {
$clss=$_ -replace " Win32_ " ," " ; Get-WmiObject -Class $_ -ComputerName $comp | Where {$_.PhysicalAdapter -or $_.SpoolEnabled -or $_.Status -eq " OK " } | Select Name, PNPDeviceID, Model, Path, Size | ForEach {
if ($clss - l i k e " U S B * " ) { $ c l s s = " U S B " }
if ($clss - e q " S h a r e " ) { $ _ . P N P D e v i c e I D = $ _ . P a t h }
if ($clss - e q " O p e r a t i n g S y s t e m " ) { $ _ . n a m e = ( $ _ . n a m e - s p l i t " \ | " ) [ 0 ] }
if ($clss - e q " D i s k D r i v e " ) { $ _ . N a m e = $ _ . M o d e l ; $ _ . P N P D e v i c e I D = " " ; i f ( $ _ . S i z e - g t 0 ) { $ _ . P N P D e v i c e I D = " $ ( [ i n t ] ( $ _ . S i z e / ( 1 0 0 0 0 0 0 0 0 0 ) ) ) " + " G B " } }
@ {FriendlyName=$_.Name; InstanceId=$_.PNPDeviceID; Class=$clss}
if ($clss - e q " P r o c e s s o r " ) { @ { F r i e n d l y N a m e = ( G e t - W m i O b j e c t - C l a s s C I M _ C o m p u t e r S y s t e m - C o m p u t e r N a m e $ c o m p ) . m o d e l ; I n s t a n c e I d = " " ; C l a s s = " M a n u f a c t u r e r " } }
}
}
Get-WmiObject -Class Win32_PnPEntity -ComputerName $comp | Select Name, PNPDeviceID, Manufacturer | ForEach {
if ($_.name - l i k e " * ( C O M * " ) { @ { F r i e n d l y N a m e = $ _ . N a m e ; I n s t a n c e I d = $ _ . P N P D e v i c e I D ; C l a s s = " C o m P o r t s " } }
if ($_.Manufacturer - e q $ n u l - a n d $ _ . P N P D e v i c e I D - n o t l i k e " R O O T \ L E G A C Y * " ) { @ { F r i e n d l y N a m e = $ _ . N a m e ; I n s t a n c e I d = $ _ . P N P D e v i c e I D ; C l a s s = " U n k n o w D e v i c e s " } }
}
}
function Device ($comp){
Get-Job | Remove-Job -Force
$compAdr= ($ListBox2.Text).trim()
if (-not $ c o m p A d r ) { $ c o m p A d r = $ e n v : C O M P U T E R N A M E ; $ L i s t B o x 2 . T e x t = $ c o m p A d r }
$ListBox3.text=" `r`n "
$ip=GetIP $compAdr
if ($lstcmp - n e $ c o m p A d r ) { $ g l o b a l : l i s t = @ ( ) ; $ g l o b a l : l s t c m p = $ c o m p A d r }
$cnt=2; while($cnt) {$cnt--; $a= $(.$ping); Output " $a`r`n " $(if($a -like '*TTL=*'){" green " ; $png=$true}else{" red " })}
if (-not $ p n g ) { t x t " ` r ` n C o m p u t e r $ c o m p A d r u n a c c e s s i b l e . . " ; r e t u r n }
$os=ChkOS $compAdr
Output " `n$($os)`n`n "
$dev=@(); $dev+=@{FriendlyName=$os; Class=" OperatingSystem " }
if ($dev){PrintOut ( G e t D e v $ c o m p A d r ) }
else{txt " `r`nComputer $compAdr unaccessible.. " }
}
$Form = New-Object System.Windows.Forms.Form
$Form.Size = New-Object System.Drawing.Size(687,842)
$Form.Text =" ScanPC "
$Form.MaximizeBox = $true
$Form.MinimizeBox = $true
$Form.SizeGripStyle = [System.Windows.Forms.SizeGripStyle]::Hide
$Form.BackColor = " #c0c0c0 "
$Form.ShowIcon = $true
$Form.MaximumSize = @{Width=1300; Height=900}
$Form.MinimumSize = @{Width=400; Height=500}
$Form.WindowState = " Normal "
$Form.Opacity = 1.0
$Form.TopMost = $false
$ListBox2 = New-Object System.Windows.Forms.TextBox
$ListBox2.Location = New-Object System.Drawing.Size(2,2)
$ListBox2.Size = New-Object System.Drawing.Size(190,16)
$ListBox2.Text=$comp
$ListBox2.Font = " Courier New,10 "
$ListBox2.WordWrap = $False
$ListBox2.AllowDrop = $True
$ListBox2.Anchor='Top,Left'
$Form.Controls.Add($ListBox2)
$cntxtMenu = New-Object System.Windows.Forms.ContextMenuStrip
$cntxtMenu.Items.Add(" Copy " ).add_Click({ $ListBox3.Copy() })
$ListBox3 = New-Object System.Windows.Forms.RichTextBox
$ListBox3.Location = New-Object System.Drawing.Point(2,26)
$ListBox3.Size = New-Object System.Drawing.Size(665,770)
$ListBox3.Text=$help
$ListBox3.MultiLine = $True
$ListBox3.DetectUrls = $false
$ListBox3.Font = " Courier New,10 "
$ListBox3.ReadOnly = $true
$ListBox3.WordWrap = $False
$ListBox3.ScrollBars = " Vertical "
$ListBox3.ReadOnly = $True
$ListBox3.AllowDrop = $True
$ListBox3.Anchor='Top,Left,Bottom,Right'
$ListBox3.ContextMenuStrip = $cntxtMenu
$ListBox3.ShortcutsEnabled = $false
$Form.Controls.Add($ListBox3)
$font=$ListBox3.Font
$fontBold = New-Object Drawing.Font($font.FontFamily, $font.Size, [Drawing.FontStyle]::Bold)
$Label = New-Object System.Windows.Forms.label
$Label.Location = New-Object System.Drawing.Size(595,3)
$Label.Size = New-Object System.Drawing.Size(100,16)
$Label.Text = " "
$Label.Anchor='Top,Right'
$Label.Font = New-Object Drawing.Font(" Terminal " ,12, [Drawing.FontStyle]::Bold) #Regular
$Form.Controls.Add($Label)
$DeviceButton = New-Object System.Windows.Forms.Button
$DeviceButton.Location = New-Object System.Drawing.Point(200,4)
$DeviceButton.Size = New-Object System.Drawing.Size(60,20)
$DeviceButton.Text = 'Devices'
$DeviceButton.Add_Click({Device})
$form.Controls.Add($DeviceButton)
2024-03-17 21:55:18 +08:00
function ScanButton ($clk,$txt) {
$Button = New-Object System.Windows.Forms.Button
$Button.Location = New-Object System.Drawing.Point(280,4)
$Button.Size = New-Object System.Drawing.Size(60,20)
$Button.Text = $txt
$Button.Add_Click($clk)
if ($ScanButton){$global:ScanButton.Dispose(); $ g l o b a l : S c a n B u t t o n = $ n u l l }
$global:ScanButton=$Button
$global:form.Controls.Add($global:ScanButton)
}
ScanButton {Chek} 'Scan'
2024-03-11 22:45:37 +08:00
$CheckBox1 = New-Object System.Windows.Forms.CheckBox
$CheckBox1.Location = New-Object System.Drawing.Size(345,5)
$CheckBox1.Size = New-Object System.Drawing.Size(50,16)
$CheckBox1.Text = " Print "
$Form.Controls.Add($CheckBox1)
$CheckBox2 = New-Object System.Windows.Forms.CheckBox
$CheckBox2.Location = New-Object System.Drawing.Size(400,5)
$CheckBox2.Size = New-Object System.Drawing.Size(45,16)
$CheckBox2.Text = " Size "
$Form.Controls.Add($CheckBox2)
$CheckBox3 = New-Object System.Windows.Forms.CheckBox
$CheckBox3.Location = New-Object System.Drawing.Size(450,5)
$CheckBox3.Size = New-Object System.Drawing.Size(50,16)
$CheckBox3.Text = " HW "
$Form.Controls.Add($CheckBox3)
$CheckBox4 = New-Object System.Windows.Forms.CheckBox
$CheckBox4.Location = New-Object System.Drawing.Size(500,5)
$CheckBox4.Size = New-Object System.Drawing.Size(50,16)
$CheckBox4.ThreeState = $True
$CheckBox4.Text = " Usr "
$CheckBox4.Checked=0
$Form.Controls.Add($CheckBox4)
function ShCRButton ($in){
if ($global:CRButton){$global:CRButton.Dispose()}; $ g l o b a l : C R B u t t o n = $ n u l l
$sz= (($in | Select-String 'Recycle.Bin' -SimpleMatch) -split '' | Where {$_ -match '\d'}) -join ''
if (500 - l e $ s z ) {
$CRButton = New-Object System.Windows.Forms.Button
$CRButton.Location = New-Object System.Drawing.Point(550,3)
$CRButton.Size = New-Object System.Drawing.Size(30,20)
$CRButton.Text = 'CR'
$CRButton.Add_Click({ClrRecycle})
$global:CRButton=$CRButton
$Form.Controls.Add($global:CRButton)
}
}
$Form.Add_Shown({$Form.Activate(); $DeviceButton.focus()})
[void] $Form.ShowDialog()
[Console.Window]::ShowWindow(( $consolePtr = [Console.Window]::GetConsoleWindow()), 4)