Posts Tagged 'Scripts'

PowerShell explorer extension

Using this extension, you can select “Command Prompt” when right-clicking a folder in the windows explorer. This will open up a PowerShell instance with the current directory set to the folder you clicked, this is quite useful to quickly jump from GUI to shell.

All you have to do is saving this script to myextension.reg and run it on the target machine.

Windows Registry Editor Version 5.00

@=”Command Prompt”

@=”\”C:\\WINDOWS\\system32\\WindowsPowerShell\\v1.0\\powershell.exe\” -NoExit -Command Set-Location -LiteralPath ‘%L'”

Thx to Jon for providing a better run command.


Display string as hex values

This tiny one-liner displays a custom string as hex values, quite useful..

PS C:\> "HEXIFY ME".ToCharArray() | % { ("0x{0:x}" -f [int]$_) } 0x48 0x45 0x58 0x49 0x46 0x59 0x20 0x4d 0x45

FATAL: Failed to spawn COM server

Today I installed Win XP on two completely different machines. After installing XP SP3 onto these machines, the windows update service somehow stopped working: Although it downloaded the patches it failed to initialize their installation, no matter what patch was selected. The log at C:\windows\WindowsUpdate.log showed several lines looking like this:

FATAL: Error: 0x80070005. wuauclt handler: failed to spawn COM server

After browsing the web, I found a solution to this, re-registering some components of the update service fixes the issue. I wrote this tiny script to automatize the fix:

Export installed Printers to HTML

I wrote another useful PowerShell one liner to collect data for a network documentation. It lists the installed printers on a computer and writes it as formatted table to an html file.

PS C:\> Get-WmiObject win32_printer -computer ADRIAN | ? { $_.type -ne 1 } | sort name | ConvertTo-Html -prop Name,DriverName,PortName,Location > c:\out.html

Now just copy&paste the result from the file into your network docs, time saved!

Processes on a remote machine

Get the currently running processes on a remote (ms) machine using WMI and PS:

PS C:\> Get-WmiObject -query "select * from win32_process" -computer ADRIAN | sort -property ProcessName | format-list ProcessName,Path

ProcessName : acrotray.exe
Path : C:\Programme\Adobe\Acrobat 8.0\Acrobat\Acrotray.exe

ProcessName : alg.exe
Path :

I didn’t think using WMI in PS would be that easy. I’m currently writing a network documentation for a customer and using WMI to collect data is quite useful..