Weekend Project: Process Explorer Auto Install
July 21, 2014 Leave a comment
I was bored this weekend and decided to try my hand at making a PowerShell script to automate the install of Sysinternals Process Explorer. It’s pretty rough product of about 3 hours of work. I’ll make improvements in the future as I get time. In any case, it’s available below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
#### Downloads Process explorer from download.sysinternals.com, #### unzips it into Program Files and then cleans up. #### #### Sources: #### s1: http://nyquist212.wordpress.com/2013/09/23/powershell-webclient-example/ #### s2: http://sharepoint.smayes.com/2012/07/extracting-zip-files-using-powershell/ # s1 Function Get-Webclient ($urla, $out) { $proxy = [System.Net.WebRequest]::GetSystemWebProxy() $proxy.Credentials = [System.Net.CredentialCache]::DefaultCredentials $request = New-Object System.Net.WebClient $request.UseDefaultCredentials = $true ## Proxy credentials only $request.Proxy.Credentials = $request.Credentials $request.DownloadFile($urla, $out) } # s2 # Expands the entire contents of a zip file to a folder # MSDN References # - Shell Object: http://msdn.microsoft.com/en-us/library/windows/desktop/bb774094(v=vs.85).aspx # - SHFILEOPSTRUCT: http://msdn.microsoft.com/en-us/library/windows/desktop/bb759795(v=vs.85).aspx function Expand-Zip ( [ValidateNotNullOrEmpty()][string]$ZipFilePath, [ValidateNotNullOrEmpty()][string]$DestinationFolderPath, [switch]$HideProgressDialog, [switch]$OverwriteExistingFiles ) { # Ensure that the zip file exists, the destination path is a folder, and the destination folder # exists. The code to expand the zip file will *only* execute if the three conditions above are # true. if ((Test-Path $ZipFilePath) -and (Test-Path $DestinationFolderPath) -and ((Get-Item $DestinationFolderPath).PSIsContainer)) { try { # Configure the flags for the copy operation based on the switches passed to this # function. The flags for the CopyHere method are based on the SHFILEOPSTRUCT # structure's fFlags field. Two of the flags are leveraged by this function. # 0x04 --- Do not display a progress dialog box. # 0x10 --- Click "Yes to All" in any dialog box displayed. Functionally overwrites any # existing files. $copyFlags = 0x00 if ($HideProgressDialog) { $copyFlags += 0x04 } if ($OverwriteExistingFiles) { $copyFlags += 0x10 } # Create the Shell COM object $shell = New-Object -ComObject Shell.Application # Get references to the zip file and the destination folder as Shell Folder COM objects $zipFile = $shell.NameSpace($ZipFilePath) $destinationFolder = $shell.NameSpace($DestinationFolderPath) # Execute a file copy from the zip file to the destination folder; which effectively # extracts the zip file's contents to the destination folder $destinationFolder.CopyHere($zipFile.Items(), $copyFlags) } finally { # Release the COM objects if ($zipFile -ne $null) { [void][System.Runtime.InteropServices.Marshal]::ReleaseComObject($zipFile) } if ($destinationFolder -ne $null) { [void][System.Runtime.InteropServices.Marshal]::ReleaseComObject($destinationFolder) } if ($shell -ne $null) { [void][System.Runtime.InteropServices.Marshal]::ReleaseComObject($shell) } } } } function mkdirs { mkdir $sDirtemp -force > $null mkdir $sDirProcessExplorer -force > $null } # Variables $sDir = $env:programfiles $uDir = $env:allusersprofile $url = "http://download.sysinternals.com/files/ProcessExplorer.zip" $file = $sDir + "tempProcessExplorer.zip" # Makes directories: # ProcessExplorer directory in Program Files according to Environment variable # temp directory in Program Files for download mkdirs Get-Webclient $url $file Start-Sleep -s 2 Expand-Zip $file "$sDirProcessExplorer" -HideProgressDialog -OverwriteExistingFiles Remove-Item "$sDirtemp" -recurse start-process $sDirProcessExplorerprocexp.exe -ArgumentList "/AcceptEula /t" ##Accepts EULA and starts minimized |
Download ProcessExplorerInstaller.ps1 from Github
GitHub | PowerShell-Scripts / ProcessExplorerInstaller.ps1
Recent Comments