Deploying Java

We had a hard time getting a clean silent java deploy. There is a bug where the settings file has to exist for a silent install. This is the script i ended up with.

@echo off
rem We have to kill the browsers for a clean uninstall and install
taskkill /f /im iexplore*
taskkill /f /im firefox*
taskkill /f /im chrome*
taskkill /f /im safari*
taskkill /f /im msiexec.exe

rem we need a config file in order for java.
mkdir C:\ProgramData\Oracle\Java
copy /y java.settings.cfg C:\ProgramData\Oracle\Java\

start /wait msiexec /i jre1.8.0_31.msi /qn INSTALL_SILENT=Enable AUTO_UPDATE=Disable WEB_JAVA=Enable EULA=0 /L*V "install.log"
AUTO_UPDATE=Disable
EULA=0
INSTALL_SILENT=Enable

SCCM Container Query

I was asked to help write a script to query all machines that do not have the SCCM agent and produce their email address in a CSV file.

Import-Module 'D:\Program Files\Microsoft Configuration Manager\AdminConsole\bin\ConfigurationManager.psd1' -Verbose

set-location "SITEID:"

$Members = Get-CMDevice -CollectionName "Inactive AD computers with SCCM 2012 Client"

 

 

$Members | foreach-object {

  $Username=$_.UserName

  $Computername=$_.Name

 

  If($Username -ne 'Administrator'){

    If($Username){

        Try{

            $email = (Get-ADUser $Username -properties mail).mail

            New-Object -TypeName PSCustomObject -Property @{   

                Username = $Username   

                Computername = $Computername    

                Email = $email} | Export-Csv -Path "Machines.csv" -NoTypeInformation -Append

        }Catch{

            #who cares

        }

        #write-host $name

     }

   }#end if

}#end for each

Hyper-V VM Trunk

I am running Sophos-UTM in Hyper-V and i needed a TRUNK port to the virtual machine so i can do vlan tagging. Here is the powershell code to implement it.

Example with Place Holders

get-vmnetworkadapter -vmname NAME_OF_VM | where-object -property MacAddress -eq "MAC_ADDR_OF_NIC" | set-vmnetworkadaptervlan -Trunk -AllowedVlanIdList Start-End NativeVlanID DEFAULT_VLAN

Example with Real Data

get-vmnetworkadapter -vmname Sophos-UTM | where-object -property MacAddress -eq "1234567890AB" | set-vmnetworkadaptervlan -Trunk -AllowedVlanIdList 10-20 NativeVlanID 10

Sophos Duplicate IDs

I found my self in a large environment where someone decided to deploy an image with Sophos installed. This resulted in all the computers being seen as 1 single computer in the Sophos Enterprise Console.

This caused me to write the following scripts. sophosFindDuplicate.pl scan the IIS logs looking for duplicate GUIDs from computer. It will output the IPs of the machines. This command will let you remotely fix the machines.(Remeber to whitelist psexec in Sophos)

psexec @hosts.txt -u domain\user -p password -c batchfile.bat

sophosFixDuplicate.cmd

@echo off
net stop "Sophos Message Router"
net stop "Sophos Agent"
net stop "Sophos AutoUpdate Service"

echo y|del "C:\Program Files\Sophos\AutoUpdate\machine_ID.txt"
echo y|del "C:\ProgramData\Sophos\AutoUpdate\machine_ID.txt"

reg delete "HKLM\Software\Sophos\Messaging System\Router\Private" /v pkc /f
reg delete "HKLM\Software\Sophos\Messaging System\Router\Private" /v pkp /f

reg delete "HKLM\Software\Sophos\Remote Management System\ManagementAgent\Private" /v pkc /f
reg delete "HKLM\Software\Sophos\Remote Management System\ManagementAgent\Private" /v pkp /f

reg delete "HKLM\Software\Wow6432Node\Sophos\Messaging System\Router\Private" /v pkc /f
reg delete "HKLM\Software\Wow6432Node\Sophos\Messaging System\Router\Private" /v pkp /f

reg delete "HKLM\Software\Wow6432Node\Sophos\Remote Management System\ManagementAgent\Private" /v pkc /f
reg delete "HKLM\Software\Wow6432Node\Sophos\Remote Management System\ManagementAgent\Private" /v pkp /f

net start "Sophos Message Router"
net start "Sophos Agent"
net start "Sophos AutoUpdate Service"

sophosFindDuplicate.pl

#Stephen
#Check for Duplicates
use Data::Dumper;

$file = "\\\\sophos-c108-01\\W3SVC1\\u_ex110822.log";
my %hash = ();
my %hDup = ();

open FILE, $file or die $!;

while () {
  @data = ($_ =~ /(\b143\.55\.\d{1,3}\.\d{1,3}\b).*?(\b143\.55\.\d{1,3}\.\d{1,3}\b).*?(\{{0,1}[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}\}{0,1})/);
	#print $data[0] . "\n";
	if ((exists $hash{$data[2]}) && ($hash{$data[2]} ne $data[1]))
	{
		if(not exists $hDup{$data[1]})
		{
			print $data[1] . "\n";
			$hDup{$data[1]} = $data[1];
		}
	}
	else
	{
		$hash{$data[2]} = $data[1];
	}
}

close(FILE);