28 June 2013

Apply all Microsoft Office Updates within a folder

Here is a script that will install all Microsoft Office updates within the same folder. It queries the folder for all of the filenames and then runs installs the updates.

You can download the script from here.

 '*******************************************************************************  
 '   Author: Mick Pletcher  
 '    Date: 28 June 2013  
 '  Modified:  
 '  
 ' Description: This will install all office updates residing in the same folder as this  
 '                 script.  
 '                 1) Define the relative installation path  
 '                 2) Create the Log Folder  
 '                 3) Read list of Updates into Array  
 '                 4) Install updates  
 '                 5) Cleanup Global Memory  
 '*******************************************************************************  

 Option Explicit  

 REM Define Constants  
 CONST TempFolder    = "c:\temp\"  
 CONST LogFolderName = "OfficeUpdates"  

 REM Define Global Variables  
 DIM Count        : Count      = 1  
 DIM LogFolder    : LogFolder    = TempFolder & LogFolderName & "\"  
 DIM RelativePath : Set RelativePath = Nothing  
 ReDIM arrFiles(1)  

 REM Define the relative installation path  
 DefineRelativePath()  
 REM Create the Log Folder  
 CreateLogFolder()  
 REM Read list of Updates into Array  
 ReadUpdates()  
 REM Install Updates  
 InstallUpdates()  
 REM Cleanup Global Memory  
 GlobalMemoryCleanup()  

 '*******************************************************************************  
 '*******************************************************************************  

 Sub DefineRelativePath()  

      REM Get File Name with full relative path  
      RelativePath = WScript.ScriptFullName  
      REM Remove file name, leaving relative path only  
      RelativePath = Left(RelativePath, InStrRev(RelativePath, "\"))  

 End Sub  

 '*******************************************************************************  

 Sub CreateLogFolder()  

      REM Define Local Objects  
      DIM FSO : Set FSO = CreateObject("Scripting.FileSystemObject")  

      If NOT FSO.FolderExists(TempFolder) then  
           FSO.CreateFolder(TempFolder)  
      End If  
      If NOT FSO.FolderExists(LogFolder) then  
           FSO.CreateFolder(LogFolder)  
      End If  

      REM Cleanup Local Variables  
      Set FSO = Nothing  

 End Sub  

 '*******************************************************************************  

 Sub ReadUpdates()  

      REM Define Local Objects  
      DIM FSO : Set FSO = CreateObject("Scripting.FileSystemObject")  

      REM Define Local Variables  
      DIM Folder : Set Folder = FSO.GetFolder(RelativePath)  
      DIM Files  : Set files = Folder.Files  
      DIM File   : Set File  = Nothing  

      For each File in Files  
           If NOT File.Name = Wscript.ScriptName then  
                arrFiles(Count) = File.Name  
                Count = Count + 1  
                ReDim Preserve arrFiles(Count)  
           End If  
      Next  
      Count = Count - 1  

      REM Cleanup Local Memory  
      Set File   = Nothing  
      Set Files  = Nothing  
      Set Folder = Nothing  
      Set FSO    = Nothing  

 End Sub  

 '*******************************************************************************  

 Sub InstallUpdates()  

      REM Define Local Objects  
      DIM File     : Set File   = Nothing  
      DIM FSO      : Set FSO   = CreateObject("Scripting.FileSystemObject")  
      DIM i        : Set i    = Nothing  
      DIM oShell   : Set oShell  = CreateObject("Wscript.Shell")  
      DIM Switches : Set Switches = Nothing  

      For i = 1 to Count  
           File = Left(arrFiles(i),Len(arrFiles(i))-4)  
           Switches = Chr(32) & "/passive /norestart /log:" & LogFolder & File & ".log"  
           oShell.run arrFiles(i) & Switches, 1, True  
      Next  

      REM Cleanup Local Memory  
      Set File     = Nothing  
      Set FSO      = Nothing  
      Set i        = Nothing  
      Set oShell   = Nothing  
      Set Switches = Nothing  

 End Sub  

 '*******************************************************************************  

 Sub GlobalMemoryCleanup()  

      Set Count        = Nothing  
      Set LogFolder    = Nothing  
      Set RelativePath = Nothing  
      Erase arrFiles  

 End Sub  

17 June 2013

How to extract the iOS 7 ipsw file from the dmg on a PC and apply it to your iDevice

First thing to do is to download the DMG file from Apple. Once you have downloaded it, here is how to push it to your iPhone


  1. Extract the .IPSW file from the DMG. I used PeaZIP to open up the DMG file. Once you open it up, double-click on 2.hfs. the IPSW file is located inside of it.
  2. Open up iTunes
  3. Connect your iPhone/iPod/iPad to the PC
  4. In iTunes, click on the device in the upper right corner
  5. Make sure you perform a backup of your device. I a backup both to iCloud and my PC.
  6. While holding down the shift key, click on Restore iPod/iPad/iPhone
  7. Select the IPSW file to apply to the device
That is all that is to it.

12 June 2013

Autodesk Revit 2013 Hotfix Script

Here is a script that will automate the installation of the new DLL files that replace the old ones. Sadly, Autodesk expects for all users to manually replace these files, even in larger corporations, like I work in. This script runs relative to to it's execution path. The only thing that has to be done is to make sure all of the DLL files are in the same directory, including the directory .\RevitServerToolCommand be present, containing the DLL files within that directory too.

Here is the link to Autodesk's website describing what this script does.

Here is the link to download the script below.

 #*******************************************************************************  
 #   Author: Mick Pletcher  
 #    Date: 12 June 2013  
 #  
 #   Program: Revit 2013 Hotfix  
 #*******************************************************************************  
 Clear-Host  

 $Global:OS  
 $Global:RelativePath  
 $FileLoc = "C:\Program Files\Autodesk\Revit 2013\Program\"  
 $DLL_01 = "RS.Common.ClientServer.Proxy"  
 $DLL_02 = "DataStorageClient"  
 $DLL_03 = "DesktopMFC"  
 $DLL_04 = "FamilyDB"  
 $DLL_05 = "GeomUtil"  
 $DLL_06 = "Graphics"  
 $DLL_07 = "GrphOGS3"  
 $DLL_08 = "CommandServiceClient"  
 $DLL_09 = "RS.Common.ClientServer.Proxy"  

 Function GetRelativePath{  
      $Global:RelativePath=(split-path $SCRIPT:MyInvocation.MyCommand.Path -parent)+"\"  
      Write-Host $Global:RelativePath  
 }  

 Function GetOSArchitecture{  
      $Global:OS=Get-WMIObject win32_operatingsystem  
      #$Global:OS.OSArchitecture  
      #Answers: 32-bit, 64-bit  
 }  

 GetRelativePath  
 GetOSArchitecture  
 If ($Global:OS.OSArchitecture -eq "64-bit"){  
      If ((Test-Path -Path $FileLoc$DLL_01".dll") -eq $true){  
           Copy-Item -Path $FileLoc$DLL_01".dll" -Destination $FileLoc$DLL_01".orig" -Force  
           Remove-Item -Path $FileLoc$DLL_01".dll" -Force  
           Copy-Item -Path $Global:RelativePath$DLL_01".dll" -Destination $FileLoc -Force  
      }  
      If ((Test-Path -Path $FileLoc$DLL_02".dll") -eq $true){  
           Copy-Item -Path $FileLoc$DLL_02".dll" -Destination $FileLoc$DLL_02".orig" -Force  
           Remove-Item -Path $FileLoc$DLL_02".dll" -Force  
           Copy-Item -Path $Global:RelativePath$DLL_02".dll" -Destination $FileLoc -Force  
      }  
      If ((Test-Path -Path $FileLoc$DLL_03".dll") -eq $true){  
           Copy-Item -Path $FileLoc$DLL_03".dll" -Destination $FileLoc$DLL_03".orig" -Force  
           Remove-Item -Path $FileLoc$DLL_03".dll" -Force  
           Copy-Item -Path $Global:RelativePath$DLL_03".dll" -Destination $FileLoc -Force  
      }  
      If ((Test-Path -Path $FileLoc$DLL_04".dll") -eq $true){  
           Copy-Item -Path $FileLoc$DLL_04".dll" -Destination $FileLoc$DLL_04".orig" -Force  
           Remove-Item -Path $FileLoc$DLL_04".dll" -Force  
           Copy-Item -Path $Global:RelativePath$DLL_04".dll" -Destination $FileLoc -Force  
      }  
      If ((Test-Path -Path $FileLoc$DLL_05".dll") -eq $true){  
           Copy-Item -Path $FileLoc$DLL_05".dll" -Destination $FileLoc$DLL_05".orig" -Force  
           Remove-Item -Path $FileLoc$DLL_05".dll" -Force  
           Copy-Item -Path $Global:RelativePath$DLL_05".dll" -Destination $FileLoc -Force  
      }  
      If ((Test-Path -Path $FileLoc$DLL_06".dll") -eq $true){  
           Copy-Item -Path $FileLoc$DLL_06".dll" -Destination $FileLoc$DLL_06".orig" -Force  
           Remove-Item -Path $FileLoc$DLL_06".dll" -Force  
           Copy-Item -Path $Global:RelativePath$DLL_06".dll" -Destination $FileLoc -Force  
      }  
      If ((Test-Path -Path $FileLoc$DLL_07".dll") -eq $true){  
           Copy-Item -Path $FileLoc$DLL_07".dll" -Destination $FileLoc$DLL_07".orig" -Force  
           Remove-Item -Path $FileLoc$DLL_07".dll" -Force  
           Copy-Item -Path $Global:RelativePath$DLL_07".dll" -Destination $FileLoc -Force  
      }  
      If ((Test-Path -Path $FileLoc"RevitServerToolCommand\"$DLL_08".dll") -eq $true){  
           Copy-Item -Path $FileLoc"RevitServerToolCommand\"$DLL_08".dll" -Destination $FileLoc"RevitServerToolCommand\"$DLL_08".orig" -Force  
           Remove-Item -Path $FileLoc"RevitServerToolCommand\"$DLL_08".dll" -Force  
           Copy-Item -Path $Global:RelativePath"RevitServerToolCommand\"$DLL_08".dll" -Destination $FileLoc"RevitServerToolCommand\" -Force  
      }  
      If ((Test-Path -Path $FileLoc"RevitServerToolCommand\"$DLL_09".dll") -eq $true){  
           Copy-Item -Path $FileLoc"RevitServerToolCommand\"$DLL_09".dll" -Destination $FileLoc"RevitServerToolCommand\"$DLL_09".orig" -Force  
           Remove-Item -Path $FileLoc"RevitServerToolCommand\"$DLL_09".dll" -Force  
           Copy-Item -Path $Global:RelativePath"RevitServerToolCommand\"$DLL_09".dll" -Destination $FileLoc"RevitServerToolCommand\" -Force  
      }  
 }  
 Remove-Variable -Name DLL_01  
 Remove-Variable -Name DLL_02  
 Remove-Variable -Name DLL_03  
 Remove-Variable -Name DLL_04  
 Remove-Variable -Name DLL_05  
 Remove-Variable -Name DLL_06  
 Remove-Variable -Name DLL_07  
 Remove-Variable -Name DLL_08  
 Remove-Variable -Name DLL_09  
 Remove-Variable -Name FileLoc  
 Remove-Variable -Name OS  
 Remove-Variable -Name RelativePath  

PowerShell: Display all Add/Remove Program Entries with Uninstall String

Here is a script that will display all Add/Remove Program entries with the uninstall string, directly from the x86 and x64 registry keys.

You can download the script from here.

 #*******************************************************************************  
 #      Author: Mick Pletcher  
 #        Date: 12 June 2013  
 #  
 #     Program: Add/Remove Programs  
 # Description: This script will either list all applications in the Add/Remove  
 #              programs, which is pulled from both the registry. On a 64-bit  
 #              machine, it pulls from both the x86 and x64 add/remove programs  
 #              registry entries. You will also have the option to search for  
 #              a specific application.   
 #*******************************************************************************  
 cls

 $Global:OS  

 Function GetOSArchitecture{  
      $Global:OS=Get-WMIObject win32_operatingsystem  
      #$Global:OS.OSArchitecture  
      #Answers: 32-bit, 64-bit  
 }  

 $DisplayOutput = $false  
 GetOSArchitecture  
 [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")  
 [System.Reflection.Assembly]::LoadWithPartialName('Microsoft.VisualBasic') | Out-Null  
 $Output = [System.Windows.Forms.MessageBox]::Show("Search for a specific program?" , "Status" , 4)  
 If ($Output -eq "Yes"){  
      $ProgramName = [Microsoft.VisualBasic.Interaction]::InputBox("Enter specific software name:")  
      $ProgramName = "*"+$ProgramName+"*"  
 }  
 If ($Global:OS.OSArchitecture -eq "32-bit"){  
      $RegPath = "HKLM:\software\microsoft\windows\currentversion\uninstall\"  
      $Results = Get-ChildItem $RegPath -Recurse -ErrorAction SilentlyContinue  
      foreach ($item in $Resultsx86){  
           If (($item.GetValue("DisplayName") -ne $null) -and ($item.GetValue("UninstallString") -ne $null)) {  
                Write-Host  
                Write-Host  
             Write-Host "  Software: "$item.GetValue("DisplayName")  
                Write-Host "  Version: "$item.GetValue("DisplayVersion")  
             Write-Host "Uninstaller: "$item.GetValue("UninstallString")  
           }  
      }  
 }  
 If ($Global:OS.OSArchitecture -eq "64-bit"){  
      $RegPathx86 = "HKLM:\software\wow6432node\microsoft\windows\currentversion\uninstall\"  
      $RegPathx64 = "HKLM:\software\microsoft\windows\currentversion\uninstall\"  
      $Resultsx86 = Get-ChildItem $RegPathx86 -Recurse -ErrorAction SilentlyContinue  
      $Resultsx64 = Get-ChildItem $RegPathx64 -Recurse -ErrorAction SilentlyContinue  
      foreach ($item in $Resultsx86){  
           If (($item.GetValue("DisplayName") -ne $null) -and ($item.GetValue("UninstallString") -ne $null)) {  
                If ($Output -eq "Yes"){  
                     If ($item.GetValue("DisplayName") -like $ProgramName){  
                          $DisplayOutput = $true  
                     }  
                }else{  
                     $DisplayOutput = $true  
                }  
                If ($DisplayOutput -eq $true){  
                     Write-Host  
                     Write-Host  
                  Write-Host "  Software: "$item.GetValue("DisplayName")  
                     Write-Host "  Version: "$item.GetValue("DisplayVersion")  
                  Write-Host "Uninstaller: "$item.GetValue("UninstallString")  
                }  
           }  
           $DisplayOutput = $false  
      }  
      $DisplayOutput = $false  
      foreach ($item in $Resultsx64){  
           If (($item.GetValue("DisplayName") -ne $null) -and ($item.GetValue("UninstallString") -ne $null)) {  
                If ($Output -eq "Yes"){  
                     If ($item.GetValue("DisplayName") -like $ProgramName){  
                          $DisplayOutput = $true  
                     }  
                }else{  
                     $DisplayOutput = $true  
                }  
                If ($DisplayOutput -eq $true){  
                     Write-Host  
                     Write-Host  
                  Write-Host "  Software: "$item.GetValue("DisplayName")  
                     Write-Host "  Version: "$item.GetValue("DisplayVersion")  
                  Write-Host "Uninstaller: "$item.GetValue("UninstallString")  
                }  
           }  
           $DisplayOutput = $false  
      }  
 }  

11 June 2013

APPLYING WINDOWS UPDATE MSU FILES TO WIM IMAGES

This powershell script will inject all .msu files into a mounted WIM file. The script first scans the relative path of the directory that it was executed from for WIM files. Next, it mounts the WIM file. The script then scans the relative directory for all existing .msu files and writes them to an array. The msu files are then injected into the mounted WIM file. Once all updates are injected, the WIM is unmounted and cleaned up.

To use this, I suggest creating a separate directory and copying the script to it. Copy all of the pertinant .msu files and the WIM file over.

NOTE: Make sure to backup the WIM file before injecting the .msu files into it. Some updates are only online updates and will corrupt the WIM file if injected. You can read more on this topic in my blog located here.

You can download the script here.

 Clear-Host  
 $Global:MountPath  
 $Global:RelativePath  
 $Global:WimFile  
 $Global:UpdatesPath  
 Function GetRelativePath{  
      $Global:RelativePath=(split-path $SCRIPT:MyInvocation.MyCommand.Path -parent)+"\"  
      Write-Host $Global:RelativePath  
 }  
 Function GetWimFile{  
      $FileName = Get-ChildItem $Global:RelativePath | Where-Object {($_.Name -like "*.wim")}  
      $Global:WimFile = $Global:RelativePath+$FileName  
      Write-Host $Global:WimFile  
 }  
 Function MountWIM{  
      $Global:MountPath = $Global:RelativePath+"Mount\"  
      If ((Test-Path $Global:MountPath) -ne $true){  
           New-Item -ItemType directory -Path $Global:RelativePath"Mount"  
      }  
      Write-Host $Global:MountPath  
      $Arguments = "dism.exe /mount-wim /wimfile:"+$Global:WimFile+[char]32+"/index:1 /mountdir:"+$Global:MountPath  
      Write-Host $Arguments  
      Invoke-Expression -Command $Arguments  
 }  
 Function UnmountWIM{  
      $Arguments = "dism.exe /unmount-wim /mountdir:"+$Global:MountPath+[char]32+"/commit"  
      Write-Host $Arguments  
      Invoke-Expression -Command $Arguments  
 }  
 Function CleanupWIM{  
      $Arguments = "dism.exe /cleanup-wim"  
      Write-Host $Arguments  
      Invoke-Expression -Command $Arguments  
 }  
 Function GlobalMemoryCleanup{  
      Clear-Variable -Name MountPath -Scope Global -Force  
      Clear-Variable -Name WimFile -Scope Global -Force  
      Clear-Variable -Name UpdatesPath -Scope Global -Force  
      Clear-Variable -Name RelativePath -Scope Global -Force  
      Remove-Variable -Name MountPath -Scope Global -Force  
      Remove-Variable -Name WimFile -Scope Global -Force  
      Remove-Variable -Name UpdatesPath -Scope Global -Force  
      Remove-Variable -Name RelativePath -Scope Global -Force  
 }  
 GetRelativePath  
 GetWimFile  
 MountWIM  
 $Global:UpdatesPath = $Global:RelativePath+"*.msu"  
 $UpdatesArray = Get-Item $Global:UpdatesPath  
 ForEach ($Updates in $UpdatesArray) {  
      $Arguments = "dism.exe /image:"+$Global:MountPath+[char]32+"/Add-Package /PackagePath:"+$Updates  
      Write-Host $Arguments  
      Invoke-Expression -Command $Arguments  
      Start-Sleep -Seconds 10  
 }  
 UnmountWIM  
 CleanupWIM  
 Clear-Variable -Name Arguments -Scope Local -Force  
 Clear-Variable -Name Updates -Scope Local -Force  
 Clear-Variable -Name UpdatesArray -Scope Local -Force  
 Remove-Variable -Name Arguments -Scope Local -Force  
 Remove-Variable -Name Updates -Scope Local -Force  
 Remove-Variable -Name UpdatesArray -Scope Local -Force  
 GlobalMemoryCleanup