Archives par mot-clé : Powershell

powershell

Supprimer un programme windows2016 Core

Get-WmiObject -Class Win32_Product | Select-Object Name,IdentifyingNumber
Name                                                           IdentifyingNumber
----                                                           -----------------
VMware Tools                                                   {45147181-CF69-4C8C-81CB-0FC96F170758}
Microsoft Visual C++ 2008 Redistributable - x64 9.0.30729.6161 {5FCE6D76-F5DC-37AB-B2B8-22AB8CEDB1D4}
Microsoft Visual C++ 2008 Redistributable - x86 9.0.30729.6161 {9BE518E6-ECC6-35A9-88E4-87755C07200F}
Get-WmiObject -Class Win32_Product | Where-Object {$_.IdentifyingNumber -match '{45147181-CF69-4C8C-81CB-0FC96F170758}'} |  Invoke-WmiMethod -Name "Uninstall"

Sync de dossiers

powershell.exe -noexit "& 'D:\sync_local_drive.ps1'"
function Pause ($Message="Press any key to continue...")
{
Write-Host -NoNewLine $Message
$null = $Host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")
Write-Host ""
}

Robocopy.exe   "D:\Source" "Z:\Destination"   /MIR /XD *Exclude_pattern* Folder_exclude /XF .file_pattern* file_pattern2*
 OR 
Robocopy.exe   "D:\local_save"  "G:\usb_key" /MIR  ( XD => eXclude Directory XF => eXclude File )
pause

Execution policy

Get-ExecutionPolicy -list

        Scope ExecutionPolicy
        ----- ---------------
MachinePolicy       Undefined
   UserPolicy       Undefined
      Process       Undefined
  CurrentUser       Undefined
 LocalMachine    RemoteSigned


Get-ExecutionPolicy

Set-ExecutionPolicy RemoteSigned

Netoyage des logs

  (Get-WinEvent -ListLog *).logname | ForEach-Object   {[System.Diagnostics.Eventing.Reader.EventLogSession]::GlobalSession.ClearLog(“$psitem”)}