Friday, September 20, 2013

Quick Script: Run a MSI installer with a transform using Powershell

function Run-MsiExec($installShare, $msiPackage, $Transform, $options){
       $Arguments = "/i `"$env:temp\$msiPackage`" ALLUSERS=2 TRANSFORMS=`"$env:temp\$Transform`" /qn $options"
      
       Copy-Item "$installShare\$msiPackage" "$env:temp\$msiPackage"

       if($Transform){
              Copy-Item "$installShare\$Transform" "$env:temp\$Transform"
       }else{
              $Arguments = "/i `"$env:temp\$msiPackage`" ALLUSERS=2 /qn $options"
       }
       Write-Host "Installing $msiPackage"
    Write-Host "Start-Process -FilePath 'msiexec.exe' -ArgumentList "$Arguments" -Wait -Passthru"
       return (Start-Process -FilePath "msiexec.exe" -ArgumentList "$Arguments" -Wait -Passthru).ExitCode

Thursday, September 12, 2013

Quick Script: Uninstall Software with Powershell

Get-WmiObject win32_product | ?{$_.Name -imatch "software"} | %{$_.Uninstall()} 

Friday, September 06, 2013

Quick Script: Sign script with timestamp using Powershell

$cert = gci cert:\currentuser\my -CodeSigningCert | ?{$_.thumbprint -eq "DA46063E89886D185F19FCD64483E35B1898925D" }

Set-AuthenticodeSignature $args[0] $cert -TimestampServer "http://timestamp.verisign.com/scripts/timstamp.dll"