Ils se pourraient que ces articles t interessent plus que les autres

Powershell : Ranger votre bureau

Imagine-toi que tu peux ranger tout le bordel qu’il y a sur ton bureau d’ordinateur juste en exécutant un script 💙
Ouvrez Powershell puis coller le code ci-dessous :

$pathToUse = "C:\Users\$env:username\Desktop"
$video = @(
'3g2','3gp','3gpp','asf','avi','divx','f4v',
'flv','h264','ifo','m2ts','m4v','mkv','mod','mov',
'mp4','mpeg','mpg','mswmm','mts','mxf','ogv','rm',
'srt','swf','ts','vep','vob','webm','wlmp','wmv'
)
$spreadsheets = @(
'csv','ods','xls','xlsx'
)
$images = @(
'arw','bmp','cr2','crw','dcm','dds','djvu','djvu',
'dmg','dng','fpx','gif','ico','ithmb','jp2','jpeg',
'jpg','nef','nrw','orf','pcd','pict','png','psd',
'sfw','tga','tif','tiff','webp','xcf'
)
$presentations = @(
'key','odp','pps','ppsx''ppt','pptm','pptx'
)
$docs = @(
'chm','doc','docm','docx','dot','dotx','eml','eps',
'hwp','log','m3u','odt','pages','pdf','pub','rtf',
'sxw','txt','wpd',' wps','xml','xps'
)
$cadFiles = @(
'dwg','dxf'
)
$misc = @(
'bin','cda','dat','dll','exe','isc',
'img','inf','ipa','kmz','lnk','pes',
'ps','rem','torrent','ttf','vcf'
)
$ebooks = @(
'azw','azw3','epub','fb2''lit','lrf','mbp','mobi',
'opf','prc'
)
$web = @(
'css','htm','html','js','json','php'
)
$arcs = @(
'7z','apk','bz2','cbr','gz','gzip','jar','rar',
'tar','tgz','zip','war'
)
$scripts = @(
'bat','cmd','vb','vbs','vbe','js',
'jse','ws','wsf','wsc','wsh','ps1',
'ps1xml','ps2','ps2xml','psc1','psc2','sql'
)
$files = Get-ChildItem -Path $pathToUse
Foreach ($x in $files){
if($docs.Contains($x.Extension.TrimStart('.').ToLower())){
New-Item -ItemType Directory -Path $pathToUse -Name "Documents" -ErrorAction Ignore
Move-Item -Path $x.FullName -Destination $pathToUse/"Documents"
}
elseif($spreadsheets.Contains($x.Extension.TrimStart('.').ToLower())){
New-Item -ItemType Directory -Path $pathToUse -Name "Feuilles de calcul" -ErrorAction Ignore
Move-Item -Path $x.FullName -Destination $pathToUse/"Feuilles de calcul"
}
elseif($images.Contains($x.Extension.TrimStart('.').ToLower())){
New-Item -ItemType Directory -Path $pathToUse -Name "Images" -ErrorAction Ignore
Move-Item -Path $x.FullName -Destination $pathToUse/"Images"
}
elseif($presentations.Contains($x.Extension.TrimStart('.').ToLower())){
New-Item -ItemType Directory -Path $pathToUse -Name "Présentations" -ErrorAction Ignore
Move-Item -Path $x.FullName -Destination $pathToUse/"Présentations"
}
elseif($video.Contains($x.Extension.TrimStart('.').ToLower())){
New-Item -ItemType Directory -Path $pathToUse -Name "Vidéos" -ErrorAction Ignore
Move-Item -Path $x.FullName -Destination $pathToUse/"Vidéos"
}
elseif($cadFiles.Contains($x.Extension.TrimStart('.').ToLower())){
New-Item -ItemType Directory -Path $pathToUse -Name "Fichiers CAD" -ErrorAction Ignore
Move-Item -Path $x.FullName -Destination $pathToUse/"Fichiers CAD"
}
elseif($misc.Contains($x.Extension.TrimStart('.').ToLower())){
New-Item -ItemType Directory -Path $pathToUse -Name "Divers" -ErrorAction Ignore
Move-Item -Path $x.FullName -Destination $pathToUse/"Divers"
}
elseif($ebooks.Contains($x.Extension.TrimStart('.').ToLower())){
New-Item -ItemType Directory -Path $pathToUse -Name "E-Books" -ErrorAction Ignore
Move-Item -Path $x.FullName -Destination $pathToUse/"E-Books"
}
elseif($web.Contains($x.Extension.TrimStart('.').ToLower())){
New-Item -ItemType Directory -Path $pathToUse -Name "Web" -ErrorAction Ignore
Move-Item -Path $x.FullName -Destination $pathToUse/"Web"
}
elseif($arcs.Contains($x.Extension.TrimStart('.').ToLower())){
New-Item -ItemType Directory -Path $pathToUse -Name "Archives" -ErrorAction Ignore
Move-Item -Path $x.FullName -Destination $pathToUse/"Archives"
}
elseif($scripts.Contains($x.Extension.TrimStart('.').ToLower())){
New-Item -ItemType Directory -Path $pathToUse -Name "Scripts" -ErrorAction Ignore
Move-Item -Path $x.FullName -Destination $pathToUse/"Scripts"
}
elseif($x.Directory){
New-Item -ItemType Directory -Path $pathToUse -Name "Autres - divers" -ErrorAction Ignore
Move-Item -Path $x.FullName -Destination $pathToUse/"Autres - divers"
}
else{
Write-Host $x
}
}
new desktop

Vous pouvez également exécuter le script si vous ne souhaitez pas copier/coller, cependant la permission d’exécution de script est nécessaire.

Bravo : Vous avez réussi ! Alors le bureau ?😎😎😎

Partagez cet article sur vos réseaux !

Je ne suis plus confiné, Fan de foot mais aussi des nouvelles geeks. On discute ici et on règle les comptes sur FIFA.

You don't have permission to register
>