Archive

Archive for the ‘Windows 7’ Category

Joining a Windows 7 Client to a Domain through PowerShell

June 5th, 2009 Niklas Goude 2 comments

Time to join a Windows 7 client to a domain. Now that the Test Domain is up and running ( Check Previous Posts ), we can start joining clients to the domain.

Since it’s a freshly installed Windows 7 client, we dont have to bother about userprofiles and so on.. we’ll save that for later :)

Joining the domain is done through WMI. Just create a new Object containing the Win32_ComputerSystem WMI object and call the JoinDOmainOrWorkGroup() method.


function JoinDomain ([string]$Domain, [string]$User, [string]$Password ) {

	$DomainUser = $Domain + "\" + $User
	$OU = $null

	$ComputerSystem = gwmi Win32_ComputerSystem

	$ComputerSystem.JoinDomainOrWorkGroup(
		$Domain,
		$Password,
		$DomainUser,
		$OU,
		3
	)
}

Here’s an example on running the function.


PS > JoinDomain PowerShell.nu migaccount Password1

And voila! the client shuts down and on Startup, It’ll have joined the new domain.

Rating 3.00 out of 5
[?]
Categories: Projects, Windows 7 Tags: ,

Write-StickyNote

June 5th, 2009 Niklas Goude No comments

Here’s a fun script that uses the new “Sticky Notes” in WIndows 7.

The script is based on a simple function that uses the SendKeys() method through the Wscript.Shell COM object. This is a nice example on how you can handle COM objects through PowerShell.

I’ve also included an if statement that checks if StickyNotes is active. If that’s the case, the text will be started in a new StickyNotes.. note..

Anyway, here’s the function.


function Write-StickyNote ([string]$Text) {

	if (gps | Where { $_.ProcessName -match "stikynot" }) {

		$StickyNote = $True
	}

	$Wscript = New-Object -Com Wscript.Shell
	[void]$Wscript.Run("stikynot.exe")
	start-sleep 1

	if ($StickyNote -eq $True) {

		$Wscript.SendKeys("^n")
	}

	$Wscript.SendKeys($Text)
}

And here’s an example on running the function.


PS > .\Write-StickyNote.ps1 "Hello from PowerShell.nu"

stickynotes01

Click here to download the Script

Rating 3.00 out of 5
[?]
Categories: COM Object, Windows 7 Tags: