Creating a Pidgin config file with PowerShell

As detailed in another post, I was able to get a Windows jabber/XMPP setup working eventually. This used Openfire as the server and Pidgin for the clients. The hard part was getting SSO (single sign-on) working, i.e. getting Pidgin to pass the builtin Windows credentials directly to Openfire (which uses LDAP).

The final step of all of this mess was to automatically setup Pidgin on the workstations. As long as MIT Kerberos for Windows is installed, Pidgin’s setup consists pretty much of the protocol (XMPP) and the username@domain. No password is needed in the config file since it’s using Kerberos (the whole point).

Anyway, the following PowerShell script is used at logon time to simply copy the certificate over and create the config file if it doesn’t exist already.

Now, there’s not much PowerShell in this script I realize, but what I think is cool is how it illustrates just how easy and flexible the language is regarding strings and variables. It’s essentially like writing in pseudocode, except it actually works.

# Creates accounts.xml for user and installs certificate

if ((test-path $env:appdata\.purple) -eq 0)
	"Setting up Pidgin..."
	mkdir $env:appdata\.purple\certificates\x509\tls_peers
	copy \\filesrv\share\company.local $env:appdata\.purple\certificates\x509\tls_peers\
	$acctinfo =
	"<?xml version='1.0' encoding='UTF-8' ?>

	<account version='1.0'>
		  <setting name='use-global-buddyicon' type='bool'>1</setting>
		  <setting name='require_tls' type='bool'>1</setting>
		  <setting name='ft_proxies' type='string'></setting>
		  <setting name='check-mail' type='bool'>0</setting>
		  <setting name='connect_server' type='string'></setting>
		  <setting name='old_ssl' type='bool'>0</setting>
		  <setting name='auth_plain_in_clear' type='bool'>0</setting>
		  <setting name='port' type='int'>5222</setting>
		  <setting name='custom_smileys' type='bool'>1</setting>
		<settings ui='gtk-gaim'>
		  <setting name='auto-login' type='bool'>1</setting>
	$acctinfo > $env:appdata\.purple\accounts.xml
	"Pidgin already setup!"