$From = ""
$To = ""
$Cc = ""
#$Attachment = "C:\temp\Some random file.txt"
$SMTPServer = ""
$SMTPPort = "25"
$Subject = "Success - PVD Parcel Data Extract Completed Successfully"
$Body = "PVD Parcel Data Extract CompleSQLPPted Successfully"
$StartTime = Get-Date
function ErrorHandler($error)
{
$ErrorTime = Get-Date
$Subject = "Failure - PVD Parcel Data Extract Process Started at $StartTime and failed to Complete at $ErrorTime"
$Body = "PVD Parcel Data Extract Process failed to Complete"
Send-MailMessage -From $From -to $To -Cc $Cc -Subject $Subject -Body $Body -SmtpServer $SMTPServer
}
trap { ErrorHandler $_; break }
$ErrorActionPreference = "Stop"
#Prod Setup using Cloud URL
#Setup your credential
$username = ""
$password = "" | ConvertTo-SecureString -AsPlainText -Force
$credential = New-Object System.Management.Automation.PSCredential($username,$password)
#Get a session object to pass to other cmdlet's
#Prod Cloud Session
$session = Get-PVDSession -URL "" -Credential $credential -UseSSL
#$query = "SELECT top(100000) * FROM vd_vw_VendorDB_ParcelGIS;"
#$query = "SELECT * FROM vd_vw_VendorDB_ParcelGIS;"
$query = "SELECT
[ParcelNumber]
,[AltParcelNumber]
,[MapNumber]
,case OwnerName when 'NA' then 'Occupant' else OwnerName end ownername
,case OwnerName when 'NA' then '' else OwnerName2 end ownername2
,case OwnerName when 'NA' then '' else OwnerName3 end ownername3
,case OwnerName when 'NA' then '' else OwnerName4 end ownername4
,[OwnerAddress]
,[OwnerAddress2]
,[OwnerCity]
,[OwnerState]
,[OwnerZip]
,[OwnerForeignState]
,[OwnerForeignCountry]
,[Township]
,[LegalDescription]
,[Acreage]
,[PropertyClass]
,[PropertySubClass]
,[PropertySubClassDescription]
,[AddressNumber]
,[AddressNumberFraction]
,[AddressDirection]
,[AddressStreetName]
,[AddressStreetSuffix]
,[AddressStreetSuffix2]
,[AddressCity]
,[AddressZip]
,[FullAddress1]
,[FullAddress2]
,[Block]
,[Lot]
,[StateBlock]
,[StateTaxDistrictID]
,[TaxDistrict]
,[STR_Section]
,[STR_Township]
,[STR_Range]
,[AssessorDistrict]
,[SubdivisionID]
,[SubdivisionName]
,[LandNeighborhood]
,[Neighborhood]
,[NeighborhoodFactor]
,[TrendingFactor]
,[PlatBook]
,[PPFormType]
,[CondoType]
,[Sewer]
,[Water]
,[Gas]
,[Electricity]
,[Alley]
,[Sidewalk]
,[RoadType]
,[Topography]
,[AssessorYear]
,[AssessorYear_LandC1]
,[AssessorYear_LandC2]
,[AssessorYear_LandC3]
,[AssessorYear_ImpC1]
,[AssessorYear_ImpC2]
,[AssessorYear_ImpC3]
,[AssessorYear_LandTotal]
,[AssessorYear_ImpTotal]
,[AssessorYear_TotalAV]
,[CertifiedYear]
,[CertifiedYear_LandC1]
,[CertifiedYear_LandC2]
,[CertifiedYear_LandC3]
,[CertifiedYear_ImpC1]
,[CertifiedYear_ImpC2]
,[CertifiedYear_ImpC3]
,[CertifiedYear_LandTotal]
,[CertifiedYear_ImpTotal]
,[CertifiedYear_TotalAV]
,[Status]
,[AssessedBy]
,[AssessedDate]
,[CheckedBy]
,[CheckedDate]
,[UpdatedBy]
,[UpdateDate]
,[CamaParcelID] FROM vd_vw_VendorDB_ParcelGIS;"
Get-PVDAdhocQuery -Session $session -Query $query | Out-PVDQueryToFile -FileName "C:\PVD_GIS_Extracts\Extract_Files\Parcel_extract_cloud_test.csv" -Delimited -Delimiter "|"
$EndTime = Get-Date
$Body = "PVD Parcel Data Extract Started at $StartTime and Completed Successfully at $EndTime"
Send-MailMessage -From $From -to $To -Cc $Cc -Subject $Subject -Body $Body -SmtpServer $SMTPServer
exit