0

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

1 Answer 1

2

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++

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.