Blog

What Port am I plugged into??

Something that’s always handy to know is what switch port you’re plugged into. What’s even better is being able to find out without getting out of your chair.

If you’re on a nix based system with tcpdump then just turn the following:

1
tcpdump -nn -v -i eth0 -s 1500 -c 1 'ether[20:2] == 0x2000'

On Windows you’ll need to grab WinDump and WinPCap from http://www.winpcap.org.

Once installed run

1
windump -D

To list the interfaces on your system. Then just run the same as above but with windump:

1
windump -nn -v -i eth0 -s 1500 -c 1 'ether[20:2] == 0x2000'
Read more

7Zip with Powershell

7-Zip is something I use on a daily basis not only for creating or extracting various archive formats but for extracting ISOs. I love this feature of 7-Zip.

Something I’ve wanted to do for a while was figure out if it was possible to use 7-Zip from Powershell and indeed it is.

There is a C# wrapper for 7-Zip available at http://sevenzipsharp.codeplex.com/ that makes this all a lot easier. You’ll need to download the SevenZipSharp.dll as well as the native 7-Zip dlls (they’re in the Other Available Downloads section).

I’ve extracted SevenZipSharp.dll, 7z.dll and 7z64.dll to a directory called SevenZipSharp.

First up you’ll need to load the Assembly:

1
Add-Type -Path "D:\Tools\Assemblies\SevenZipSharp\SevenZipSharp.dll"

Then simply create an extractor and extract the archive, simply:

1
2
$extractor = New-Object SevenZip.SevenZipExtractor('D:\Data\BigArchive.zip')
$extractor.ExtractArchive('D:\tmp')

Note for x64 users
When I first tried this I got an error when attempting to create an SevenZip.SevenZipExtractor object: New-Object : Exception calling “.ctor” with “1″ argument(s): “Can not load 7-zip library or internal COM error! Message: failed to load library.”

This is because the SevenZipSharp.dll looks for 7z.dll in the same directory and the 7z.dll in that directory is the x86 Dll. You have two options, rename 7z64.dll to 7z.dll or run the following after loading the assembly:

1
[SevenZip.SevenZipExtractor]::SetLibraryPath('D:\Tools\Assemblies\SevenZipSharp\7z64.dll')
Read more

FTP 7 for IIS 7

When trying to add an FTP component to an IIS 7 website I got lost looking for how to add a new FTP site. Turns out there is new FTP service available as an extension to IIS 7 that boasts enhanced functionality and several new features. Some summary points:

  • Built as an extension to IIS 7 and integrates into the IIS Manager.
  • Supports FTP over SSL as well as UTF8 and IPv6.
  • Adds new membership based authentication system.
  • Allows for users to enable an existing website for FTP without the need to create a separate FTP site.
  • Virtual hostname support (Host headers but for ftp).
  • And much, much more.

Head on over to http://www.iis.net/download/FTP for a deeper look. Or download using the Web Platform Installer.

If you have the Windows Firewall enabled (and you should) it is worth looking at Configuring FTP Firewall Settings to ensure you have the correct firewall settings

Read more

Editing Powershell in Visual Studio

Looking for Powershell support in Visual Studio 2010?? Check out PowerGUI VSX! Essentially you get the great features of PowerGUI inside the Visual Studio IDE. Well worth downloading.

Read more

Powershell Prompt

Customising my Powershell prompt was something that I never really thought I’d do. After all surely the out of the box prompt tells me where I am and making a new one seems like a bit of work. Well actually it’s not and I kept getting my x86 and x68, admin and non-admin prompts confused. So I altered my prompt to inlucde this information.

Firstly, to change your prompt you just need to write your own prompt function as this is what generates the prompt each time the prompt is printed to the screen. To see the default promtp try the following:

1
(Get-Item Function:\prompt).Definition

You’ll get back something like this:

1
2
$(if (test-path variable:/PSDebugContext) { '[DBG]: ' } else { '' }) + 'PS ' +
$(Get-Location) + $(if ($nestedpromptlevel -ge 1) { '>>' }) + '> '

So the first thing that I wanted to change was adding [Admin] in red to the start of the prompt if I’m running as an administrator. I have a global variable in my profile called $IsAdmin that tells me if I’m an admin or not. So the code below uses write-host to output ‘[Admin]‘ in red if I’m an Administrator.

1
2
3
4
if( ([System.Environment]::OSVersion.Version.Major -gt 5) -and ($IsAdmin) )
{
write-host '[Admin]' -NoNewLine -Fore 'red'
}

Next, I wanted to show if I was running x86 or x64. Which simply involved creating a string with the right architecture type and adding that to the prompt.

1
2
3
4
5
6
7
$bitness = ''
if ([IntPtr]::Size -eq <img src="https://web.archive.org/web/20120320084139im_/https://www.project84.net/wp-includes/images/smilies/icon_cool.gif" alt="8)" class="wp-smiley"> {
$bitness = '(x64)'
}
elseif ($Pscx:IsWow64Process) {
$bitness = '(x86)'
}

I added a few other bits but here’s the end result:

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
## Set My Prompt
## . Set-Prompt.ps1 in profile.
function prompt {
## If this is Vista or higher and we're an admin change the prompt
$adminPrompt=''
if( ([System.Environment]::OSVersion.Version.Major -gt 5) -and ($IsAdmin) )
{
#$adminPrompt='[Admin]'
write-host '[Admin]' -NoNewLine -Fore 'red'
}
## Get the commmand ID for Get-History/Invoke-History
$nextCommandId = (Get-History -count 1).Id + 1
#was there an error in the last thing we did??
$err = !$?
#Totally stole this from somewhere, finds the architecture
$bitness = ''
if ([IntPtr]::Size -eq <img src="https://web.archive.org/web/20120320084139im_/https://www.project84.net/wp-includes/images/smilies/icon_cool.gif" alt="8)" class="wp-smiley"> {
$bitness = '(x64)'
}
elseif ($Pscx:IsWow64Process) {
$bitness = '(x86)'
}
if($err) { $fg = "Red" } else { $fg = "Cyan" }
write-host "PS$bitness [$nextCommandId]$(Get-Location)>" -NoNewLine -Fore $fg
return " "
}
Read more

Powershell Console Colours

I’m certain this is probably elsewhere on the web but I couldn’t find it immediately. I was wondering how to ouput the names of each console colour in the corresponding colour. Turns out it’s really easy:

1
[consolecolor]::GetNames([consolecolor]) | %{Write-Host "$_" -For $_}
Read more

Create a Windows PE 3.0 Boot CD

The process of creating a Windows PE 3.0 disk has changed slightly from the previous version. The Windows PE User’s Guide that ships with the WAIK has all the information you’ll ever need. To get started download the WAIK for Windows 7. Then follow the steps in the section “Windows PE Walkthroughs”. I’ve provided the batch file I use to create a generic WinPE 3.0 ISO 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
Echo off"
REM ********************************************************************************
REM head block
REM Setup
SET PETOOLS=C:\Program Files\Windows AIK\Tools\PETools
SET ARCH=x86
SET WORKINGDIR=%~dp0windowspe-%ARCH%
IF NOT EXIST "%WORKINGDIR%" Goto :COPYPE
Echo "%WORKINGDIR%" exists, Removing....
rmdir "%WORKINGDIR%" /S /Q
:COPYPE
cd /d "%PETOOLS%"
call copype.cmd %ARCH% "%WORKINGDIR%"
REM Copy Base WIM to boot.wim
copy "%WORKINGDIR%\winpe.wim" "%WORKINGDIR%\ISO\sources\boot.wim"
REM Mount boot.wim
Dism /Mount-Wim /WimFile:"%WORKINGDIR%\ISO\sources\boot.wim" /index:1 /MountDir:"%WORKINGDIR%\mount"
REM Add Optional Components
Dism /image:"%WORKINGDIR%\mount" /Add-Package /PackagePath:"%PETOOLS%\%ARCH%\WinPE_FPs\winpe-wmi.cab"
Dism /image:"%WORKINGDIR%\mount" /Add-Package /PackagePath:"%PETOOLS%\%ARCH%\WinPE_FPs\en-us\winpe-wmi_en-us.cab"
Dism /image:"%WORKINGDIR%\mount" /Add-Package /PackagePath:"%PETOOLS%\%ARCH%\WinPE_FPs\winpe-hta.cab"
Dism /image:"%WORKINGDIR%\mount" /Add-Package /PackagePath:"%PETOOLS%\%ARCH%\WinPE_FPs\en-us\winpe-hta_en-us.cab"
Dism /image:"%WORKINGDIR%\mount" /Add-Package /PackagePath:"%PETOOLS%\%ARCH%\WinPE_FPs\winpe-mdac.cab"
Dism /image:"%WORKINGDIR%\mount" /Add-Package /PackagePath:"%PETOOLS%\%ARCH%\WinPE_FPs\en-us\winpe-mdac_en-us.cab"
Dism /image:"%WORKINGDIR%\mount" /Add-Package /PackagePath:"%PETOOLS%\%ARCH%\WinPE_FPs\winpe-scripting.cab"
Dism /image:"%WORKINGDIR%\mount" /Add-Package /PackagePath:"%PETOOLS%\%ARCH%\WinPE_FPs\en-us\winpe-scripting_en-us.cab"
Dism /image:"%WORKINGDIR%\mount" /Add-Package /PackagePath:"%PETOOLS%\%ARCH%\WinPE_FPs\winpe-wmi.cab"
Dism /image:"%WORKINGDIR%\mount" /Add-Package /PackagePath:"%PETOOLS%\%ARCH%\WinPE_FPs\en-us\winpe-wmi_en-us.cab"
REM Copy Imagex into the Windows Dir
copy "C:\Program Files\Windows AIK\Tools\%ARCH%\imagex.exe" "%WORKINGDIR%\mount\Windows"
REM COpy Tools
xcopy %~dp0Tools %WORKINGDIR%\ISO /E /S
REM Unmount the WIM
Dism /unmount-Wim /MountDir:"%WORKINGDIR%\mount" /Commit
REM Create the ISO
oscdimg -n -b"%WORKINGDIR%\etfsboot.com" "%WORKINGDIR%\ISO" "%WORKINGDIR%\winpe_x86.iso"

You may want to comment out the line with “xcopy %~dp0Tools” at the beginning. I usually copy a bunch of tools onto my WinPE disk using this tools directory.

Read more

Moving SCCM Packages and Drivers Source Location

I had a situation recently where a server that had the source shares for my Packages and Drivers had to be decommissioned. This initially seemed like an simple task of updating the source location in each package to the new server. However after realising that there were a lot of packages and about 400 drivers I sought a better way. Powershell to the rescue!

The following block of Powershell gets all the drivers and does a search and replace on the server name.

1
2
3
4
$drivers = Get-WmiObject SMS_Driver -Namespace root\SMS\site_LNK
$drivers | ?{$_.ContentSourcePath -like "\\creekserver\*"} | `
%{$_.ContentSourcePath = $_.ContentSourcePath -replace "creekserver", "PRI-SCCM-V01"; $_.Put()}

I did the same for packages:

1
2
3
4
5
6
$packages = Get-WmiObject SMS_Package -Namespace root\SMS\site_LNK
$packages | ?{$_.PkgSourcePath -like "*creekserver*"} | `
%{$_.PkgSourcePath = $_.PkgSourcePath -replace "creekserver","PRI-SCCM-V01"; $_.Put()}
$packages | %{$_.RefreshPkgSource}

Enjoy!

Read more

Installing Lenovo Hotkey Utility in an SCCM Task Sequence

If you’ve ever tried to install the Lenovo Hotkey utility as part of an SCCM Task Sequence you’ll have noticed that no matter how big a tantrum you through it won’t work. Lenovo’s documentation states that you can install the Hotkey utility in an unattended fasion using “Setup.exe /S”. For whatever reason this doesn’t work in a Task Sequence using a standard Package and Program. To get around this do the follow:

  1. Extract the Hotkey utility.
  2. Create a batch file InstallHotkey.cmd with a single line: %~dp0SETUP.EXE /S
  3. Create a standard SCCM package with the source pointing to your extracted hotkey files.
  4. Make sure that InstallHotkey.cmd is in the same dir as Setup.exe
  5. In you Task Sequence add a new “Run Command Line” task.
  6. Set the Package to the Hotkey Package you created in step 4.
  7. In the command line put InstallHotkey.cmd
Read more

MDT 2008, VMWare Workstation and Stop 0x7B

When working with the Microsoft Deployment Toolkit (MDT) I spend a lot of time in VMWare Workstation as it makes the job of developing and testing a workstation image much simpler. However there is one big gottcha that you should be aware of. Make sure you edit your .VMX file and modify the following:

scsi0.present = “TRUE” should be changed to scsi0.present = “FALSE”

If you don’t do this then after deploying a Syspreped image to VMWare Workstation you’ll end up with a Stop 0x7B error and much less hair than when you started.

Thanks Chris for reminding me of something I supposedly knew. :)

Read more
Page 2 of 1012345...10...Last »