<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>LegacyCode's blog</title>
	<atom:link href="http://www.legacycode.net/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.legacycode.net</link>
	<description>Scripting, configuring, managing, windows and linux</description>
	<lastBuildDate>Tue, 13 Nov 2012 09:55:24 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.5.1</generator>
		<item>
		<title>Domain Join using Powershell</title>
		<link>http://www.legacycode.net/2012/11/13/domain-join-using-powershell/</link>
		<comments>http://www.legacycode.net/2012/11/13/domain-join-using-powershell/#comments</comments>
		<pubDate>Tue, 13 Nov 2012 09:50:57 +0000</pubDate>
		<dc:creator>Ricky</dc:creator>
				<category><![CDATA[IT related]]></category>
		<category><![CDATA[Powershell]]></category>
		<category><![CDATA[Scripting]]></category>
		<category><![CDATA[Windows]]></category>

		<guid isPermaLink="false">http://www.legacycode.net/?p=193</guid>
		<description><![CDATA[Example of how to join a computer (Windows 8) to a domain using PowerShell.]]></description>
				<content:encoded><![CDATA[<p>Example of how to join a computer (Windows 8) to a domain using PowerShell.</p>
<pre class="brush: powershell; title: ; notranslate"> $Credential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList @('ALTIRIS\srv_altiris', (ConvertTo-SecureString -AsPlainText -Force 'P@ssw0rd' ))
Add-Computer -DomainName altiris.local -OUPath 'OU=CORPORATE_COMPUTERS,OU=BELGIUM,DC=altiris,DC=local' -PassThru -Verbose -Credential $credential </pre>
]]></content:encoded>
			<wfw:commentRss>http://www.legacycode.net/2012/11/13/domain-join-using-powershell/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>CentOS &#8211; Launching VMWare Workstation VMs at boot</title>
		<link>http://www.legacycode.net/2011/01/23/centos-launching-vmware-workstation-vms-at-boot/</link>
		<comments>http://www.legacycode.net/2011/01/23/centos-launching-vmware-workstation-vms-at-boot/#comments</comments>
		<pubDate>Sun, 23 Jan 2011 09:30:40 +0000</pubDate>
		<dc:creator>Ricky</dc:creator>
				<category><![CDATA[Bash]]></category>
		<category><![CDATA[CentOS]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[VMWare]]></category>

		<guid isPermaLink="false">http://www.legacycode.net/?p=172</guid>
		<description><![CDATA[A daemon script that starts a VMWare Workstation Team during boot and suspends it during shutdown.]]></description>
				<content:encoded><![CDATA[<p>I was searching for a solution to launch and suspend VMWare Workstation VMs on a CentOS 5-machine during boot/shutdown.<br />
A script script for launching VirtualBox VMS during boot inspired me to create one for VMWare Workstation.<br />
In this example I have teamed my VMs in a team /vms/my_team.vmtm, it could as well be a single VM (.vmx) that is being launched.<br />
The VM Team will be launched with a different user account as VMWare not allows root to launch VMs.<br />
During shutdown root however can suspend the VM Team, and this is also the action being used during system shutdown.</p>
<ol>
<li> Create a user vmuser </li>
<p> <code> useradd vmuser<br />
passwd vmuser </code> </p>
<li> Create the VMHeadless script. I have teamed all my VMS and will launch/suspend the team /vms/my_team.vmtm </li>
<p> <code> vi /etc/init.d/vmheadless </code> </p>
<pre class="brush: bash; title: ; notranslate"> 
#!/bin/bash
### BEGIN INIT INFO
# Provides:          vmheadless.sh
# Required-Start:    $remote_fs $syslog
# Required-Stop:     $remote_fs $syslog
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# chkconfig: 2345 99 20
# Short-Description: Start VM
# Description:       Start/stop the virtual machines
### END INIT INFO

MACHINE_NAME=&quot;/vms/my_team.vmtm&quot;
VM_USER=&quot;vmuser&quot;
RETVAL=0
LD_LIBRARY_PATH=/usr/lib/vmware:$LD_LIBRARY_PATH
PATH=/sbin:/usr/sbin:/bin:/usr/bin:/usr/local/bin

id=`id -u`
if  [ &quot;$id&quot; != &quot;0&quot; ] ; then
   echo &quot;This script must be run as root&quot; 1&gt;&amp;2
   exit 1
fi

# Load the VERBOSE setting and other rcS variables
 [ -f /etc/default/rcS ]  &amp;&amp; . /etc/default/rcS

# Load the VERBOSE setting and other rcS variables
#. /lib/init/vars.sh

# Define LSB log_* functions.
# Depend on lsb-base (&gt;= 3.0-6) to ensure that this file is present.
. /lib/lsb/init-functions

# Get function from functions library
. /etc/init.d/functions

# Load network defaults. Use this if there is any extra network stuff to do first.

case &quot;$1&quot; in
start)
   su $VM_USER -c &quot;/usr/bin/vmrun start $MACHINE_NAME nogui&quot;
        RETVAL=0
  echo &quot;Started VM Headless RETVAL=($RETVAL)&quot;
        ;;
stop)
  /usr/bin/vmrun suspend &quot;$MACHINE_NAME&quot;
        RETVAL=$?
 echo &quot;Suspended VM Headless RETVAL=($RETVAL)&quot;
        ;;
status)
  ps=`ps -ef | grep vmware-vmx | grep -v grep | wc -l`
  if  [ &quot;$ps&quot; -gt 0 ]  ; then
    echo &quot;$ps VMS started&quot;
    RETVAL=1
  else
    echo &quot;VMS not running&quot;
    RETVAL=0
  fi
        ;;
restart)
  /usr/bin/vmrun suspend &quot;$MACHINE_NAME&quot; nogui
        RETVAL=$?
 echo &quot;Suspended VM Headless RETVAL=($RETVAL)&quot;
  su backup -c &quot;/usr/bin/vmrun -T ws start $MACHINE_NAME nogui&quot;
        RETVAL=$?
  echo &quot;Started VM Headless RETVAL=($RETVAL)&quot;
        ;;
*)
        echo &quot;Usage: $0 { start | stop }&quot;
        RETVAL=1
        ;;
esac
exit $RETVAL
 </pre>
<li> Enable VMHeadless during boot </li>
<p> <code> chkconfig --add vmheadless<br />
chkonfig --level 2345 vmheadless on<br />
 </code> </p>
<li> Launch the VMHeadless daemon, and thus launching the VM Team </li>
<p> <code> service vmheadless start </code>
 </ol>
]]></content:encoded>
			<wfw:commentRss>http://www.legacycode.net/2011/01/23/centos-launching-vmware-workstation-vms-at-boot/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PS &#8211; Disable Unidentified network for VM nics</title>
		<link>http://www.legacycode.net/2010/10/06/ps-disable-unidentified-network-for-vm-nics/</link>
		<comments>http://www.legacycode.net/2010/10/06/ps-disable-unidentified-network-for-vm-nics/#comments</comments>
		<pubDate>Wed, 06 Oct 2010 11:30:04 +0000</pubDate>
		<dc:creator>Ricky</dc:creator>
				<category><![CDATA[IT related]]></category>
		<category><![CDATA[Powershell]]></category>
		<category><![CDATA[Scripting]]></category>
		<category><![CDATA[VMWare]]></category>

		<guid isPermaLink="false">http://www.legacycode.net/?p=161</guid>
		<description><![CDATA[This script adds the *NdisDeviceType registry value with value 1 to the keys of the VMWare network cards.
Afterwards it disables and enables the networkcards to let the changes take effect.]]></description>
				<content:encoded><![CDATA[<p>This script adds the *NdisDeviceType registry value with value 1 to the keys of the VMWare network cards.<br />
Afterwards it disables and enables the networkcards to let the changes take effect.</p>
<pre class="brush: powershell; title: ; notranslate"> 
$nics = gci &quot;HKLM:\SYSTEM\\CurrentControlSet\\Control\\Class\\{4D36E972-E325-11CE-BFC1-08002BE10318}&quot;
$nics | foreach-object -process {
	$devInstanceId = $_.getvalue(&quot;DeviceInstanceID&quot;)
	if($devInstanceId -match &quot;VMWARE&quot;){
		Write-Host $_.Name
		$regpath = ( $_.name ) -replace(&quot;HKEY_LOCAL_MACHINE&quot;,&quot;HKLM:&quot;)
		new-itemproperty -path $regpath -name &quot;*NdisDeviceType&quot; -value 1 -PropertyType &quot;DWORD&quot;
	}
}

 $wminics = get-wmiobject win32_networkadapter | where-object {$_.name -like &quot;*vmware*&quot; } 
 $wminics | foreach-object -process {  
       
     write-host -nonew &quot;Disabling $($_.name) ... &quot; 
     $result = $_.Disable()  
     if ($result.ReturnValue -eq -0) { write-host &quot; success.&quot; } else { write-host &quot; failed.&quot; }  
       
     write-host -nonew &quot;Enabling $($_.name) ... &quot; 
     $result = $_.Enable()  
     if ($result.ReturnValue -eq -0) { write-host &quot; success.&quot; } else { write-host &quot; failed.&quot; }  
 }
 </pre>
]]></content:encoded>
			<wfw:commentRss>http://www.legacycode.net/2010/10/06/ps-disable-unidentified-network-for-vm-nics/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Outlook VBA &#8211; remove reminders</title>
		<link>http://www.legacycode.net/2010/08/27/outlook-vba-remove-reminders/</link>
		<comments>http://www.legacycode.net/2010/08/27/outlook-vba-remove-reminders/#comments</comments>
		<pubDate>Fri, 27 Aug 2010 12:20:29 +0000</pubDate>
		<dc:creator>Ricky</dc:creator>
				<category><![CDATA[IT related]]></category>
		<category><![CDATA[Scripting]]></category>
		<category><![CDATA[VBA]]></category>
		<category><![CDATA[Windows]]></category>

		<guid isPermaLink="false">http://www.legacycode.net/?p=141</guid>
		<description><![CDATA[Small macro that disable reminders for all future calendar entries with a certain subject.]]></description>
				<content:encoded><![CDATA[<p>I synchronize my Windows Mobile Device with my corporate-exchange account. This way my calendar stays nicely up to date and gives me reminders for the tasks I have to do. <br/><br />
However I find it rather a hassle that I receive reminders for certain activities like holidays. Therefore I have written a small macro that disables the reminders for all future calendar entries with a certain subject.</p>
<pre class="brush: vb; title: ; notranslate"> 
Private Sub RemoveReminders(sProject As String)
Dim fldMailbox As MAPIFolder
Dim fldCalendar As MAPIFolder

Dim objItem As AppointmentItem
Dim iCntr As Integer
iCntr = 0

Set fldMailbox = Session.Folders(sMailboxName)
Set fldCalendar = fldMailbox.Folders(&quot;Calendar&quot;)
Set mcolCalItems = fldCalendar.Items

For Each objItem In mcolCalItems
If objItem.start &gt; Now() Then
If objItem.ReminderSet = True Then
    If InStr(objItem.Body, sProject) &gt; 0 Then
    iCntr = iCntr + 1
With objItem
.ReminderSet = False
.Save
End With

objItem.Save
End If
End If
End If
Next

MsgBox &quot;Modified &quot; &amp; iCntr &amp; &quot; calendar entries&quot;
End Sub

Public Sub RemoveHolidayReminders()
RemoveReminders (&quot;Holiday&quot;)
End Sub
 </pre>
]]></content:encoded>
			<wfw:commentRss>http://www.legacycode.net/2010/08/27/outlook-vba-remove-reminders/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>ESXi 3.5 and Server 2003 dualboot</title>
		<link>http://www.legacycode.net/2010/01/31/esxi-3-5-server-2003-dualboot/</link>
		<comments>http://www.legacycode.net/2010/01/31/esxi-3-5-server-2003-dualboot/#comments</comments>
		<pubDate>Sun, 31 Jan 2010 10:34:14 +0000</pubDate>
		<dc:creator>Ricky</dc:creator>
				<category><![CDATA[IT related]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[VMWare]]></category>
		<category><![CDATA[Windows]]></category>
		<category><![CDATA[dual boot]]></category>
		<category><![CDATA[ESxi]]></category>
		<category><![CDATA[server 2003]]></category>
		<category><![CDATA[syslinux]]></category>

		<guid isPermaLink="false">http://www.legacycode.net/?p=126</guid>
		<description><![CDATA[Description how to dual boot ESXi and Server 2003]]></description>
				<content:encoded><![CDATA[<p>After some testing I managed to create a dualboot setup with ESXi 3.5 and Windows Server 2003.</p>
<ol>
<li>  Install ESXi to harddisk 1 </li>
<li> Install Windows Server 2003 to harddisk 2.  Delete the existing partition on harddisk 2 if ESXi has created one.<br />
On the first reboot during the installation you should get an error &#8220;NTLDR is missing&#8221; </li>
<li> Boot with a live linux cd-rom, eg KNOPPIX </li>
<li> (Re-)install syslinux  bootloader to boot partition (Hypervisor0)
<pre class="brush: plain; title: ; notranslate"> sudo syslinux /dev/hda1
file is read only. overwrite anyway (y/n)? y
sudo mkdir /mnt/Hypervisor0
sudo mount /dev/hda1 /mnt/Hypervisor0
vi /mnt/Hypervisor0/syslinux.cfg
 </pre>
<p>original:</p>
<pre class="brush: plain; title: ; notranslate"> 
default safeboot.c32
 </pre>
<p>modified:</p>
<pre class="brush: plain; title: ; notranslate"> 
default menu.c32
menu title Dual boot
timeout 100

label esx
menu label ESXi 3.5
COM32 safeboot.c32

LABEL win
MENU LABEL MS Windows Server 2003
COM32 chain.c32
APPEND boot ntldr=/NTLDR
 </pre>
</li>
<li> Copy syslinux modules menu.c32 and chain.c32 to boot partition (Hypervisor0)<br />
Use locate to find the folder on the live cd that contains the modules, eg  <span style="font-family: courier"> locate menu.c32 </span> </p>
<pre class="brush: plain; title: ; notranslate"> 
cp /usr/lib/syslinux/menu.c32 /mnt/Hypervisor0
cp /usr/lib/syslinux/chain.c32 /mnt/Hypervisor0
 </pre>
</li>
<li> Reboot </li>
</ol>
]]></content:encoded>
			<wfw:commentRss>http://www.legacycode.net/2010/01/31/esxi-3-5-server-2003-dualboot/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Tool to query SQL databases</title>
		<link>http://www.legacycode.net/2010/01/15/tool-to-query-sql-databases/</link>
		<comments>http://www.legacycode.net/2010/01/15/tool-to-query-sql-databases/#comments</comments>
		<pubDate>Fri, 15 Jan 2010 08:51:06 +0000</pubDate>
		<dc:creator>Ricky</dc:creator>
				<category><![CDATA[Powershell]]></category>
		<category><![CDATA[Scripting]]></category>
		<category><![CDATA[datatable]]></category>
		<category><![CDATA[Excel]]></category>
		<category><![CDATA[SQL]]></category>

		<guid isPermaLink="false">http://www.legacycode.net/?p=93</guid>
		<description><![CDATA[This is a tool written in PowerShell which allows you to perform queries against SQL server databases. Output is by default displayed in a datatable, output can also exported to an Excel document.]]></description>
				<content:encoded><![CDATA[<p>For some tasks it is useful to run a custom query against a database.<br />
The application using the database perhaps does not have the ability to generate certain reports.<br />
Using SQL manager is a viable option, but then everyone who needs to have this installed to be able to run a query.<br />
It is however possible to create some Excel-files which have the queries embedded.</p>
<p>But as an alternative solution I have created this PowerShell app.<br />
It is a GUI-based tool allowing you to select a saved script or enter a custom query and run it.<br />
The output is by default displayed in a datatable but the output can also be exported to an Excel-document.</p>
<p>The available SQL servers are defined in  <span style="font-family: courier;"> servers.xml </span><br />
And to avoid the hassle of selecting a server and database after selecting a script you can predefine a combination of a shortname, server and database in  <span style="font-family: courier;"> shortnames.xml </span><br />
Eg. if you have a SQL-file  <span style="font-family: courier;"> hlp_openincidents.sql </span>  and  <span style="font-family: courier;"> hlp </span>  is defined in  <span style="font-family: courier;"> shortnames.xml </span>  with server set to  <span style="font-family: courier;"> SQLSERVER </span>  and database to  <span style="font-family: courier;"> HELPDESK </span>  the tool will autoselect the server:  <span style="font-family: courier;"> SQLSERVER </span>  and the database:  <span style="font-family: courier;"> HELPDESK </span> </p>
<span><a href="http://www.legacycode.net/wp-content/plugins/download-monitor/download.php?id=1" title="Downloaded 619 times"><img src="/wp-includes/images/crystal/archive.png"  style="vertical-align:middle;" alt="SQL tool source code" /> SQL tool source code</a></span>
]]></content:encoded>
			<wfw:commentRss>http://www.legacycode.net/2010/01/15/tool-to-query-sql-databases/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Script software deployment in PowerShell</title>
		<link>http://www.legacycode.net/2010/01/10/script-altiris-ds-software-deployment-in-powershell/</link>
		<comments>http://www.legacycode.net/2010/01/10/script-altiris-ds-software-deployment-in-powershell/#comments</comments>
		<pubDate>Sun, 10 Jan 2010 19:10:17 +0000</pubDate>
		<dc:creator>Ricky</dc:creator>
				<category><![CDATA[Altiris]]></category>
		<category><![CDATA[IT related]]></category>
		<category><![CDATA[Powershell]]></category>
		<category><![CDATA[Scripting]]></category>
		<category><![CDATA[Altiris DS]]></category>
		<category><![CDATA[Deployment Solution]]></category>

		<guid isPermaLink="false">http://www.legacycode.net/?p=115</guid>
		<description><![CDATA[This is an example in PowerShell of how you can schedule the installation a software package by Altiris DS.
Instead of using the API, the command-line tool axsched is being called to schedule the software package.]]></description>
				<content:encoded><![CDATA[<p>This is an example in PowerShell of how you can schedule the installation a software package by Altiris DS.<br />
Instead of using the API, the command-line tool  <span style="font-family: courier;"> axsched </span>  is being called to schedule the software package.</p>
<pre class="brush: powershell; title: ; notranslate"> 
function DeploySoftware
{
	param( [String] $pcname,  [String] $package,  [String] $nexttime,  [String] $folder)
	#Write-Host &quot;Deploy $pcname '$package' /t $nexttime /f '$folder'&quot;
	#\\ALTIRIS\express\axsched.exe &quot;$pcname&quot; &quot;$package&quot; / t &quot;$nexttime&quot; / f &quot;$folder&quot;
		
	$StartInfo = New-Object System.Diagnostics.ProcessStartInfo
	$StartInfo.CreateNoWindow = $true
	$StartInfo.UseShellExecute = $false
	$StartInfo.FileName = &quot;\\ALTIRIS\express\axsched.exe&quot;
	$StartInfo.WorkingDirectory = &quot;C:\Temp&quot;
	$StartInfo.Arguments = &quot;`&quot;$pcname`&quot; `&quot;$package`&quot; /t `&quot;$nexttime`&quot; /f `&quot;$folder`&quot;&quot;
	$p =  [System.Diagnostics.Process] ::Start($StartInfo)
	$p.WaitForExit()
	if ($p.ExitCode -eq 0) { $TRUE } else { $FALSE }
}
#This function adds a number of minutes to the given date time and outputs the addition in the right format for AxSched.
function Get-ScheduleTime
{
	param( [System.DateTime]  $starttime,  [int] $minutes)
	#$minutes = 12
	$tspan = New-Object System.TimeSpan(0, 0, $minutes, 0)
	$addtime =  [System.DateTime] ::op_Addition($starttime, $tspan)
	#&quot;2008-10-20 15:00&quot;
	$y = $addtime.Year
	$mo = $addtime.Month
	$d = $addtime.Day
	$h = $addtime.Hour
	$mi = $addtime.Minute
	$schedtime = &quot;$y&quot;
	$schedtime += &quot;-&quot;
	$schedtime += TwoDecimal(&quot;$mo&quot;)
	$schedtime += &quot;-&quot;
	$schedtime += TwoDecimal(&quot;$d&quot;)
	$schedtime += &quot; &quot;
	$schedtime += TwoDecimal(&quot;$h&quot;)
	$schedtime += &quot;:&quot;
	$schedtime += TwoDecimal(&quot;$mi&quot;)
	$schedtime
}
#Simple function to convert a single decimal to a two decimal, eg 7 becomes 07
function TwoDecimal
{
	param( [String] $Number)
	while ($number.Length -lt 2) { $number = &quot;0$number&quot; } 
	$number
}
$now =  [System.DateTime] ::Now
$pcname = &quot;COMP007&quot;
$jobname = &quot;Install Outlook 2007&quot;
$jobfolder = &quot;Software&quot;
#The installation of the package needs to be started after 5 minutes.
$nexttime = Get-ScheduleTime $now 5
DeploySoftware $pcname $jobname $nexttime $jobfolder 
 </pre>
]]></content:encoded>
			<wfw:commentRss>http://www.legacycode.net/2010/01/10/script-altiris-ds-software-deployment-in-powershell/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Powershell check requirements and load addins</title>
		<link>http://www.legacycode.net/2010/01/10/ps-check-requirements-and-load-addins/</link>
		<comments>http://www.legacycode.net/2010/01/10/ps-check-requirements-and-load-addins/#comments</comments>
		<pubDate>Sun, 10 Jan 2010 18:41:12 +0000</pubDate>
		<dc:creator>Ricky</dc:creator>
				<category><![CDATA[Powershell]]></category>
		<category><![CDATA[Scripting]]></category>
		<category><![CDATA[.net]]></category>
		<category><![CDATA[Altiris]]></category>
		<category><![CDATA[asdk]]></category>
		<category><![CDATA[dotnet]]></category>
		<category><![CDATA[Quest AD]]></category>

		<guid isPermaLink="false">http://www.legacycode.net/?p=104</guid>
		<description><![CDATA[Powershell excerpts of how to check if .NET FrameWork 3.5, Quest AD, Altiris ASDK is installed]]></description>
				<content:encoded><![CDATA[<p>Powershell excerpts of how to check if .NET FrameWork 3.5, Quest AD, Altiris ASDK is installed</p>
<p>First the functions that execute the installer.</p>
<pre class="brush: powershell; title: ; notranslate"> 
function Execute-Installer()
{
	param( [String] $parameters, [String] $msiworkingdir)
	$msiworkingdir = Resolve-Path $msiworkingdir
	$StartInfo = New-Object System.Diagnostics.ProcessStartInfo
	$StartInfo.CreateNoWindow = $true
	$StartInfo.UseShellExecute = $false
	$StartInfo.FileName = &quot;c:\windows\system32\msiexec.exe&quot;
	$StartInfo.WorkingDirectory = &quot;$msiworkingdir&quot;
	$StartInfo.Arguments = &quot;$parameters&quot;
	$p =  [System.Diagnostics.Process] ::Start($StartInfo)
	$p.WaitForExit()
	if ($p.ExitCode -eq 0) { $TRUE } else { $FALSE }
}

function Execute-Program()
{
	param( [String] $parameters, [String] $program)
	Write-Host &quot;Execute-Program $program $parameters&quot;
	#Write-Host &quot;MSI WorkingDir: $msiworkingdir&quot;
	#$msiworkingdir = Resolve-Path $msiworkingdir
	$program = Resolve-Path $program
	Write-Host &quot;Program: $program&quot;
	$StartInfo = New-Object System.Diagnostics.ProcessStartInfo
	$StartInfo.CreateNoWindow = $true
	$StartInfo.UseShellExecute = $false
	$StartInfo.FileName = $program
	$StartInfo.Arguments = &quot;$parameters&quot;
	$p =  [System.Diagnostics.Process] ::Start($StartInfo)
	$p.WaitForExit()
	if ($p.ExitCode -eq 0) { $TRUE } else { $FALSE }
}
 </pre>
<p>The code that checks if .NET FrameWork 3.5 is installed.<br />
A messagebox will be displayed if it is not installed.<br />
If users answers yes to the messagebox the requirement will be installed.</p>
<pre class="brush: powershell; title: ; notranslate"> 
#region Check if .NET 3.5 is installed (Requirement for QuestAD and AltirisASDK
function Check-DotNet35{
Write-Host &quot;Check-DotNet35&quot;
$net35 = get-itemproperty &quot;hklm:\\SOFTWARE\Microsoft\NET Framework Setup\NDP\v3.5&quot;
if($net35 -eq $null){
Write-Host &quot;.NET 3.5 is not installed.&quot;
$install =  [Windows.Forms.MessageBox] ::Show(&quot;.NET 3.5 Framework is not installed. This is required. Would you like to install it?&quot;, &quot;My Application&quot;,  [Windows.Forms.MessageBoxButtons] ::YesNo,  [Windows.Forms.MessageBoxIcon] ::Question)
if ($install -eq  [Windows.Forms.DialogResult] ::Yes){
Execute-Program &quot;/PASSIVE /NORESTART&quot; &quot;D:\Software\DotNet\3.5\dotnetfx35SP1.exe&quot;
}
}else{
Write-Host &quot;DotNet 3.5 FrameWork is installed&quot;
}
}
Check-DotNet35
#endregion
 </pre>
<p>The code to check if Quest AD is installed.<br />
A messagebox will be displayed if it is not installed.<br />
If users answers yes to the messagebox the requirement will be installed.<br />
Also if the users has an outdated version he will receive a messagebox asking to perform an upgrade.</p>
<pre class="brush: powershell; title: ; notranslate"> 
#region Load Quest AD plugin
function Load-QuestAD-Plugin
{
Write-Host &quot;Load-QuestAD-Plugin&quot;
$retVal = (Get-PSSnapin Quest.ActiveRoles.ADManagement 2&gt;$null)
$qadversion = &quot;1.2.2.1254&quot;
#Write-Host $retVal
if ($retVal -eq $null)
{
Write-Host &quot;Quest.ActiveRoles.ADManagement&quot;
Add-PSSnapin Quest.ActiveRoles.ADManagement
$retVal = &quot;$?&quot;
if ($retVal -eq $false)
{
$install =  [Windows.Forms.MessageBox] ::Show(&quot;Quest.ActiveRoles.ADManagement is not installed. Would you like to install it?&quot;, &quot;My Application&quot;,  [Windows.Forms.MessageBoxButtons] ::YesNo,  [Windows.Forms.MessageBoxIcon] ::Question)
if ($install -eq  [Windows.Forms.DialogResult] ::Yes)
{
Write-Host &quot;Installing Quest.ActiveRoles.ADManagement&quot;
Write-Host &quot;msiexec.exe /i `&quot;$WorkingDir\Requirements\arps.$qadversion.msi`&quot; /qn /norestart /l*c:\windows\temp\arsps.log&quot;
$retVal = Execute-Installer &quot;/i `&quot;$WorkingDir\Requirements\arps.$qadversion.msi`&quot; /qn /norestart /l* c:\windows\temp\arsps.log&quot; &quot;c:\temp&quot;
if($retVal -eq $true){
Write-Host &quot;Install finished&quot;
}
}
else
{
Write-Host &quot;No install of Quest.ActiveRoles.ADManagement&quot;
}
}
else
{
Write-Host &quot;QAD installed&quot;
$pssnapinversion = (Get-PSSnapin Quest.ActiveRoles.ADManagement).version
$textversion = $pssnapinversion.Major.tostring() + &quot;.&quot; + $pssnapinversion.Minor.tostring() + &quot;.&quot; + $pssnapinversion.Build.tostring() + &quot;.&quot; + $pssnapinversion.Revision.tostring()
Write-Host &quot;Required version: $qadversion - Current version: $textversion &quot;
if ($textversion -ne $qadversion)
{
$install =  [Windows.Forms.MessageBox] ::Show(&quot;Quest.ActiveRoles.ADManagement is not up to date. Would you like to update it?&quot;, &quot;My Application&quot;,  [Windows.Forms.MessageBoxButtons] ::YesNo,  [Windows.Forms.MessageBoxIcon] ::Question)
#if ($install.tolower() -eq &quot;y&quot;)
if ($install -eq  [Windows.Forms.DialogResult] ::Yes)
{
Remove-PSSnapin Quest.ActiveRoles.ADManagement
Write-Host &quot;Installing Quest.ActiveRoles.ADManagement&quot;
Write-Host &quot;msiexec.exe /i `&quot;$WorkingDir\Requirements\arps.$qadversion.msi`&quot; /qn /norestart /l*c:\windows\temp\arsps.log&quot;
$retVal = Execute-Installer &quot;/i `&quot;$WorkingDir\Requirements\arps.$qadversion.msi`&quot; /qn /norestart /l* c:\windows\temp\arsps.log&quot; &quot;c:\temp&quot;
if($retVal -eq $true){
Write-Host &quot;Install finished&quot;
}
}
else
{
Write-Host &quot;No install of Quest.ActiveRoles.ADManagement&quot;
}
}
}
}
}
Load-QuestAD-Plugin
#endregion
 </pre>
<p>Check if Altiris ASDK for NS is installed.<br />
A messagebox will be displayed if it is not installed.<br />
If users answers yes to the messagebox the requirement will be installed.<br />
If it is already installed the connections will be made to the server.</p>
<pre class="brush: powershell; title: ; notranslate"> 
#region Load Altiris ASDK
function Load-AltirisASDK
{
Write-Host &quot;Load-AltirisASDK&quot;
$altirisserver=&quot;ALTIRIS&quot;
$global:nsColl = New-Object -comObject Altiris.ASDK.NS.CollectionManagement
if($? -eq $false){
Write-Host &quot;AltirisASDK is not installed&quot;
$install =  [Windows.Forms.MessageBox] ::Show(&quot;Altiris ASDK is not installed. Would you like to install it?&quot;, &quot;My Application&quot;,  [Windows.Forms.MessageBoxButtons] ::YesNo,  [Windows.Forms.MessageBoxIcon] ::Question)
#if ($install.tolower() -eq &quot;y&quot;)
if ($install -eq  [Windows.Forms.DialogResult] ::Yes)
{
#Execute-Program &quot;/S&quot; &quot;$WorkingDir\Requirements\Altiris_ASDK_1_4_209.exe&quot;
$retVal = Execute-Installer &quot;/i `&quot;$WorkingDir\Requirements\Symantec_ASDK_NS_COM_x86.msi`&quot; /qn /norestart /l* c:\windows\temp\asdkNS.log&quot; &quot;c:\temp&quot;
if($retVal -eq $true){
Write-Host &quot;ASDK has been installed&quot;
}else{
Write-Host &quot;ASDK installation failed&quot;
}
}

}else{
$global:nsItem = New-Object -comObject Altiris.ASDk.NS.ItemManagement
$global:nsRes = New-Object -comObject Altiris.ASDK.NS.ResourceManagement
$global:nsReport = New-Object -comObject Altiris.ASDK.NS.ReportManagement
$global:nsReport.targetserver = $altirisserver
$global:nsReport.authenticate()
$global:nsItem.targetserver = $altirisserver
$global:nsItem.authenticate()
$global:nsColl.targetserver = $altirisserver
$global:nsColl.authenticate()
$global:nsRes.targetserver = $altirisserver
$global:nsRes.authenticate()
}
}
Load-AltirisASDK
#endregion
 </pre>
]]></content:encoded>
			<wfw:commentRss>http://www.legacycode.net/2010/01/10/ps-check-requirements-and-load-addins/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Migrating software to new workstations (Altiris NS)</title>
		<link>http://www.legacycode.net/2010/01/04/migrating-software-to-new-workstations-altiris-ns/</link>
		<comments>http://www.legacycode.net/2010/01/04/migrating-software-to-new-workstations-altiris-ns/#comments</comments>
		<pubDate>Mon, 04 Jan 2010 09:33:01 +0000</pubDate>
		<dc:creator>Ricky</dc:creator>
				<category><![CDATA[Altiris]]></category>
		<category><![CDATA[IT related]]></category>
		<category><![CDATA[Powershell]]></category>
		<category><![CDATA[Scripting]]></category>
		<category><![CDATA[Altiris NS]]></category>
		<category><![CDATA[asdk]]></category>
		<category><![CDATA[Notification Server]]></category>
		<category><![CDATA[SDK]]></category>

		<guid isPermaLink="false">http://www.legacycode.net/?p=68</guid>
		<description><![CDATA[A powershell script that adds a new computer to the same software collections as an other/old computer.
The script makes use of the Altiris ASDK.]]></description>
				<content:encoded><![CDATA[<p>The web-interface of Altiris Notification Server can sometimes be a bit sluggish.<br />
Certainly if you have to add a computer to 10 or more collections.<br />
To speed things a bit up I have written this Powershell script, which uses the  <a href="https://kb.altiris.com/utility/getfile.asp?rid=5685&#038;aid=44253"> Altiris ASDK </a>  to perform queries to Altiris NS.<br />
This script was intended to ensure that a new workstation receives the same software as the old workstation.<br />
It also can be used to just clone the software of a workstation to a new workstation.</p>
<pre class="brush: powershell; title: ; notranslate"> 
#Active Directory Domain
$domain = &quot;LCODE&quot; 
#Host name of Altiris Notification Server
$nsserver = &quot;ALTIRISNS&quot; 
#Major resource collection
$maincollection = &quot;LCODE Software Collections&quot; 
#Sub resource collection
$softinstallcollection = &quot;Software Installation&quot;

#This is a schematic of the structure maintained in Notification Server
#The major resource collection is a child of Software Management
#The name of the sub resource collection is just the first part of the full name (Software Installation)
# as this is being matched with the children of the major resource collection
# all children beginning with that name are being enumerated
# eg. &quot;Software Installation&quot; causes &quot;Software Installation 1&quot; and &quot;Software Installation 2&quot; to be enumerated
#
#Resources tab
# Resource Management
#  [-]  Collections
#       [-]  Software Management
#            [-]  LCODE Software Collections
#         [-]  Software Installation 1
#             []  SW Package 1
#             []  SW Package 2
#         [-]  Software Installation 2
#             []  SW Package 3
#             []  SW Package 4
#

#Load Altiris ASDK
$coll = New-Object -comObject Altiris.ASDK.NS.CollectionManagement
$item = New-Object -comObject Altiris.ASDk.NS.ItemManagement
$res = New-Object -comObject Altiris.ASDK.NS.ResourceManagement
$report = New-Object -comObject Altiris.ASDK.NS.ReportManagement

#Establish connections to Altiris Notification Server
$report.targetserver = $nsserver
$report.authenticate()
$item.targetserver = $nsserver
$item.authenticate()
$coll.targetserver = $nsserver
$coll.authenticate()
$res.targetserver = $nsserver
$res.authenticate()

#Retrieve GUID of the Major resource collection
$maincollectionguid = ($item.getItemsByName($maincollection)).GetValue(0).Guid

#Ask user to enter hostnames of old and new pc
$oldpc = Read-Host &quot;Old PC&quot;
$newpc = Read-Host &quot;New PC&quot;

#Retrieve GUIDs of computers
$oldpcguid = $res.getComputerByNameAndDomain($oldpc,$domain)
$newpcguid = $res.getComputerByNameAndDomain($newpc,$domain)

#Check if we don't have an empty GUID for one of the computers
if(($oldpcguid.length -gt 0) -and ($newpcguid.length -gt 0)){

#Retrieve all software collections
$softwarecoll = $item.GetItemsInFolder($maincollectionguid) | foreach-object -process { $item.GetItemsInFolder($_.Guid) | where-object { $_.parentfoldername -match $softinstallcollection } }

#Enumerate all software collections
$softwarecoll | foreach-object -process{
$softguid = $_.guid

#Check if OldPC is in software collection
$result = $coll.getinclusions($softguid,&quot;Resource&quot;) | where-object { $_.name -eq $oldpc}
if($result -ne $null){
$softname = $_.Name

#Display and log that OldPC has this piece of software
Write-Host &quot;$oldpc $softname&quot;
Add-Content &quot;.\$newpc.txt&quot; -value &quot;$oldpc $softname&quot;

#Add NewPC to software collection
$coll.addinclusions($softguid,$newpcguid)

#Check if NewPC is in software collection
$result = $coll.getinclusions($softguid,&quot;Resource&quot;) | where-object { $_.name -eq $newpc}
if($result -ne $null){

#Display and log that NewPC has this piece of software
Write-Host &quot;$newpc $softname&quot;
Add-Content &quot;.\$newpc.txt&quot; -value &quot;$newpc $softname&quot;
}

#Refresh the software collection
$coll.updatecollections($softguid)
}
#Write-Host &quot;Result:$result&quot;
}
}else{

#One of the GUIDs could not be found. Most likely computername is wrong or it does not exist in Notification Server
Write-Host &quot;Problem finding GUID for Old/New PC&quot;
Write-Host &quot;Old PC: $oldpcguid&quot;
Write-Host &quot;New PC: $newpcguid&quot;
}
 </pre>
]]></content:encoded>
			<wfw:commentRss>http://www.legacycode.net/2010/01/04/migrating-software-to-new-workstations-altiris-ns/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Exchange 2007 upgrade CAS &#8216;owa&#8217; already exists</title>
		<link>http://www.legacycode.net/2009/10/25/exchange-2007-upgrade-cas/</link>
		<comments>http://www.legacycode.net/2009/10/25/exchange-2007-upgrade-cas/#comments</comments>
		<pubDate>Sun, 25 Oct 2009 17:22:10 +0000</pubDate>
		<dc:creator>Ricky</dc:creator>
				<category><![CDATA[Exchange 2007]]></category>
		<category><![CDATA[Windows]]></category>
		<category><![CDATA[CAS]]></category>
		<category><![CDATA[error]]></category>
		<category><![CDATA[upgrade]]></category>

		<guid isPermaLink="false">http://www.legacycode.net/?p=25</guid>
		<description><![CDATA[Currently I am using a test-environment to become familiar with Exchange 2007. Today I tried to upgrade from Exchange 2007 RTM to SP2. Whilst trying to upgrade my CAS-server I encountered the following error The virtual directory &#8216;owa&#8217; already exists under &#8216;ExchCAS/Default Web Site&#8217; Parameter name: VirtualDirectoryName The solution that I used to solve this [...]]]></description>
				<content:encoded><![CDATA[<p>Currently I am using a test-environment to become familiar with Exchange 2007.<br />
Today I tried to upgrade from Exchange 2007 RTM to SP2.<br />
Whilst trying to upgrade my CAS-server I encountered the following error</p>
<p style="font-family:courier"> The virtual directory &#8216;owa&#8217; already exists under &#8216;ExchCAS/Default Web Site&#8217; Parameter name: VirtualDirectoryName </p>
<p>The solution that I used to solve this was to delete the offending virtual directory and all other Exchange related virtual directories by issuing the following lines in the Exchange Management Shell.</p>
<p style="font-family:courier"> Get-OwaVirtualDirectory| foreach-object -process { $id=$_.server.tostring() + &#8216;\&#8217; + $_.name.tostring(); write-host &#8216;Going to remove $id&#8217;;  Remove-OwaVirtualDirectory -Identity $id } </p>
<p style="font-family:courier"> Get-OabVirtualDirectory | foreach-object -process { $id=$_.server.tostring() + &#8216;\&#8217; + $_.name.tostring(); write-host &#8216;Going to remove $id&#8217;; Remove-OabVirtualDirectory -Identity $id } </p>
<p style="font-family:courier"> Get-AutodiscoverVirtualDirectory | foreach-object -process { $id=$_.server.tostring() + &#8216;\&#8217; + $_.name.tostring(); write-host &#8216;Going to remove $id&#8217;; Remove-AutodiscoverVirtualDirectory -Identity $id } </p>
<p style="font-family:courier"> Get-UMVirtualDirectory | foreach-object -process { $id=$_.server.tostring() + &#8216;\&#8217; + $_.name.tostring(); write-host $id;<br />
Remove-UMVirtualDirectory -Identity $id }</p>
<p style="font-family:courier"> Get-ActiveSyncVirtualDirectory | foreach-object -process { $id=$_.server.tostring() + &#8216;\&#8217; + $_.name.tostring(); write-host $id; Remove-ActiveSyncVirtualDirectory -Identity $id } </p>
<p style="font-family:courier"> Get-WebServicesVirtualDirectory | foreach-object -process { $id=$_.server.tostring() + &#8216;\&#8217; + $_.name.tostring(); write-host $id;<br />
Remove-WebServicesVirtualDirectory -Identity $id } </p>
]]></content:encoded>
			<wfw:commentRss>http://www.legacycode.net/2009/10/25/exchange-2007-upgrade-cas/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
