Author Posts

January 1, 2012 at 12:00 am

by VPham at 2012-11-19 13:20:28

Hi Guys

Could someone pelase help me wit the below Power Shell Script. the below script currenlty works but its only polling for 1 file at one location , im needing it to look for 4 differemt files at 4 different location .

Was going to create 4 jobs for each file but seeing if it can be done in one job

any help would be much appreciated

Cheers Guys

$DataPath = "ARAP_MI_EXTRACT\TNZ\ACCOUNT"
$continue = $true
while ($continue)
{
write-host "Checking for files"
$items = Get-ChildItem -Path $DataPath -Filter "MI_EXP_20121031000531985_ACCOUNT.csv"
if ($items -ne $null )
{
$continue = $false
Add-PSSnapin MVPSI.JAMS -ErrorAction SilentlyContinue
Submit-JAMSEntry < >\Account_Ageing_Job_2>>
}

start-sleep < >
}

by DonJ at 2012-11-20 08:56:37

(FYI – you can use the Code and PowerShell buttons on the toolbar to have your code format nicely – easier to read, too)

So, a couple of notes. First, consider using Test-Path to see if the file exists.


If (Test-Path $FilePath) {
# file exists
}

There's no reason you couldn't have multiple blocks like that, each one checking for a specific file. $FilePath, in my example, would contain the complete path and filename.

by VPham at 2012-11-21 14:52:36

cheers Donj

Thought id give this a try , looks to have worked but instead of polling for what ever file arrives first it polls in order/sequence, e.g if ACCOUNT123456789.csv arrives first it will not show that the file has arrived untill file ACCOUNT12.csv has turned up.

instead of it polling in order from top to bottom is there a way of just getting the job to complete what ever file it finds ?

Cheers All.

$DataPath = "ARAP_MI_EXTRACT\TNZ\ACCOUNT12"
$continue = $true
while ($continue)
{
write-host "Checking for files"
$items = Get-ChildItem -Path $DataPath -Filter "MI_EXP_20121031000531985_ACCOUNT12.csv"
if ($items -ne $null )
{
$continue = $false
Add-PSSnapin MVPSI.JAMS -ErrorAction SilentlyContinue
Submit-JAMSEntry < >\Account_Ageing_Job_2>>
}

start-sleep < >
}

$DataPath = "ARAP_MI_EXTRACT\TNZ\ACCOUNT123456789"
$continue = $true
while ($continue)
{
write-host "Checking for files"
$items = Get-ChildItem -Path $DataPath -Filter "MI_EXP_20121031000531985_ACCOUNT123456789.csv"
if ($items -ne $null )
{
$continue = $false
Add-PSSnapin MVPSI.JAMS -ErrorAction SilentlyContinue
Submit-JAMSEntry < >\Account_Ageing_Job_2>>
}

start-sleep < >
}

by DonJ at 2012-11-21 15:04:59

Ah. I don't think you mentioned that there'd be multiple incoming files. Yes, whenever it gets a directory listing it'll be in a default order – you can use Sort-Object to change that, perhaps sorting by creation time in to get the most recent file.