Posts

Showing posts from May, 2014

Bulk Extension Renamer - bash

Image
As a quick counter-point to my earlier PowerShell script , here's my equivalent in bash: 1: #!/bin/bash 2: 3: if [ $# -lt 2 ]; then 4: echo -e "\e[33mUsage: $0 <current extension> <new extension>\e[0m" 5: exit 1 6: fi 7: 8: for fileName in *.$1; do 9: newFileName=${fileName/.$1/.$2} 10: if [ -f "$newFileName" ]; then 11: echo -e "\e[31mNot renaming \e[1m$fileName\e[22m to \e[1m$newFileName\e[22m -- File exists." 12: elif [ -d "$newFileName" ]; then 13: echo -e "\e[31mNot renaming \e[1m$fileName\e[22m to \e[1m$newFileName\e[22m -- Is a directory." 14: else 15: if [ -w "$fileName" ]; then 16: mv "$fileName" "$newFileName" 17: echo -e "\e[1;32m$fileName\e[22m renamed to \e[1m$newFileName\e[0m" 18: else 19:

Change the ComputerName value in Unattend.xml using PowerShell

A quick and dirty PowerShell script to update the value of ComputerName in Unattend.xml before imaging. This particular value is located at: <unattend>  <settings pass="generalize">   <component name="Microsoft-Windows-Shell-Setup" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">     <computername> Which is a bit of a mouthful, but we can be lazy and just pull the value from the nth component node (in my case it's 3, or the 4th component node). PowerShell uses dots to describe the hierarchical path, which looks a lot neater than the above: $xml.unattend.settings.component[3].computername To repeat, the value of .component[n] will change depending on the structure of the file. The value of the

Customized Windows PE 5.0

Image
A quick run-through covering creating a customized Windows PE bootable drive, mainly so I don't space out and forget any of the steps (*ahem* again). The below is based on the Deployment and Imaging tools available by installing Windows ADK 8.1 Create Windows PE files Run Deployment and Imaging Tools Environment as Administrator Create the base structure with copype command: copype <architecture> <directory> Example for 64 bit: copype amd64 c:\winpe64 Example for 32 bit: copype x86 c:\winpe32 Paths to packages amd64: \Program Files (x86)\Windows Kits\8.1\Assessment and Deployment Kit\Windows Preinstallation Environment\amd64\WinPE_OCs x86: \Program Files (x86)\Windows Kits\8.1\Assessment and Deployment Kit\Windows Preinstallation Environment\x86\WinPE_OCs Mount boot.wim (assuming current path is the root of WinPE, e.g., c:\winpe) dism /mount-wim /wimfile:media\sources\boot.wim /index:1 /mountdir:mount Adding Key Packages (as

Bulk File Extension Renamer - PowerShell

Image
Here's a quick PowerShell script to change the extension on a group of matching files, posted chiefly to illustrate how much more concise PowerShell can be when compared to VBScript (I'll post an equivalent script shortly). The script below is still about twice the length of the a similar script I wrote in bash for *nix but it's certainly an improvement in both length and readability over VBS. First up, grab the required parameters (old extension, new extension) from the command line. If either or both are missing, the user will be prompted to enter them. Each parameter is set with three options - [parameter(Mandatory = $true)] makes the parameter mandator. ValidateNotNullorEmpty is called to do exactly what it says on the tin.   [string]$oldExt puts the value of the parameter into a string called $oldExt . 1: param( 2: [parameter(Mandatory = $true)] 3: [ValidateNotNullOrEmpty()] 4: [string]$oldExt, 5: [parameter(Mandatory = $tru

Not a bad background for a morning

Image
The view from my overnight digs made a very pleasant background for breakfast/coffee o'clock this morning. Loved the silence most of all - buried in the bush between Tathra and Bega. Not that the interior was anything to sneeze at... You just have to love off-peak rates that make places like this affordable for a simple business trip :)

Quote for the day

"I have so little that is fanciful or poetical about my own individu [sic] that I must trick out my dwelling with something fantastical otherwise the Coerulean Nymphs and swains will hold me nothing worth." - Sir Walter Scott