0

How to execute 2 scripts, if the 2nd one is dependent on the results of the fist one. I want to deploy a network and a server has to deploy in that network. The network deployment is taking time, but before that the server deployment scripts start, which shows an error, that no such network name found. I tried the sleep start command, but I don't know exactly how long it will take to deploy a network.

The gist is that, the result of one script is used as an input of another script.

Could you please help me in this regard. I know there must be a single line cmdlts in powershell for such type of situation.

Thanks, Krishna

1
  • 1
    How exactly do you start your scripts? What kind of result of the first script is used as input of the second? Because so far it looks like this one-liner should work: Script1.ps1; Script2.ps1. Commented May 20, 2014 at 6:40

2 Answers 2

1

What version of powershell are you using? Verify it using $PSVersionTable. if you have 3.0 or greater, use Workflow(sequence) to get your desired. Read through this link: http://technet.microsoft.com/en-us/library/jj574157.aspx

Is this what you are looking at?

Example:

# PowerShell 3.0 and greater example.
Workflow Test-Sequence { 
   Sequence 
   { 
   "In sequence Test1"
  Start-Sleep -Seconds 10
   "In sequence Test2" 
   Start-Sleep -Seconds 1

  } # Closes Sequence


}  # Closes workflow

Test-Sequence
Sign up to request clarification or add additional context in comments.

Comments

0

I like to wait for the SMB port -

function Test-TCPPort {
    param (
        [parameter(Mandatory=$true)]
        [string] $ComputerName,

        [parameter(Mandatory=$true)]
        [string] $Port
    )

    try {
        $TimeOut = 5000
        $IsConnected = $false
        $Addresses = [System.Net.Dns]::GetHostAddresses($ComputerName) | ? {$_.AddressFamily -eq 'InterNetwork'}
        $Address = [System.Net.IPAddress]::Parse($Addresses)
        $Socket = New-Object System.Net.Sockets.TCPClient

        $Connect = $Socket.BeginConnect($Address, $Port, $null, $null)
        $Wait = $Connect.AsyncWaitHandle.WaitOne($TimeOut, $false)  

        if ( $Socket.Connected ) {
            $IsConnected = $true
        } else {
            $IsConnected = $false
        }

    } catch {
        Write-Warning $_
        $IsConnected = $false
    } finally {
        $Socket.Close()
        return $IsConnected
    }
}

while (-not (Test-TcpPort -ComputerName $server_to_wait_on_here -Port 445)) {
    Write-Warning ("Waiting for ${server_to_wait_on_here}:445")
    start-sleep -sec 5
}

# Ok server is ready, do stuff here

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.