Azure Pipeline - Powershell Task Output

%3CLINGO-SUB%20id%3D%22lingo-sub-2941435%22%20slang%3D%22en-US%22%3EAzure%20Pipeline%20-%20Powershell%20Task%20Output%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2941435%22%20slang%3D%22en-US%22%3E%3CP%3EHello%20all%2C%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20am%20looking%20to%20leverage%20Azure%20Pipelines%20to%20replace%20an%20existing%20scheduled%20task%20that%20I%20have%20running%20on%20an%20on-premise%20server.%26nbsp%3B%20Today%2C%20my%20script%20connects%20to%20a%20SQL%20database%20using%20the%20dbatools%20PowerShell%20module%2C%20runs%20a%20few%20queries%2C%20and%20dumps%20the%20files%20to%20a%20specific%20file%20format.%26nbsp%3B%20Then%20uploads%20these%20files%20to%20an%20SFTP%20server.%26nbsp%3B%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EMy%20repository%20contains%20the%20SQL%20files%20to%20run%2C%20the%20Get-Data.ps1%20script%20that%20connects%20to%20the%20database%2C%20retrieves%20the%20data%2C%20and%20exports%20it%20to%20the%20format%20necessary.%26nbsp%3B%20I%20also%20have%20a%20Send-Data.ps1%20which%20takes%20the%20files%20created%20from%20Get-Data.ps1%20and%20SFTPs%20them%20to%20an%20SFTP%20server.%3C%2FP%3E%3CP%3EI've%20got%201%20PowerShell%20script%20to%20retrieve%20and%20output%20the%20data%20to%20files%2C%20and%20another%20to%20SFTP%20the%20files%20to%20an%20SFTP%20server.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EMy%20Send-Data.ps1%20script%20has%203%20parameters%20-%20localpath%2C%20remotepath%20and%20credential.%26nbsp%3B%20I%20am%20curious%20how%20I%20could%20have%20the%20Get-Data.ps1%20script%20write%20as%20output%20the%20data%20required%20for%20%22localpath%22%20parameter%2C%20and%20then%20pass%20this%20to%20the%20Send-Data.ps1%20as%20a%202nd%20task%20in%20the%20pipeline%3F%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EAdditionally%2C%20is%20there%20a%20recommended%20way%20to%20pass%20credentials%20into%20PowerShell%20scripts%20in%20a%20pipeline%3F%26nbsp%3B%20I%20saw%20where%20I%20can%20leverage%20the%20library%20to%20store%20a%20username%20and%20password%20to%20pass%20into%20a%20script.%26nbsp%3B%20But%20this%20isn't%20a%20PSCredential%20object.%26nbsp%3B%20Would%20I%20do%20this%20by%20using%20Azure%20Keyvault%3F%26nbsp%3B%20Could%20I%20do%20it%20using%20the%20library%20and%20the%20inline%20script%20part%20of%20the%20pipeline%3F%26nbsp%3B%20Or%20read%20it%20in%20from%20the%20key%20vault%2Flibrary%2C%20create%20the%20PSCredential%20object%2C%20store%20that%20as%20a%20variable(%3F)%20and%20pass%20it%20into%20the%20PowerShell%20script%20task%3F%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThanks%20in%20advance%20for%20any%20input.%3C%2FP%3E%3CP%3ESteve%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-2941435%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EPipelines%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EPowerShell%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E
Frequent Contributor

Hello all,

 

I am looking to leverage Azure Pipelines to replace an existing scheduled task that I have running on an on-premise server.  Today, my script connects to a SQL database using the dbatools PowerShell module, runs a few queries, and dumps the files to a specific file format.  Then uploads these files to an SFTP server.  

 

My repository contains the SQL files to run, the Get-Data.ps1 script that connects to the database, retrieves the data, and exports it to the format necessary.  I also have a Send-Data.ps1 which takes the files created from Get-Data.ps1 and SFTPs them to an SFTP server.

I've got 1 PowerShell script to retrieve and output the data to files, and another to SFTP the files to an SFTP server.

 

My Send-Data.ps1 script has 3 parameters - localpath, remotepath and credential.  I am curious how I could have the Get-Data.ps1 script write as output the data required for "localpath" parameter, and then pass this to the Send-Data.ps1 as a 2nd task in the pipeline?

 

Additionally, is there a recommended way to pass credentials into PowerShell scripts in a pipeline?  I saw where I can leverage the library to store a username and password to pass into a script.  But this isn't a PSCredential object.  Would I do this by using Azure Keyvault?  Could I do it using the library and the inline script part of the pipeline?  Or read it in from the key vault/library, create the PSCredential object, store that as a variable(?) and pass it into the PowerShell script task?

 

Thanks in advance for any input.

Steve

0 Replies