Skip to content

Instantly share code, notes, and snippets.

@dstreefkerk
Created May 2, 2014 08:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dstreefkerk/228716eb840c1f6fac8c to your computer and use it in GitHub Desktop.
Save dstreefkerk/228716eb840c1f6fac8c to your computer and use it in GitHub Desktop.
Computer startup or PS Remoting script to migrate an installed Officescan client to another server if it's currently pointed at a different one.
<#
.SYNOPSIS
Migrate-OfficescanClient - Migrate Officescan clients to the correct server
.DESCRIPTION
Checks which server the Officescan client is pointing to (by reading ofcscan.ini)
If it's pointing to the wrong one, call the appropriate ipxfer command with
the correct parameters to point it to the new/correct server
This script was also designed to be used with PS Remoting. To use it this way,
do this:
Invoke-Command -FilePath <path_to_script> -Verbose -Computername <single computer/array of computers>
.OUTPUTS
Nothing, unless run with the -Verbose switch, in which case
it'll output some basic info about what's going on.
.LINK
.NOTES
Written By: Daniel Streefkerk
Website: http://daniel.streefkerkonline.com
Twitter: http://twitter.com/dstreefkerk
Todo: Nothing at the moment
#>
# The OfficeScan server that clients should be pointing to
$correctOfficescanServer = 'officescanserver.local'
# The server port on the destination Officescan server
$correctOfficescanServerPort = 8080
# The client listen port
$correctOfficescanClientPort = 48528
# The share where we can find ipxfer
$ofcscanShare = '\\officescanserver.local\ofcscan'
# The path to search for ofcscan.ini. This covers 32-bit machines as well as 64-bit machines
$installSearchPath = 'c:\program*\trend*'
# Determine if the OS running this script is 32-bit
$is32bitSystem = ([System.IntPtr]::Size -eq 4)
# Get the full path to ofcscan.ini
$ofcscanConfigFile = (Get-ChildItem -Path $installSearchPath -Recurse -WarningAction SilentlyContinue | ? {$_ -like "*ofcscan.ini"}).FullName
# If the Officescan Client config file wasn't found, exit
if ((Test-Path $ofcscanConfigFile) -eq $false) { Write-Verbose "$env:COMPUTERNAME - Couldn't locate ofcscan.ini"; exit }
# Read some of the values from the INI file that we're interested in, and turn them into a hashtable
$configValues = @(Get-Content $ofcscanConfigFile -ErrorAction SilentlyContinue| Where-Object {$_ -like 'Master_*'} | ConvertFrom-StringData)
# If no values have come through, exit. There must have been an issue while reading the file
if ($configValues.Count -lt 1) { Write-Verbose "$env:COMPUTERNAME - There was a problem parsing the configuration INI file values"; exit }
# If the client is already pointing to the correct server, exit
if ($configValues.Master_DomainName -match $correctOfficescanServer) { Write-Verbose "$env:COMPUTERNAME - Already connected to the correct server"; exit}
# Run the relevant IpXfer executable based on the installed OS
switch ($is32bitSystem) {
$true {
Write-Verbose "32-bit system. Running IpXfer.exe"
& $ofcscanShare\Admin\Utility\IpXfer\IpXfer.exe -m 1 -s $correctOfficescanServer -p $correctOfficescanServerPort -c $correctOfficescanClientPort -q 1
break;
}
$false {
Write-Verbose "64-bit system. Running IpXfer_x64.exe"
& $ofcscanShare\Admin\Utility\IpXfer\IpXfer_x64.exe -m 1 -s $correctOfficescanServer -p $correctOfficescanServerPort -c $correctOfficescanClientPort -q 1
}
}
# Report on the status of the command's execution
switch ($LASTEXITCODE) {
0 {Write-Verbose "$env:COMPUTERNAME - Ran IpXfer.exe successfully"; break}
Default {Write-Verbose "$env:COMPUTERNAME - Running IpXfer failed with exit code $LASTEXITCODE"}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment