by VPham at 2012-11-19 13:20:28
Hi Guysby DonJ at 2012-11-20 08:56:37
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 <<JAMS.System.SystemName>>\Account_Ageing_Job_2>>
}
start-sleep <<reschedule_secs>>
}
(FYI - you can use the Code and PowerShell buttons on the toolbar to have your code format nicely - easier to read, too)by VPham at 2012-11-21 14:52:36
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.
cheers Donjby DonJ at 2012-11-21 15:04:59
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 <<JAMS.System.SystemName>>\Account_Ageing_Job_2>>
}
start-sleep <<reschedule_secs>>
}
$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 <<JAMS.System.SystemName>>\Account_Ageing_Job_2>>
}
start-sleep <<reschedule_secs>>
}
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.