credential.txt<\/a> (60 Bytes)<\/p>","upvoteCount":0,"datePublished":"2021-04-20T20:03:36.000Z","url":"https://community.spiceworks.com/t/send-mail-if-found-blank-in-csv-file/797484/9","author":{"@type":"Person","name":"marlon3","url":"https://community.spiceworks.com/u/marlon3"}},{"@type":"Answer","text":"here you go<\/p>\n
function start-csvcheck {\n param(\n [parameter(mandatory)]\n $csv\n )\n\n $csv = import-csv $csv\n $noteproperties = ($csv | get-member | where-object MemberType -eq 'noteproperty').name\n $counter = 2\n\n $report = \n foreach ($row in $csv) {\n $propertycheck =\n foreach ($property in $noteproperties) {\n if ([string]::IsNullOrEmpty($row.$property) -or [string]::IsNullOrWhiteSpace($row.$property)) {\n write-output $property\n }\n elseif ($row.$property -match '\\s$+') {\n write-output $property\n }\n }\n \n if ($propertycheck) {\n [pscustomobject]@{\n Status = 'Error'\n Row = $counter\n Column = $propertycheck -join ','\n }\n }\n ++$counter\n }\n $report\n}\n\n$csvcheck = start-csvcheck \"C:\\Users\\neally\\Desktop\\Book2.csv\"\n\n# display to host\n$csvcheck\n\nif ($csvcheck) {\n\n$Head = \n@\"\n<style>\nbody { background-color:#f6f6f6;}\nTABLE {border-width: 0px;border-style: solid;border-color: black;border-collapse: collapse;}\nTH {border-width: 1px;padding: 1px;border-style: solid;border-color: black;background-color: #34495e ; color:white;text-align: center;}\nTD {border-width: 1px;padding: 1px;border-style: solid;border-color: black;text-align: center;}\nTR:Nth-Child(Even) {Background-Color: #dddddd;text-align: center;}\n</style>\n\"@\n $mailer = @{\n To = \"[email protected]\"\n From = \"[email protected]\"\n Subject = \"Error in CSV\"\n Body = $csvcheck | convertto-html -Head $head | out-string\n BodyAsHtml = $true\n Smtpserver = \"smtphost\"\n }\n Send-MailMessage @mailer\n}\nelse {\n Write-Output \"CSV check pass\"\n}\n<\/code><\/pre>","upvoteCount":0,"datePublished":"2021-04-20T21:56:54.000Z","url":"https://community.spiceworks.com/t/send-mail-if-found-blank-in-csv-file/797484/10","author":{"@type":"Person","name":"Neally","url":"https://community.spiceworks.com/u/Neally"}},{"@type":"Answer","text":"Wow, its superb.<\/p>\n
Thanks Neally for this.<\/p>\n
right now, ill be adding if the file is exist or not to the script then send mail.<\/p>","upvoteCount":0,"datePublished":"2021-04-21T12:46:56.000Z","url":"https://community.spiceworks.com/t/send-mail-if-found-blank-in-csv-file/797484/11","author":{"@type":"Person","name":"marlon3","url":"https://community.spiceworks.com/u/marlon3"}}]}}