locked
command output to a variable RRS feed

  • Question

  • I am calling azcopy from powershell to transfer files from/to blob storage. 

    azcopy copy "C:\local\path" "https://account.blob.core.windows.net/mycontainer1/?sv=2018-03-28&ss=bjqt&srt=sco&sp=rwddgcup&se=2019-05-01T05:01:17Z&st=2019-04-30T21:01:17Z&spr=https&sig=MGCXiyEzbtttkr3ewJIh2AR8KrghSy1DGM9ovN734bQF4%3D" --recursive=true

    When the copy job finishes I get the following info printed in the ps console. 

    Job 908862ef-2867-ac48-4d9c-e79121338203 summary
    Elapsed Time (Minutes): 0.0334
    Total Number Of Transfers: 1
    Number of Transfers Completed: 1
    Number of Transfers Failed: 0
    Number of Transfers Skipped: 0
    TotalBytesTransferred: 45990
    Final Job Status: Completed

    How can I take that output and put it in a variable ?

    Thanks 


    • Edited by net_tech Friday, September 20, 2019 7:01 PM
    Friday, September 20, 2019 7:00 PM

Answers

  • To get the output just assign it to a variable

    $var = azcopy …


    \_(ツ)_/

    • Marked as answer by net_tech Friday, September 20, 2019 7:14 PM
    Friday, September 20, 2019 7:09 PM

All replies

  • To get the output just assign it to a variable

    $var = azcopy …


    \_(ツ)_/

    • Marked as answer by net_tech Friday, September 20, 2019 7:14 PM
    Friday, September 20, 2019 7:09 PM
  • $OutputVariable = (azcopy  copy $localPath $URI --recursive ) | Out-String
    Friday, September 20, 2019 7:12 PM
  • That should work but it isn't necessary to use Out-String with utilities that outpu text.


    \_(ツ)_/

    Friday, September 20, 2019 7:21 PM