Archive for the ‘sysadmin’ Category
Enhancement to PowerShell Drives Script
I recently posted a script to map local and remote directories to PowerShell drives. Because this script executes when you open a new PowerShell session if you open it while disconnected then any network drives will remain unmapped until you start a new PowerShell session. I’ve resolved this by changing the script to map the drive on the fly when you try to access the drive. Here is the revised script:
$Drives = @{
"dev"="C:\Dev\";
"docs"="C:\Users\WilliamB\Documents\";
"utils"="C:\Utils\";
"drops"="\\server\drops\"
}
foreach ($Name in $Drives.Keys) {
$Location = $Drives.$Name
Invoke-Expression "function global:$($Name): { `
if ( -not (Get-PSDrive $($Name) -ErrorAction SilentlyContinue) ) {
`$null = New-PSDrive -PSProvider FileSystem -Name $Name -Root $Location -Scope Global
}
Push-Location $($Name): `
}"
}
PowerShell Drives
I’ve been reading Pro Windows PowerShell recently, which is without a doubt the best book on the subject I’ve found. One of the cool things about PowerShell is that you can define your own drives that aren’t restricted to a single character name, think Subst on steroids.
I was inspired by this and decided it would be useful to have a script that maps my most commonly used directories to drives. So I created the following script:
$Drives = @{
"dev"="C:\Dev\";
"docs"="C:\Users\WilliamB\Documents\";
"utils"="C:\Utils\";
"drops"="\\server\devdrops\"
}
foreach ($Name in $Drives.Keys) {
$null = New-PSDrive -PSProvider FileSystem -Name $Name -Root $Drives.$Name -Scope Global
Invoke-Expression "function global:$($Name): { Push-Location $($Name): }"
}
The first part of this script creates a hashtable of drive name and destination path, for example, I want the drive dev mapped to C:\Dev\.
The second part of the script loops through each of the keys (drive names) in the hashtable and:
- Creates a new FileSystem drive named after the key ($Name) and rooted at the value ($Drives.$Name). The scope is set to global otherwise when the script finishes executing the drive will be removed.
- Defines a function called $Name: that changes directory to the drive we created. By default, you can’t type a drive name followed by colon to change to that drive like you can for C:, D:, etc. so we mimic this behaviour by defining a global function named $Name:.
These drives will only exist in the PowerShell session, so if you want them to be available every time you run PowerShell then you’ll need to execute this script from your PowerShell profile script. Run Get-Help profile to learn how to do this.
VMWare LabManager: Bad Handle 0x7B4, the handle is invalid
I’ve been doing a bit of work recently with VMWare LabManager. However, when accessing the machine consoles on a variety of operating systems (but always using Internet Explorer
we’d receive the error “Bad Handle 0x7B4, the handle is invalid”.
VMWare have a knowledgebase article about this issue that recommends you disable UAC. I don’t like this solution because I do believe UAC is a good thing and I think it’s important the developers develop and test with UAC enabled to catch UAC issues in their software early (the same reason I think developers should develop on x64).
After discussing the problem with our Internal Systems people they suggested trying to add the site to the Intranet zone, and low and behold, it worked! So I suggest you try this before the more drastic solution of disabling UAC.
PowerShell Get-ChildItem and Hidden/System Files
A little gotcha is that PowerShell’s Get-ChildItem does not return hidden/system files by default (as with the dir command), if you want to include these files you need to include the –Force switch.
Running Virtual Server 2005 R2 on Windows Home Server
Windows Home Server is without a doubt one of the most useful additions to a home network. It provides three main features:
- Backup of client machines
- Shared storage
- Remote access to shared storage and client machines
This allows me to do complete backups both my partner’s and my machine as well as share files. As an added bonus it can stream music (and probably videos) to my XBox 360.
Because of the amount of work I do with Visual Studio Team System I thought it would be useful to have a Team Foundation Server at home and although I have spare hardware I didn’t really want to have to set up and maintain another machine (or pay for the electricity it would use!).
The solution was to install Virtual Server 2005 (which is free) on my Windows Home Server machine and then run Team Foundation Server as a virtual machine on the same host. The process to do this was relatively simple:
- Download Virtual Server 2005 R2 SP1.
- Remote desktop to the Windows Home Server.
- Install Virtual Server 2005 SP1.
- Using the Windows Home Server Console created a share (called VirtualMachines) and grant my user Full access to the share. Because the Virtual Server Administration Website impersonates the user you connect as you cannot see or create virtual machines on the share unless you have Full access to it.
- Open the Virtual Server Administration Website and login to it using the Windows Home Server’s Administrator account (at this point your normal user account doesn’t have the necessary permissions).
- In Server Properties | Virtual Server Security add an entry for your user account.
- In Server Properties | Virtual Machine Remote Control (VMRC) Server:
- Click the Enable checkbox.
- Select NTLM from the Authentication dropdown list. If you don’t do this you will get an Authentication Failed error when you try to remotely control the virtual machine.
- In Server Properties | Virtual Server Search Paths change the Default Virtual Machine Configuration Folder to the UNC path to the VirtualMachines share you created (for example, \\myhomeserver\VirtualMachines\).
- You can now create and run virtual machines on your Windows Home Server.
Freeing Up Space On C:
Scott Hanselman has posted a fantastic guide on how to free up space on C: on your Vista machine:
http://www.hanselman.com/blog/GuideToFreeingUpDiskSpaceUnderWindowsVista.aspx
Could Not Start Message in Windows Scheduler When Running Batch File on Windows Server 2003
I was getting the error “Could Not Start” in Windows Scheduler when trying to run a batch file as a non-administrator even though the user had permission to run as a batch job.
The issue was that the permissions on cmd.exe do not allow execution by batch jobs by default, this issue and the solutions are described in the following knowledgebase article:
Installing SQL Server 2005 On Windows Vista/IIS 7
While doing a SQL Server 2005 installation on Windows Vista I received a warning during the System Configuration Check stating that IIS was required although I already had IIS installed.
After some searching I found the following knowledgebase article http://support.microsoft.com/kb/920201 which describes how to resolve the warning.
Disable System Beep in VMWare
If you use VMWare regularly then you have no doubt suffered from system beeps from you virtual machines, here is how to disable it:
Windows Update Annoyance
One annoyance with Windows Update when installing a large number of updates on a server is updates that prompt you for input. A few times now I’ve kicked off a large update (for example, the one I’m doing now has 42 updates), you let it run, come back and the 3rd update is asking for input!