powershell end command before continue script

matteu31 502 Reputation points
2021-01-15T10:59:07.493+00:00

Hello,

I'm trying to build silent script SCCM install and I need some help to download prerequesites.
I want to download ADK files and winPE files.

I download setup here : https://learn.microsoft.com/en-us/windows-hardware/get-started/adk-offline-install

Thenk, my command line to download is here : adksetup /quiet /layout c:\temp\ADKoffline

In my script, I have :
some command
start-process -filepath "adksetup.exe" -WorkingDirectory "c:\sources" -ArgumentList "/quiet /layout c:\sources"

adksetup /quiet /layout c:\temp\ADKoffline
some command

How can I do to wait adksetup line is over before continue my script ?
This line download 1GB of data and I don't want to continue before this process ends.

Thank you for your help

Windows for business Windows Server User experience PowerShell
0 comments No comments
{count} votes

Accepted answer
  1. MotoX80 36,291 Reputation points
    2021-01-15T13:15:22.23+00:00

    Use the -Wait switch on the Start-Process command.

    https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.management/start-process?view=powershell-5.1

    -Wait
    Indicates that this cmdlet waits for the specified process and its descendants to complete before accepting more input. This parameter suppresses the command prompt or retains the window until the processes finish.

    1 person found this answer helpful.
    0 comments No comments

2 additional answers

Sort by: Most helpful
  1. Anonymous
    2021-01-15T13:09:27.297+00:00

    Hi,

    See if this works for you

    for(;$true;){  
        $ifrun = Get-Process -Name adksetup 2>$null  
        if(-not($ifrun)){ break }  
        Start-Sleep 1  
    }  
    some command  
    

    Best Regards,
    Ian Xue

    ============================================

    If the Answer is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    1 person found this answer helpful.
    0 comments No comments

  2. matteu31 502 Reputation points
    2021-01-15T13:19:39+00:00

    @MotoX80

    Perfect :)
    It works !

    Thanks you very much :)

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.