Categories

Backing up the WMI repository

The WMI repository is a collection of files. It can be easily backed up

function backup-wmirepository {            
 param(            
  [string]$path,            
  [switch]$force            
 )            
             
 if ($force){            
  if (Test-Path $path){Remove-Item -Path $path -Force}            
 }            
 else {            
   if (Test-Path $path){Throw "$path already exists"}            
 }            
 $exp = "winmgmt /backup $path"            
             
 Invoke-Expression -Command $exp             
            
}


The function will back up the repository to the give file unless the file exists. if you want the backup file overwritten use the force switch

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>