Syntax error help please

  • Hello Everyone

    I am running the below script which is meant to check the creation date of certain files and send an email if the file is missing or if the creation date is not current date. When I run it in an agent job I get this error and can't figure out the correct syntax. Any help would be appreciated.

    ERROR: 'A parameter cannot be found that matches parameter name 'eq'. '. Process Exit Code -1

    Code

    Set-ExecutionPolicy RemoteSigned -ErrorAction SilentlyContinue

    $today = (get-date).Date

    $file1 = "CRAADDET"

    $file2 = "CRACRDTL"

    $file3 = "CRACRDDB"

    $file4 = "CRACON"

    $file5 = "CRACONDB"

    $file6 = "CRAAAD"

    $file7 = "CRAAPPDB"

    $files8 = "CRAAAD2"

    $files9 = "SCORECARDAPP"

    if((Test-Path -Path "\jfocus01\WFMASTERS\Created\$file1*.tab" -eq (get-date)) -eq $true) {Write-host $file1-ForegroundColor Green " File Exists"

    Send-MailMessage -From "NJFOCUS01@marlinleasing.com" -To "dbrown@marlinleasing.com" -SmtpServer "njmail03.marlincorp.com" -Body "Success" -Subject "$file1 - Arrived Successfully" }

    else {Write-Host $file1 -ForegroundColor Yellow "Does Not Exist"}

    if((Test-Path -Path "\jfocus01\WFMASTERS\Created\$file2*.tab" -eq (get-date)) -eq $true) {Write-host $file2 -ForegroundColor Green "File Exists"

    Send-MailMessage -From "NJFOCUS01@marlinleasing.com" -To "dbrown@marlinleasing.com" -SmtpServer "njmail03.marlincorp.com" -Body "Success" -Subject "$file2 - Arrived Successfully" }

    else {Write-host $file2 -ForegroundColor Yellow "Does Not Exist"}

    if((Test-Path -Path "\jfocus01\WFMASTERS\Created\$file3*.tab" -eq (get-date)) -eq $true) {Write-host $file3 -ForegroundColor Green "File Exists"

    Send-MailMessage -From "NJFOCUS01@marlinleasing.com" -To "dbrown@marlinleasing.com" -SmtpServer "njmail03.marlincorp.com" -Body "Success" -Subject "$file3 - Arrived Successfully" }

    else {Write-host $file3 -ForegroundColor Yellow "Does Not Exist"}

    if((Test-Path -Path "\jfocus01\WFMASTERS\Created\$file4*.tab" -eq (get-date)) -eq $true) {Write-host $file4 -ForegroundColor Green "File Exists"

    Send-MailMessage -From "NJFOCUS01@marlinleasing.com" -To "dbrown@marlinleasing.com" -SmtpServer "njmail03.marlincorp.com" -Body "Success" -Subject "$file4 - Arrived Successfully" }

    else {Write-host $file4 -ForegroundColor Yellow "Does Not Exist"}

    if((Test-Path -Path "\jfocus01\WFMASTERS\Created\$file5*.tab" -eq (get-date)) -eq $true) {Write-host $file5 -ForegroundColor Green "File Exists"

    Send-MailMessage -From "NJFOCUS01@marlinleasing.com" -To "dbrown@marlinleasing.com" -SmtpServer "njmail03.marlincorp.com" -Body "Success" -Subject "$file5 - Arrived Successfully" }

    else {Write-host $file5 -ForegroundColor Yellow "Does Not Exist"}

    if((Test-Path -Path "\jfocus01\WFMASTERS\Created\$file6*.tab" -eq (get-date)) -eq $true) {Write-host $file1-ForegroundColor Green " File Exists"

    Send-MailMessage -From "NJFOCUS01@marlinleasing.com" -To "dbrown@marlinleasing.com" -SmtpServer "njmail03.marlincorp.com" -Body "Success" -Subject "$file1 - Arrived Successfully" }

    else {Write-Host $file1 -ForegroundColor Yellow "Does Not Exist"}

    if((Test-Path -Path "\jfocus01\WFMASTERS\Created\$file7*.tab" -eq (get-date)) -eq $true) {Write-host $file1-ForegroundColor Green " File Exists"

    Send-MailMessage -From "NJFOCUS01@marlinleasing.com" -To "dbrown@marlinleasing.com" -SmtpServer "njmail03.marlincorp.com" -Body "Success" -Subject "$file1 - Arrived Successfully" }

    else {Write-Host $file1 -ForegroundColor Yellow "Does Not Exist"}

    if((Test-Path -Path "\jfocus01\WFMASTERS\Created\$file8*.tab" -eq (get-date)) -eq $true) {Write-host $file1-ForegroundColor Green " File Exists"

    Send-MailMessage -From "NJFOCUS01@marlinleasing.com" -To "dbrown@marlinleasing.com" -SmtpServer "njmail03.marlincorp.com" -Body "Success" -Subject "$file1 - Arrived Successfully" }

    else {Write-Host $file1 -ForegroundColor Yellow "Does Not Exist"}

    if((Test-Path -Path "\jfocus01\WFMASTERS\Created\$file9*.tab" -eq (get-date)) -eq $true) {Write-host $file1-ForegroundColor Green " File Exists"

    Send-MailMessage -From "NJFOCUS01@marlinleasing.com" -To "dbrown@marlinleasing.com" -SmtpServer "njmail03.marlincorp.com" -Body "Success" -Subject "$file1 - Arrived Successfully" }

    else {Write-Host $file1 -ForegroundColor Yellow "Does Not Exist"}

  • Pretty sure it's this bit

    Test-Path -Path "\jfocus01\WFMASTERS\Created\$file3*.tab" -eq (get-date)

    -eq isn't a parameter for Test-Path.

    "The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood"
    - Theodore Roosevelt

    Author of:
    SQL Server Execution Plans
    SQL Server Query Performance Tuning

  • Hi Grant

    I changed the code to:

    Set-ExecutionPolicy RemoteSigned -ErrorAction SilentlyContinue

    $today = (get-date).Date

    $file1 = "CRAADDET"

    $file2 = "CRACRDTL"

    $file3 = "CRACRDDB"

    $file4 = "CRACON"

    $file5 = "CRACONDB"

    $file6 = "CRAAAD"

    $file7 = "CRAAPPDB"

    $files8 = "CRAAAD2"

    $files9 = "SCORECARDAPP"

    if((Test-Path -Path "\jfocus01\WFMASTERS\Created\$file1*.tab" ($lastWriteTime -lt $today)) -eq $true) {Write-host $file1-ForegroundColor Green " File Exists"

    Send-MailMessage -From "NJFOCUS01@marlinleasing.com" -To "dbrown@marlinleasing.com" -SmtpServer "njmail03.marlincorp.com" -Body "Success" -Subject "$file1 - Arrived Successfully" }

    else {Write-Host $file1 -ForegroundColor Yellow "Does Not Exist"}

    if((Test-Path -Path "\jfocus01\WFMASTERS\Created\$file2*.tab" ($lastWriteTime -lt $today)) -eq $true) {Write-host $file2 -ForegroundColor Green "File Exists"

    Send-MailMessage -From "NJFOCUS01@marlinleasing.com" -To "dbrown@marlinleasing.com" -SmtpServer "njmail03.marlincorp.com" -Body "Success" -Subject "$file2 - Arrived Successfully" }

    else {Write-host $file2 -ForegroundColor Yellow "Does Not Exist"}

    if((Test-Path -Path "\jfocus01\WFMASTERS\Created\$file3*.tab" ($lastWriteTime -lt $today)) -eq $true) {Write-host $file3 -ForegroundColor Green "File Exists"

    Send-MailMessage -From "NJFOCUS01@marlinleasing.com" -To "dbrown@marlinleasing.com" -SmtpServer "njmail03.marlincorp.com" -Body "Success" -Subject "$file3 - Arrived Successfully" }

    else {Write-host $file3 -ForegroundColor Yellow "Does Not Exist"}

    if((Test-Path -Path "\jfocus01\WFMASTERS\Created\$file4*.tab" ($lastWriteTime -lt $today)) -eq $true) {Write-host $file4 -ForegroundColor Green "File Exists"

    Send-MailMessage -From "NJFOCUS01@marlinleasing.com" -To "dbrown@marlinleasing.com" -SmtpServer "njmail03.marlincorp.com" -Body "Success" -Subject "$file4 - Arrived Successfully" }

    else {Write-host $file4 -ForegroundColor Yellow "Does Not Exist"}

    if((Test-Path -Path "\jfocus01\WFMASTERS\Created\$file5*.tab" ($lastWriteTime -lt $today)) -eq $true) {Write-host $file5 -ForegroundColor Green "File Exists"

    Send-MailMessage -From "NJFOCUS01@marlinleasing.com" -To "dbrown@marlinleasing.com" -SmtpServer "njmail03.marlincorp.com" -Body "Success" -Subject "$file5 - Arrived Successfully" }

    else {Write-host $file5 -ForegroundColor Yellow "Does Not Exist"}

    if((Test-Path -Path "\jfocus01\WFMASTERS\Created\$file6*.tab" ($lastWriteTime -lt $today)) -eq $true) {Write-host $file1-ForegroundColor Green " File Exists"

    Send-MailMessage -From "NJFOCUS01@marlinleasing.com" -To "dbrown@marlinleasing.com" -SmtpServer "njmail03.marlincorp.com" -Body "Success" -Subject "$file1 - Arrived Successfully" }

    else {Write-Host $file1 -ForegroundColor Yellow "Does Not Exist"}

    if((Test-Path -Path "\jfocus01\WFMASTERS\Created\$file7*.tab" ($lastWriteTime -lt $today)) -eq $true) {Write-host $file1-ForegroundColor Green " File Exists"

    Send-MailMessage -From "NJFOCUS01@marlinleasing.com" -To "dbrown@marlinleasing.com" -SmtpServer "njmail03.marlincorp.com" -Body "Success" -Subject "$file1 - Arrived Successfully" }

    else {Write-Host $file1 -ForegroundColor Yellow "Does Not Exist"}

    if((Test-Path -Path "\jfocus01\WFMASTERS\Created\$file8*.tab" ($lastWriteTime -lt $today)) -eq $true) {Write-host $file1-ForegroundColor Green " File Exists"

    Send-MailMessage -From "NJFOCUS01@marlinleasing.com" -To "dbrown@marlinleasing.com" -SmtpServer "njmail03.marlincorp.com" -Body "Success" -Subject "$file1 - Arrived Successfully" }

    else {Write-Host $file1 -ForegroundColor Yellow "Does Not Exist"}

    if((Test-Path -Path "\jfocus01\WFMASTERS\Created\$file9*.tab" ($lastWriteTime -lt $today)) -eq $true) {Write-host $file1-ForegroundColor Green " File Exists"

    Send-MailMessage -From "NJFOCUS01@marlinleasing.com" -To "dbrown@marlinleasing.com" -SmtpServer "njmail03.marlincorp.com" -Body "Success" -Subject "$file1 - Arrived Successfully" }

    else {Write-Host $file1 -ForegroundColor Yellow "Does Not Exist"}

    Now I get the error: The error information returned by PowerShell is: 'A positional parameter cannot be found that accepts argument 'True'. '. Process Exit Code -1. The step failed.

    I know $true should work. Do you know where I am going wrong?

    Doug

  • But now you have that $lastwritetime construct in there. That's what's giving you conniptions. Check the documentation on test-path again. There isn't a date filter that you seem to be looking for. You could use Get-Item to look for files based on dates. There are examples here.

    "The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood"
    - Theodore Roosevelt

    Author of:
    SQL Server Execution Plans
    SQL Server Query Performance Tuning

  • Thanks Grant will do.

Viewing 5 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic. Login to reply