Home > Blockchain >  Call one Powershell script 2 from powershell script 1 with parameters
Call one Powershell script 2 from powershell script 1 with parameters

Time:09-21

I have below PowerShell script which generate some set of CSV files from large CSV files

$BatchNr = 1
Import-Csv -Path .\Master.csv |Create-Batch -Size 50 |ForEach-Object {
    $_ |ForEach-Object {
        $_ # do something with each item in the batch of 50
    } |Export-Csv ".\Batch$BatchNr.csv"
    $BatchNr  
}

And results will be Batch1.CSV, Batch2.CSV and so on

Now I have another powershell script which do some operations with this Batch1.CSV, Batch2.CSV. example below

$Users = Import-Csv -Path "Batch1.CSV"

But now i have to do it manually take each Batch. How can call this files from my PS1 file as soon as file create it, PS2 take files and execute it and after 15 minutes next files like this

CodePudding user response:

Change the second script to accept the CSV path as a parameter:

# script2.ps1
param(
  [string]$LiteralPath
)

$Users = Import-Csv -LiteralPath $LiteralPath

# ...

Then change the first script to pass the next CSV name to it:

    $_ |ForEach-Object {
        $_ # do something with each item in the batch of 50
    } |Export-Csv ".\Batch$BatchNr.csv"
    .\script2.ps1 -LiteralPath ".\Batch$BatchNr.csv"
    $BatchNr  
  • Related