Yearly Archives: 2008

Powershell Script to Connect to SQL Server and get some information

A quick script to connect to an sql sserver and get the information from a table.  In this case find the SQL Proxy accounts from the msdb database.

 # SQL Server and Database Information
 $SqlServer = “.”;
 $SqlCatalog = “msdb”;

 # SQL Query Statement
 $q= “EXEC dbo.sp_help_proxy”

 $cn = new-object system.data.SqlClient.SqlConnection(“Data Source=$SqlServer;Integrated Security=SSPI;Initial Catalog=$SqlCatalog”);
 $ds = new-object “System.Data.DataSet” “dbo”

 $da = new-object “System.Data.SqlClient.SqlDataAdapter” ($q, $cn)

 $junk = $da.Fill($ds)
 
 $proxyAccounts = new-object “System.Data.DataTable” “dtPersonData”
 $proxyAccounts = $ds.Tables[0]

 $proxyAccounts | FOREACH-OBJECT {“” + $_.Name}

Read More

PowerShell Script to compare two lists

A quick script to compare two arrays.

$arrFirst = get-content First.txt
$arrSecond = get-content Second.txt

New-Item “C:MyworkplacepsFirstInSecond.txt” -Type file
New-Item “C:MyworkplacepsFirstNotInSecond” -Type file

Foreach ($First in $arrFirst)
{
If ($arrSecond -contains $First)
{Add-content “C:MyworkplacepsFirstInsecond.txt” $First}
Else
{Add-content “C:MyworkplacepsFirstNotInSecond.txt” $First}

Read More

PowerShell script to add/remove a domain user to the Local Administrators group on a remote machine

Here is a PowerShell script to add/remove a domain user to the Local Administrators group on a remote machine and you can easily make it to work on multiple remote machines using the technique in my previous script

# if your user name is whatevertest

$domain = “whatever”
$strComputer = “XYZ”
$username = “test”

$computer = [ADSI](“WinNT://” + $strComputer + “,computer”)
$computer.name

$Group = $computer.psbase.children.find(“administrators”)
$Group.name

# This will list what’s currently in Administrator Group so you can verify the result

function ListAdministrators

{$members= $Group.psbase.invoke(“Members”) | %{$_.GetType().InvokeMember(“Name”, ‘GetProperty’, $null, $_, $null)}
$members}
ListAdministrators

# Even though we are adding the AD account but we add it to local computer and so we will need to use WinNT: provider

$Group.Add(“WinNT://” + $domain + “/” + $username)

ListAdministrators

$Group.Remove(“WinNT://” + $domain + “/” + $username)

ListAdministrators

Read More

Ripping DVDs

This is an excellent article on WinSuperSite explaining how to rip DVDs.  I am in the process of converting all of my DVD collection to MP4.  This article was written for handbrake version 9.2 but as 9.3 is available some of the steps are a little simpler.

Read More

How to use an Apple keyboard with Windows

I have always envied the thin mac keyboards and I finally got me one.  Couple of customizations are very useful when using it with a PC.  Alt and Windows key are in the wrong order as you are used to on a windows keyboard.  So here is how i did it…

Introducing AutoHotKey

AutoHotKey is freeware software for Windows that lets you create easy-to-write scripts that define alternate key mappings in Windows. You can do the same by hacking the Windows registry yourself – but that’s just plain silly.

The script

After you’ve installed AutoHotKey, you can use the below script and run it. This will load a set of pre-defined rules that will make your Apple keyboard operate like a Windows one.

Here’s the rules I’m using:

; Swap Windows (Command) and Alt keys
; These button locations are reversed on Mac keyboards
LAlt::LWin
LWin::LAlt

To have this script run every time Windows boots up, save it in your Startup folder (Start -> All Applications -> Startup).

Read More

Installing PHP for IIS on Windows Home Server

If you’re interested in running a website from your home server, you may have considered various options, including running PHP. But running PHP with IIS can be fraught with problems – or at least was, until WGS reader, Christopher Courtney, wrote the following guide to installing PHP for IIS on Windows Home Server. Over to Christopher…

Because running IIS and Apache really isn’t feasible, one needs to be able to install PHP into IIS. If you have tried before or searched for how, you will notice many different ways, and a lot of problems with doing so. I’ve tried several times and gotten the same problem, but finally fixed it and got PHP working under IIS. Now I am going to share it.

more

Read More