none
How Combine Powershell Scripts, IF First Script Completed Start Second RRS feed

  • Question

  • How Combine Powershell Scripts, IF First Script Completed Start Second

    i have scripts which copy files to some locations and second script which restarts services how can i combine them?

    Friday, June 2, 2017 1:02 PM

Answers

  • Use a Test-Path to see if the files have been created once the first script has been run. Then if Test-Path is TRUE, the files have been created so the second script can run. Something along those lines?

    #copy files code here
    
    function restartservices{
    #function here
    }
    
    $testpath = test-path -Path #PATH YOU WANT TO CHECK!
    
    if ($testpath -eq $false){
        Write-Host "FILES HAVE NOT BEEN COPIED"
    }else { 
        restartservices
    }

    Friday, June 2, 2017 1:15 PM

All replies

  • Use a Test-Path to see if the files have been created once the first script has been run. Then if Test-Path is TRUE, the files have been created so the second script can run. Something along those lines?

    #copy files code here
    
    function restartservices{
    #function here
    }
    
    $testpath = test-path -Path #PATH YOU WANT TO CHECK!
    
    if ($testpath -eq $false){
        Write-Host "FILES HAVE NOT BEEN COPIED"
    }else { 
        restartservices
    }

    Friday, June 2, 2017 1:15 PM
  • How do you run them? Just start the second script after the first ... par example from one cmd file.

    Grüße - Best regards

    PS:> (79,108,97,102|%{[char]$_})-join''

    Friday, June 2, 2017 1:34 PM