Recettes PowerShell

De Linuxmemo.

(Différences entre les versions)
(MD5sum)
(ZIP / UNZIP)
Ligne 22 : Ligne 22 :
  expand-archive -path 'c:\users\john\desktop\iislogs.zip' -destinationpath '.\unzipped'
  expand-archive -path 'c:\users\john\desktop\iislogs.zip' -destinationpath '.\unzipped'
 +
 +
==Infos matériel==
 +
(Get-WmiObject -Class Win32_ComputerSystem).Manufacturer
 +
(Get-WmiObject -Class Win32_ComputerSystem).Model
 +
(Get-WmiObject win32_computersystem).SystemSKUNumber

Version du 4 avril 2018 à 08:49

Sommaire

Exécuter une commande stocké dans une variable

Invoke-Command -ComputerName $Ip -Credential $login -ScriptBlock { Param( $LocalVariable ); Invoke-Expression -Command $LocalVariable } -ArgumentList $commande

Tester l’exécution administrateur

function Test-Administrator  
{  
   $user = [Security.Principal.WindowsIdentity]::GetCurrent();
   (New-Object Security.Principal.WindowsPrincipal $user).IsInRole([Security.Principal.WindowsBuiltinRole]::Administrator)  
}
Test-Administrator
False

MD5sum

(Get-FileHash -Path ${repbase}${repdiffusion}\${nomfichier} -Algorithm MD5).hash

ZIP / UNZIP

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'

Infos matériel

(Get-WmiObject -Class Win32_ComputerSystem).Manufacturer
(Get-WmiObject -Class Win32_ComputerSystem).Model
(Get-WmiObject win32_computersystem).SystemSKUNumber
Outils personnels