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

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

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

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

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

Thanks kvprasoon

I will try this one as well.

Thanks again for the response!