Ankit Kumar
Ankit Kumar

Reputation: 514

Read Powershell cmdlet argument from a local file

I have the following Powershell Cmdlet where I pass certain arguments as "token" and "days" and it gives me value as below. the values are list of Ids and a token. I would like first the token parameter to be taken from a local text file and next time when we run this it store the generated output token in the same file overwriting it.

So that next time when I run this it take the token which was generated in the last run. How can I do that?

Powershell Cmdlet:

Get-ChangedBills -ContinuationToken '18883' -MaxAge '2'

Output:

ContinuationToken BillsId
----------------- ----------
"184505"          {23, 33, 12, 449...}

I would like to store this Continuation Token in a file locally and in next run the Continuation token argument value is taken in the PowerShell cmdlet from the same file.

How can I achieve this?

Upvotes: 0

Views: 83

Answers (1)

Mathias R. Jessen
Mathias R. Jessen

Reputation: 174815

You can store the continuation token value in a simple text file:

'18883' |Set-Content .\token.txt

Then, in the script that executes Get-ChangedBills:

param(
  $TokenFilePath = '.\token.txt'
)

$existingToken = Get-Content -Path $TokenFilePath

$changedBills = Get-ChangedBills -ContinuationToken $existingToken -MaxAge '2'

# do your work here

# update token on disk
$changedBills.ContinuationToken.Trim('"') |Set-Content -Path $TokenFilePath

Upvotes: 1

Related Questions