How to apply the if
statement based on the command response. Following PowerShell
script is working fine. But the .imported
file should not create when ever the command java -Dc=xyz
response throws an error.
foreach($file in (Get-ChildItem 'C:\ghost\rider' -Recurse)) {
if ($file -Like '*.json') {
$file.FullName
$importedFilename=$newname = $file.DirectoryName+'\'+$file.BaseName+'.imported'
if(!(Test-Path $importedFilename)){
java -Dc=xyz -Dtype=application/json -jar post.jar $file.FullName # After this statement execution I need to apply the if statement based on the response.?
New-Item $importedFilename # This line should not execute always
}else{
'Already imported! '+$file.FullName
}
}
}
I am getting success message like below when the line java -Dc=....
executed. After that I am trying to creating a file .imported for tracking purpose.
SimplePostTool version 5.0.0
Posting files to [base] url http://localhost:8983/solr/xads/update using content-type application/json...
POSTing file rockdata.json to [base]
1 files indexed.
COMMITting Solr index changes to http://localhost:8983/solr/xads/update...
Time spent: 0:00:33.925