locked
Enforce synchronous run of command lets in PowerShell RRS feed

  • Question

  • Hi,

    I have 3 cmdlets in Powershell script.

    Unfortunetly it seems that at least on it is running asychronous.

    How to enforce run commandlets sychronously?

    Is there any cmdlet parameter for that?

    Regards,

    Tom

    Friday, July 21, 2017 1:57 PM

All replies

  • What do you mean by "running asynchronous"? Usually cmdlets run one after each other.

    Show your code!


    Grüße - Best regards

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


    • Edited by BOfH-666 Friday, July 21, 2017 2:12 PM
    Friday, July 21, 2017 2:12 PM
  • Login-AzureRmAccount$resourceGroup = "tztestresgroup"$vmName = "orioracetz"$backupvault = "tzbackupvault"Set-AzureRmVMCustomScriptExtension -ResourceGroupName $resourceGroup  `    -VMName $vmName -Name "orioracetz_test_begin"  -Location "West Europe" -StorageAccountName "orioracetz" -StorageAccountKey uAhxX1111mMTO42hExc0aXzfz95aYNDnpK+mVFxQfQfySRCjyxZHfq0xYQuPA33EqjZqv91mzk8t8z7MrogKEw== -FileName "enableBackupMode.ps1" -ContainerName "scripts1" -Run "enableBackupMode.ps1"Get-AzureRmRecoveryServicesVault -Name $backupvault | Set-AzureRmRecoveryServicesVaultContext$namedContainer = Get-AzureRmRecoveryServicesBackupContainer -ContainerType "AzureVM" -Status "Registered" -Name "orioracetz"$item = Get-AzureRmRecoveryServicesBackupItem -Container $namedContainer -WorkloadType "AzureVM"$job = Backup-AzureRmRecoveryServicesBackupItem -Item $item$jobSet-AzureRmVMCustomScriptExtension -ResourceGroupName $resourceGroup  `    -VMName $vmName -Name "orioracetz_test_begin"  -Location "West Europe" -StorageAccountName "orioracetz" -StorageAccountKey uAhxX1111mMTO42hExc0aXzfz95aYNDnpK+mVFxQfQfySRCjyxZHfq0xYQuPA33EqjZqv91mzk8t8z7MrogKEw== -FileName "disableBackupMode.ps1" -ContainerName "scripts1" -Run "disableBackupMode.ps1"

    First commandlet is still running asynchronous.
    Friday, July 21, 2017 2:25 PM
  • It is "CmdLets" "not command lets".

    Your code is damaged and all posted on one line.  It will not run.

    This is close to what it should look like.

    Login-AzureRmAccount 
    $resourceGroup = 'tztestresgroup'
    $vmName = 'orioracetz'
    $backupvault = 'tzbackupvault'
    
    Set-AzureRmVMCustomScriptExtension -ResourceGroupName $resourceGroup -VMName $vmName -Name orioracetz_test_begin -Location 'West Europe' -StorageAccountName "orioracetz" -StorageAccountKey 'uAhxX1111mMTO42hExc0aXzfz95aYNDnpK+mVFxQfQfySRCjyxZHfq0xYQuPA33EqjZqv91mzk8t8z7MrogKEw==' -FileName enableBackupMode.ps1 -ContainerName scripts1 -Run enableBackupMode.ps1
    Get-AzureRmRecoveryServicesVault -Name $backupvault | 
    	Set-AzureRmRecoveryServicesVaultContext
    $namedContainer = Get-AzureRmRecoveryServicesBackupContainer -ContainerType AzureVM -Status Registered -Name orioracetz
    $item = Get-AzureRmRecoveryServicesBackupItem -Container $namedContainer -WorkloadType AzureVM
    $job = Backup-AzureRmRecoveryServicesBackupItem -Item $item
    
    Set-AzureRmVMCustomScriptExtension -ResourceGroupName $resourceGroup -VMName $vmName -Name orioracetz_test_begin -Location 'West Europe' -StorageAccountName orioracetz -StorageAccountKey 'uAhxX1111mMTO42hExc0aXzfz95aYNDnpK+mVFxQfQfySRCjyxZHfq0xYQuPA33EqjZqv91mzk8t8z7MrogKEw==' -FileName disableBackupMode.ps1 -ContainerName scripts1 -Run disableBackupMode.ps1

    I suggest you start by learning basic PowerShell.

    CmdLets do not run async.  Some operation on Azure may just get scheduled and may require you to poll them for completion status.


    \_(ツ)_/


    • Edited by jrv Friday, July 21, 2017 2:51 PM
    Friday, July 21, 2017 2:50 PM
  • Ok thanks.

    Is there is any way to pull out for output of cmdlets status in single script to wait before proceeding.

    Maybe is there any other method to achive that? This could be done with Runbooks ?

    It will be work if I'll create 3 separated scripts ?

    Friday, July 21, 2017 3:17 PM
  • I can see no way to guess what you are trying to ask.

    \_(ツ)_/

    Friday, July 21, 2017 3:24 PM
  • command1

    wait-here-if-command1-finishes

    command2

    wait-here-if-command2-finishes

    command3

    Friday, July 21, 2017 3:38 PM
  • None of your commands require waiting.  They are not commands that schedule a long running operation.

    Please take the time to learn PowerShell so you can understand how to use these commands correctly.

    You can post in the Azure forums for assistance with using Azure CmdLets.


    \_(ツ)_/

    Friday, July 21, 2017 3:45 PM
  • Hi,
    Just checking in to see if the information provided was helpful. Please let us know if you would like further assistance.

    Best Regards,

    Frank

    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.

    Friday, August 11, 2017 4:43 AM