DefinIT Because if IT were easy, everyone would do it…

20Jan/09Off

Powershell script to zip all .bak files in a folder structure, then delete the .bak

Posted by Sam McGeown

Our development SQL server is a monster...there are many many databases, and hundreds, if not thousands of backup files. With each patch tested on the software we sell, there is a new backup. With each client deployment, a new database. With each new major version, a new database. Backups of the new databases inevitably occur, and so we have more files, in more folders - most of which need to be kept in case of roll-backs, bugs or deployment issues.

This all adds up to a bit of an administrative nightmare, especially since the backups eat away at my storage at a phenomonal rate. Zipping the .bak files is great, but since each DB has it's own backup folder, it can become a bit of a nightmare to go through, zip and delete the .baks. For my first real foray into using PowerShell, I decided I'd write a script to take the legwork out of it for me.


# Powershell Script to recurse input path looking for .bak files, Zip them
# and delete the .bak.
function out-zip {
Param([string]$path)
if (-not $path.EndsWith('.zip')) {$path += '.zip'}
if (-not (test-path $path)) {
set-content $path ("PK" + [char]5 + [char]6 + ("$([char]0)" * 18))
}
$ZipFile = (new-object -com shell.application).NameSpace($path)
$input | foreach {$zipfile.CopyHere($_.fullname)} | out-null
}
$FileCount =0
$FilesZipped =0
$FilesDeleted =0
$InputPath = $args[0]
if($InputPath.Length -lt 2)
{
Write-Host "Please supply a path name as your first argument" -foregroundcolor Red
return
}
if(-not (Test-Path $InputPath))
{
Write-Host "Path does not appear to be valid" -foregroundcolor Red
return
}
$BakFiles = Get-ChildItem $InputPath -Include *.bak -recurse
Foreach ($Bak in $BakFiles)
{
write-host "File: $Bak" -foregroundcolor Yellow
$ZipFile = $Bak.FullName -replace ".bak", ".zip"
if (Test-Path $ZipFile)
{
Write-Host "$ZipFile exists already, aborted." -foregroundcolor Red
}
else
{
Get-Item $Bak | out-zip $ZipFile
if(Test-Path $ZipFile)
{
$Response = read-host -prompt "Please wait for zip to complete then type c<enter> to continue..."
if($Response = "c")
{
$FilesZipped++
Remove-Item $Bak.FullName
if(Test-Path $Bak.FullName)
{
Write-Host "File not deleted, manually remove $Bak.Fullname" -foregroundcolor Red
}
else
{
Write-Host "OK" -foregroundcolor Green
$FilesDeleted++
}
}
else
{
Write-Host "File delete aborted by user" -foregroundcolor Red
}
}
}
$FileCount++
}
Write-Host Files found: $FileCount
Write-Host Files Zipped: $FilesZipped
Write-Host Files Deleted: $FilesDeleted

Obviously, this is not something I'd recommend you running lightly without serious testing on your own systems - that said, I hope it helps! I make no warantee or any kind of promise that you won't lose data by running this! It's just an exercise in PowerShell for me.

Filed under: PowerShell 4 Comments
20Jan/09Off

Windows update or installer fails to install with error “You do not have permission to update Windows Server 2003. Please contact your system administrator.”

Posted by Sam McGeown

I was just installing PowerShell on one of my Windows Server 2003 servers, when I encountered the error "You do not have permission to update Windows Server 2003. Please contact your system administrator." Odd, especially considering that I was installing as the Domain Administrator, and that user should have more than enough permissions. A little bit of digging led me to MSKB 888791 which shows the permissions that are required in Group Policy to install the update. Check that your applicable GPO has the following permissions for your user:

  • Back up files and directories
  • Restore files and directories
  • Manage auditing and security log
  • Take ownership of files or other objects
  • Shutdown the system
  • Debug programs

 Once I found the missing permission (in this case, an Exchange 2003 installation had removed the "Manage auditing and security log" permission) and added it back in, I ran the command "gpupdate /force", logged off and back on again on the offending server and retried the installation. The error disappears and the installation is a success!

 

Filed under: Microsoft, Windows No Comments
15Jan/09Off

Windows Vista Local Area Network Connection “Authentication Failed”

Posted by Sam McGeown

If you’re getting a error on your LAN connection it’s possible that your network connection is attempting 802.11 authentication on your wired network. Unfortunately, it seems that Vista/Server 2008 both attempt it before reverting. As far as I can see, it’s not causing any issues, other than irritating me with a “failed” and a red question mark.

VistaAuthenticationError1

Fortunately, it’s pretty easy to fix! The authentication is handled by the Wired AutoConfig service, so it’s just a case of disabling it. Navigate “Start”, then click “Run” (or just hit Win + r) and type “services.msc”. Click “OK” and the Services console will fire up.

VistaAuthenticationError2

 

Now if you scroll down to Wired Autoconfig and configure it as below (Stop the service, then select “Disabled” as the startup type).

VistaAuthenticationError3

Alternatively, you can enable 802.11 on your Windows Domain…but that’s another story!

Filed under: Microsoft, Windows 1 Comment
7Jan/09Off

Dell Latitude E6500 blue screen of death on XP install/downgrade/reinstall

Posted by Sam McGeown

I've just had a frustrating few days trying to downgrade 4 Dell Latitude E6500 laptops to XP. The problem was, whenever you booted to the XP cd you would get to the point just before you agree to the license and then hit a blue screen with a SATA error code. It seems that the bundled driver for the SATA storage controller incorrectly identifies it and causes a fatal error as it's loaded.

 The solution is fairly specific and needs to be done exactly in the order prescribed below. You will need a USB floppy drive, and a blank floppy disk.

  •  Firstly, go to Dell's support website and select the downloads for your E6500 laptop (if you enter your service tag, you might find that there are no XP downloads available -use the product select instead).
  • Download the LATEST BIOS - at the point of writing that's A11.
  • Also download the Intel Matrix Storage Manager Driver.
  • Plug in your USB floppy, insert the disk and format it. Extract the storage manager driver, and then copy the extracted files onto the floppy. Unplug the floppy
  • Now run the BIOS update, follow the on-screen instructions, let it reboot and flash your BIOS.
  • Reboot, and on the BIOS screen, hit F2 to enter into the BIOS setup.
  • Move down to System Configuration, then SATA operation. Make sure it's set to IRRT.
  • Move through the BIOS and disable Parallel, Serial, and any other devices that aren't needed. Switch the NIC to Disabled. Also go down to Miscellaneous Devices and ensure USB and the Modular bay (i.e. CD/DVD) are enabled. Disable everything else.
  • Plug in your USB floppy, and insert the floppy containing the drivers from earlier. Also put your Windows XP install CD in the CD/DVD drive. Save your BIOS changes and then reboot.
  • On the BIOS screen, hit F12 to bring up the one time boot menu. Select your CD/DVD ROM device.
  • *IMPORTANT* The blue windows installer screen will come up and you have a few seconds to hit F6 to specify that you want to use a 3rd party driver for storage.
  • Once you've hit it, wait for the next screen, which will be asking for your driver. Hit S and specify the Intel SATA driver needed. There were 4 drivers in the list for my laptops, trial and error will find the right one. It should say that Windows already has a driver for that device - do you want to use the new one? Well of course you do, the old one blue screens. Hit S to accept it and at the next screen, hit ENTER to continue.
  • After that, it's plain sailing - just don't forget to enable all of your devices once you've installed XP!!!
Filed under: Hardware, Windows 17 Comments