Archive for the ‘Apps’ Category

Function : Get-Function

February 24, 2011 Leave a comment

Here’s a time saver… well a quick function that has saved me a whole herd of time when trying to find a function that has been “forgotten”

Function Get-Function ($searchterm,[switch]$DEFINITION)
	$functions = @(Get-Command "*$searchterm*" -CommandType "Function")
	"`nFunctions matching ""$searchterm""`n" | Write-Host -ForegroundColor Green
	if (!$DEFINITION) {$functions | %{$}} else {$functions | %{"`n$($" | Write-Host -f Yellow ;$_.definition}}

sal gf Get-Function

the last line is setting an alias “gf”
– so let’s try this on something familiar… we had a function searching for apps…

Command: gf apps
Functions matching “apps”

Ahh – “installed apps”, let’s try that one again, and get Details this time:

Command: gf installedapps -de
Functions matching “installedapps”
param (
$regkey_x64 = “SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall”,
$regkey_x86 = “SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall”,
$bits_to_search = @()
if (!$EXCLUDE32){$bits_to_search += “x86”}
if (!$EXCLUDE64){$bits_to_search += “x64”}

$apps = @()
foreach ($bit in $bits_to_search)
$regkey = Get-Variable “regkey_$bit” | %{$_.value}
if (Test-Path HKLM:$regkey)
$reg = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey(“LocalMachine”,$computername)
$key = $reg.OpenSubKey($regkey)
$SubKeys = $key.GetSubKeyNames() | %{$key.OpenSubKey($_)}

foreach ($subkey in $subkeys)
$app = $subkey | select @{N=”Bit”;E={$bit}},`
if ($ {$apps += $app}

# Remove duplicates, but annoyingly names like of “C++” error when using “-match”
$unique_apps = @()
foreach ($app in $apps)
if (!($unique_apps | ?{$_.Bit -eq $app.bit} | ?{$ -eq $} |
?{$_.version -eq $app.version})) {$unique_apps += $app}

return $unique_apps | sort bit,name,version


Function : Get-InstalledApps

February 16, 2011 Leave a comment

So there I was happily using

gwmi win32_product 

to get me a list of installed applications, but this is slow, and often we just want a quick verification that an application is installed or not.

Thanks to and their “PowerTip of the Day” I was reminded about hitting the registry for this information…
So, inspired by their code, I hacked together a quick function to do this.

Note the removal of duplicates was first done as per the concept here Script of the Day – remove duplicate lines in a CSV file but there were a few entries with special characters in their names, eg “C++” that don’t play nicely with “-match” so this was recoded comparing each entry of the object. This is going to be slower, but still solves the “Get Installed Applications” faster than the WMI route!

Function Get-InstalledApps 
	param (
		$regkey_x86 = "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall",
		$regkey_x64 = "SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall",

	$apps = @()	
	foreach ($bit in "x86","x64")
		$regkey = Get-Variable "regkey_$bit" | %{$_.value}
		if (Test-Path HKLM:$regkey)
			$reg = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey("LocalMachine",$computername)
			$key = $reg.OpenSubKey($regkey)
			$SubKeys = $key.GetSubKeyNames() | %{$key.OpenSubKey($_)}
			foreach ($subkey in $subkeys)
				$app = $subkey | select @{N="Bit";E={$bit}},`
				if ($ {$apps += $app}
	# Remove duplicates, but annoyingly names like of "C++" error when using "-match"
	$unique_apps = @()
	foreach ($app in $apps) 
		if (!($unique_apps | ?{$_.Bit -eq $app.bit} | ?{$ -eq $} | 
		?{$_.version -eq $app.version})) {$unique_apps += $app}

return $unique_apps | sort bit,name,version

Extending a Windows C:\ Dell EXTPart

January 26, 2011 Leave a comment

I get many requests to extend the C:\ (or any other drive)
Most times these are for VMs – so it is pretty easy right? Extend the amount of disk allocated to the virtual machine, then extend in Computer Management – or using diskpart?

Well this does not always work – see, Windows does not really like you messing with system drive.

Well, Dell have come up with a brilliant tool called EXTPart

All you need to do now is provision the extra space to the VM, then run the tool at the command line and follow the wizard:

ExtPart - Utility to extend basic disks (Build 1.0.4)
(c) Dell Computer Corporation 2003

Volume to extend (drive letter or mount point): c:
Current volume size : 66285 MB (69504860160 bytes)
Current partition size : 76285 MB (79990815744 bytes)
Size to expand the volume (MB): 76285

that’s it – job done . . zero downtime (watch out of course . . this works differently if you have a clustered disk to extend – see: )

Authenticating through a proxy when the app has no option to do so

January 20, 2011 1 comment

Sometimes, you work in an environment where all web queries run through a proxy server and the proxy requires authentication . .

Then sometimes, you use apps that need to access the web . . and they don’t have a method of inputting Username and Password for Web connections.

The easy way to fix this is with a Squid Proxy (effectively, run a proxy server locally . . that authenticates to your web proxy)
All you need to do is use the following configuration settings:

# Listen only local interface rc:

# Parent proxy ( and Authentication settings
cache_peer parent 8080 0 no-query default login=User:Passwd

# No direct access
never_direct allow all

Of course, you may not have a Linux box available for you to run a Squid proxy . . Squid can compile and run on Windows as a system service using the Cygwin emulation environment

Alternatively and more easily, get a compiled version of Squid for Windows like :

Here’s a quick how to:

  1. Download the latest package from the above link
  2. Extract it (I extracted to c:squid for my example)
  3. Rename *.conf.default to *.conf for all files in c:squidetc
  4. Open the file squid.conf (Notepad / VI or whatever you favour)
  5. Amend the file as above – Save and exit . . .or use the file below if you’re battling and just replace the username / password, IP addresses and DNS servers

If you are battling, you could use the following file and simply edit the row starting with dns_nameservers
and the row starting with cache_peer

6. Now from a dos box, just run the following commands:
mkdir c:\squid\var\cache
c:\squid\sbin\squid -D

(this will start the Squid and ignore the DNS check it normally does at startup)

7. At this point your squid server is running. You should be able to point the proxy server for any app at and the authentication will be handled by the squid proxy. As a test I user the “Android SDK and AVD manager” which only allows specifying of Proxy, but not of credentials . . and all downloads ran properly.

Sample File

# [START - Copy from after this]
# HTTP Port (in this tutorial squid will run on localhost at port 3128)
# ICP Port and HTCP Port (we’ll disable this since we are not going to use it)
icp_port 0
htcp_port 0
# Cache Peer (we’ll forward all request into parent proxy)
cache_peer parent 8080 0 no-query default login=username:password #amend these . .the IP is the Proxy, and Username and Password need replacing.
# Cache directory (in this example i was using 30 MB space to store squid cache)
# cache_dir awin32 c:/squid/var/cache 3000 16 256
# access_log
access_log c:/squid/var/logs/access.log squid
# cache_log
cache_log c:/squid/var/logs/cache.log
# cache_store_log
cache_store_log none
# mime_table
mime_table c:/squid/etc/mime.conf
# pid_filename
pid_filename c:/squid/var/logs/
# unlinkd_program
unlinkd_program c:/squid/libexec/unlinkd.exe
# refresh_pattern (you can configure this as you like it, to get more hits from a website)
# note: if you change this parameter "refresh_pattern . 1 100% 20160 reload-into-ims ignore-reload” into something else for
# example like "refresh_pattern . 10 100% 20160 reload-into-ims ignore-reload”
# there’ll be some error on some page ( for an example) because the page didnt reload correctly after login into Gamefaqs
refresh_pattern ^http://.*.gif$ 1440 50% 20160 reload-into-ims
refresh_pattern ^http://.*.asis$ 1440 50% 20160
refresh_pattern -i .png$ 10080 150% 40320 reload-into-ims
refresh_pattern -i .jpg$ 10080 150% 40320 reload-into-ims
refresh_pattern -i .bmp$ 10080 150% 40320 reload-into-ims
refresh_pattern -i .gif$ 10080 300% 40320 reload-into-ims
refresh_pattern -i .ico$ 10080 300% 40320 reload-into-ims
refresh_pattern -i .swf$ 10080 300% 40320 reload-into-ims
refresh_pattern -i .flv$ 10080 300% 40320 reload-into-ims
refresh_pattern -i .rar$ 10080 150% 40320
refresh_pattern -i .ram$ 10080 150% 40320
refresh_pattern -i .txt$ 1440 100% 20160 reload-into-ims override-lastmod
refresh_pattern -i .css$ 1440 60% 20160
refresh_pattern ^http:// 1 100% 20160 reload-into-ims ignore-reload
refresh_pattern ^ftp:// 240 50% 20160
refresh_pattern ^gopher:// 240 40% 20160
refresh_pattern /cgi-bin/ 0 0% 30
refresh_pattern . 0 100% 20160 reload-into-ims
# Deny requests to unknown ports
# http_access deny !Safe_ports
# Deny CONNECT to other than SSL ports
# http_access deny CONNECT !SSL_ports
# Block access to Malware & ads farm site
# Insert your own rule here by using
# acl blablabla url_regex -i "path to file”
# or
# acl blablabla url_regex "path to file”
acl all src
http_access allow all
# http_access deny all
cache_mgr Reaper-X
httpd_suppress_version_string on
visible_hostname Reaper
via off
forwarded_for off
log_icp_queries off
client_db off
never_direct allow all
#Some anonymizing
header_access From deny all
#there’s some website which use referer check
#so its better to disable this
#header_access Referer deny all
header_access WWW-Authenticate deny all
header_access Link deny all
header_access Warning deny all
header_access Via deny all
header_access User-Agent deny all
header_access Proxy-Connection deny all
header_access X-Forwarded-For deny all

#[END – Copy to before here]

What we are doing here in effect is running the Squid proxy as a local proxy, that has the authnetication to your Network Proxy already configured. the squid.conf contains the username and passwpord and any request sent from your cliebt via the squid proxy thus has the request redirected and processed using an authenticated connection.

The added bonus of course is that you can set your local squid proxy to cache your web requests, thus in theory having your own local cahing proxy that never requires manual authentication.

Interestingly, if you are normally prompted for authentication when you access your work proxt, you should now stop seeing the prompt, as you dekstop / laptop will never communicate directly with the proxy anymore (unless of course you tell it to)

Happy Days

Categories: Apps, Tech Tips, Toolbox Tags: , , ,

Essential Tools . . FastSCP

January 20, 2011 Leave a comment

how many times have you had to move a VM from a Datastore on one ESX host to that on another.

Sure – storage migrate is an easy option  . . . if you

a) Have a vCenter

b) Are presenting both sets of storage to an ESX host

and/or c)  are licensed to the correct level.

the solution . . Veeam’s FastSCP.

simple – register at

Download . . connect to both ESX hosts . . and copy / move away like you’re a Windows GUI user (though of course you’re a geek . . .so you would have preferred to do it from the command line)

Happy Days..

you can add the ESX hosts, or your VC . . or even multiple VC is you have them (I use this to move vmdks between the lab and production . .

Once you’ve added your Virtual Centre(s) – you can simply browse the datastores and copy  files as if you were using Windows explorer.