Post from June, 2009

How To Detect An ICA Client And Its Version Number?

Saturday, 27. June 2009 18:56

With a few lines of code you can check if an ICA Client is installed and, if yes, determine its version.

The code below defines a function Get-ICAClientVersion. The function returns the value of the "ClientVersion" property of the "Citrix.ICAClient" COM object, or returns 0 if the object is not present (that is no ICA Client 8 or higher installed)

function Get-ICAClientVersion
{
	$ErrorActionPreference = "SilentlyContinue"
	$ica = New-Object -ComObject 'Citrix.ICAClient'
	if($ica)
	{
		return $ica.ClientVersion
	}
	else
	{
		return 0
	}
}

Category:Scripting, Windows PowerShell | Comment (0) | Author: Frank-Peter

How To Test Existence Of An Object In Active Directory?

Wednesday, 10. June 2009 11:07

The function below, Test-ADObject, searches for the specified user, group, or computer in Active Directory and returns either the object’s DN or False.

The function uses the System.DirectoryServices.DirectorySearches class from NET Framework.

function Test-ADObject (
	$objectClass = $(throw "No AD object class specified."),
	$name        = $(throw "No AD object name specified.")
)
{
	switch($objectClass)
	{
		"User"     {$filter = "(&(objectClass=User)(displayName=$name))"}
		"Group"    {$filter = "(&(objectClass=Group)(name=$name))"}
		"Computer" {$filter = "(&(objectClass=Computer)(name=$name))"}
		default    {throw "Unknown objectClass specified."}
	}
	$domainRoot = [System.DirectoryServices.ActiveDirectory.Forest]::GetCurrentForest().RootDomain.Name
	$searcher = New-Object System.DirectoryServices.DirectorySearcher([ADSI]"GC://$domainRoot")
	$searcher.Filter = $filter
	$result = $searcher.FindOne()
	if($result)
	{
		$result.GetDirectoryEntry()
	}
	else
	{
		$False
	}
}

Category:Scripting, Windows PowerShell | Comment (0) | Author: Frank-Peter

How To Uninstall An Application That Has Been Installed Using MSI?

Monday, 8. June 2009 13:38

I know that I can use Msiexec /X and the applications product code to uninstall an application that has been installed using Microsoft Installer (MSI) technology. Is there a simpler approach?

You can use the Win32_Product WMI class’ Uninstall method to uninstall software that came with an MSI setup. All you need to now is the application’s name as it is registered in Windows. The following example uninstalls the XML Notepad 2007 application:

# Uninstall "XML Notepad 2007"
(Get-WmiObject Win32_Product -filter "Name='XML Notepad 2007'").Uninstall()

Category:Scripting, Windows PowerShell | Comment (0) | Author: Frank-Peter