Astuces PowerShell

De Linuxmemo.

Sommaire

[modifier] Fichier le plus récent

Get-ChildItem | select -last 1

[modifier] Tester l’existence d'un fichier/répertoire

Test-Path .\fichier.txt
True

[modifier] unzip / zip

compress-archive -path 'c:\wwwroot\logs' -destinationpath '.\logs.zip' -compressionlevel optimal
compress-archive -path “c:\wwwroot\logs\latest” -destinationpath “c:\wwwroot\logs\logs.zip” -update -compressionlevel optimal
compress-archive test.txt test.zip
expand-archive -path 'c:\users\john\desktop\iislogs.zip' -destinationpath '.\unzipped'

[modifier] Path - compter le nombre de caractère du path

pwd | Measure-Object -Character

[modifier] proc 32 ou 64 bits ?

if ([intptr]::size -eq 8)
{
  write-output '64 bits'
}
elseif ([intptr]::size -eq 4)
{
  write-output '32 bits'
}
else
{
  write-output 'OS ni 32, ni 64 bits !'
}

[modifier] Variable null ou vide ?

if ([STRING]::IsNullOrEmpty($variable)) {
 # si true alors null ou vide
}
Outils personnels