Creating a Job to run function in the background

This topic contains 6 replies, has 2 voices, and was last updated by  Andy Smith 2 years, 3 months ago.

  • Author
  • #38013

    Andy Smith

    Evening all

    I have 2 questions about my script below.

    The script installs symantec anti virus remotley.

    1. How do i turn this into a job so it doesn't hang my app when it's running the function

    2. The Win 7 part works fine but for XP it does not install.. It copies the files over correctly but doesn't seem to run the msi .. I've checked event view and nothing there.

    Any assistance would be appriciated.

    function SEPInstall {
    $HostName = $InputBoxHW.text;
    if([System.Windows.Forms.MessageBox]::Show("This will install SEP 12 on $HostName and reboot. Continue?", "SEP 12 Install",[System.Windows.Forms.MessageBoxButtons]::OKCancel) -eq "OK")
    sleep 2
    $outputsepinstall.text = write "Copying required files to $HostName"
     sleep 5
     $service = Get-Service 'RemoteRegistry' -cn $HostName
     If ($service.Status -match 'Stopped') {
     If (!(Test-Path \\$HostName\c$\temp\AVInstall\)) {
     mkdir \\$HostName\c$\temp\AVInstall\
     $os_type64 = (Get-WmiObject -ComputerName $HostName -Class Win32_ComputerSystem).SystemType -match '(x64)'
    if ($os_type64 -eq "True") {$files = Get-ChildItem "\\DFS-EMEA\Distribution\Ldn\InstallerPackages\IWSEP12RU564B0100\"}
     $os_type32 = (Get-WmiObject -ComputerName $HostName -Class Win32_ComputerSystem).SystemType -match '(x86)' 
    if ($os_type32 -eq "True") {$files = Get-ChildItem "\\DFS-EMEA\Distribution\Ldn\InstallerPackages\IWSEP12RU532B0100\"}
     Foreach ($file in $files) {
     Copy-Item $file.fullname "\\$HostName\c$\temp\AVInstall\" -recurse
     $outputsepinstall.text = write "Installing SEP12 on $HostName"
     sleep 5
     if ($os_type64 -eq "True") {$process = Invoke-WMIMethod win32_process -name create -cn $HostName -ArgumentList 'msiexec /i "c:\temp\AVInstall\Sep64.msi" /qb'}
     if ($os_type32 -eq "True") {$process = Invoke-WMIMethod win32_process -name create -cn $HostName -ArgumentList 'msiexec /i "c:\temp\AVInstall\Sep.msi" /qb'}
     $id = $process.processid
     $a = ""
     do {
     $a = Get-Process -cn $HostName | Where{$_.ID -match "$ID"}
     While ($a -ne $null)
     del \\$HostName\c$\temp\AVInstall -force -recurse
     $outputsepinstall.text = write "Removing temp files from $HostName"
     sleep 10
     $outputsepinstall.text = write "Rebooting $HostName"
     sleep 5
     Restart-Computer -ComputerName $HostName -force
     sleep 40
     $outputsepinstall.text = write "Waiting for logon service to start"
    $status = (get-service -Name NetLogon -ComputerName $HostName).Status}
    Until ($status -eq "Running") 
    $outputsepinstall.text = "$HostName is Online"}
  • #38034

    Richard Diphoorn

    Invoke-WmiMethod has a -AsJob parameter. But, does de MSI install work when you execute this line directly?

    Invoke-WMIMethod win32_process -name create -cn $HostName -ArgumentList 'msiexec /i "c:\temp\AVInstall\Sep64.msi" /qb'
  • #38037

    Andy Smith

    I just kicked it off and i can see the event view details on the install.

  • #38039

    Andy Smith

    I've also figured out my the 32bit verion on XP isn't working.
    It doesn't seem to be creating a processID.

    Is there anyway i can force it to?

  • #38040

    Richard Diphoorn

    Are you getting any error messages in the eventlog? Or on the console? Try using -Verbose.

  • #38041

    Andy Smith

    I've done some research and its returnvalue 3 (Insufficient Privilege)

    No idea how to get round this

  • #38044

    Andy Smith

    I found that

    Invoke-WmiMethod -Path Win32_Product -Name Install -ComputerName "GBRPWMVDI023615" -ArgumentList @($true,$null,"\\GBRPWMVDI023615\c$\temp\AVInstall\Sep.msi")

    Works for installing but how do i monitor that there isn't a processid property on win32_product

You must be logged in to reply to this topic.