Wait for Process to complete from batch file and then delete folder

Welcome Forums General PowerShell Q&A Wait for Process to complete from batch file and then delete folder

This topic contains 4 replies, has 2 voices, and was last updated by

 
Participant
4 months, 4 weeks ago.

  • Author
    Posts
  • #117915

    Participant
    Points: 29
    Rank: Member

    Hi Everyone

    I'm trying to create a one click method for Office 365 to install. This is what it looks like now:

    $uncServer = "\\networkshare"
    $uncFullPath = "$uncServer\Office365"
    $uncDestination = "C:\Office365_install-x64"
    
    mkdir $uncDestination
    Copy-Item -Path $uncFullPath -Destination $uncDestination -Recurse -Force
    Start-Process -FilePath "$uncDestination\Office365\Install_Office365-x64_batch.bat" -ArgumentList /S
    
    Start-Sleep -s 300
    Remove-Item -path $uncDestination -recurse

    In the batch file I have the following:

    c:\Office365_install-x64\setup.exe /configure configuration-64.xml

    As soon as I get to Start-Process, it will create a Office-Click-to-Run process while installing Office. I want to remove the $uncDestination as soon as the Office-Click-to-Run process terminates. If there is a method to rather run the batch command in Powershell, I can add a -Wait command.

    Any help would be appreciated.
    Thanks

  • #117946

    Participant
    Points: 29
    Rank: Member

    I tried to change the script to the following but the $uncDestination is removed and I then get a "File does not exist" error.

    $uncServer = "\\networkshare"
    $uncFullPath = "$uncServer\Office365"
    $uncDestination = "C:\Office365_install-x64"
    
    $Office365setupx64 = "uncDestination\setup.exe"
    $365x64xml = "uncFullPath\configuration-64.xml"
    net use $uncServer
    
    mkdir $uncDestination
    Copy-Item -Path $uncFullPath -Destination $uncDestination -Recurse -Force
    cmd /c start /wait $Office365setupx64 /configure $365x64xml
    Remove-Item -path $uncDestination -recurse
  • #117949

    Participant
    Points: 1,607
    Helping Hand
    Rank: Community Hero

    You don't even need to use a batch file here,

    #Infinite wait
    Start-Process -FilePath "$uncDestination\setup.exe" -ArgumentList '/configure configuration-64.xml' -Wait
    
    #Or
    #Wait with specific timeout
    $TimeOut = 900
    $Process = Start-Process -FilePath "$uncDestination\setup.exe" -ArgumentList '/configure configuration-64.xml' -PassThru
    $Process | Wait-Process -TimeOut $TimeOut
    if($Process.HasExited){
    #     $Process.ExitCode will give you the exit ode, you check and decide what to do
    }
    else{
        Throw "Process didn't complete in $TimeOut seconds"
    }
    

    I would recommend you to go through the help documentation of Start-Process cmdlet, Get-Help Start-Process -Full

  • #117954

    Participant
    Points: 29
    Rank: Member

    I changed the script to the following and this seems to work excellent:

    $Office365setupx64 = "\\networkshare\Office365\setup.exe"
    $365x64xml = "\\networkshare\Office365\configuration-64.xml"
    net use "\\networkshare\Office365"
    cmd /c $Office365setupx64 /configure $365x64xml
  • #117960

    Participant
    Points: 29
    Rank: Member

    Thanks kvprasoon

    I will try this one as well.

    Thanks again for the response!

The topic ‘Wait for Process to complete from batch file and then delete folder’ is closed to new replies.

denizli escort samsun escort muğla escort ataşehir escort kuşadası escort