Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Syntax error help please Expand / Collapse
Author
Message
Posted Friday, March 21, 2014 10:18 PM


SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Friday, August 8, 2014 11:44 AM
Points: 133, Visits: 282
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"}
Post #1553734
Posted Saturday, March 22, 2014 5:02 AM


SSCoach

SSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoach

Group: General Forum Members
Last Login: Today @ 4:57 PM
Points: 15,661, Visits: 28,047
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
The Scary DBA
Author of: SQL Server 2012 Query Performance Tuning
SQL Server 2008 Query Performance Tuning Distilled
and
SQL Server Execution Plans

Product Evangelist for Red Gate Software
Post #1553748
Posted Saturday, March 22, 2014 5:42 PM


SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Friday, August 8, 2014 11:44 AM
Points: 133, Visits: 282
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
Post #1553781
Posted Sunday, March 23, 2014 3:06 AM


SSCoach

SSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoach

Group: General Forum Members
Last Login: Today @ 4:57 PM
Points: 15,661, Visits: 28,047
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
The Scary DBA
Author of: SQL Server 2012 Query Performance Tuning
SQL Server 2008 Query Performance Tuning Distilled
and
SQL Server Execution Plans

Product Evangelist for Red Gate Software
Post #1553802
Posted Sunday, March 23, 2014 7:36 PM


SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Friday, August 8, 2014 11:44 AM
Points: 133, Visits: 282
Thanks Grant will do.
Post #1553847
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse