No error is thrown, but the data is not actually exported. What did I miss or type incorrectly? I am a complete beginner here, so sorry if this is something easys.
Function Execute-SQLquery { $Date = Get-Date -f 'MM.dd.yy' $MainPath = "C:\ReadyToPrint" $filename = "C:\TestBook\CSVTest.csv" $server = "RoyGBiv" $database = "Sparkler" $SelectQuery = "Select employeefirstname, employeelastname, employeeaddress, employeephone from employees" $connectionTemplate = "Data Source={0};Integrated Security=SSPI;Initial Catalog={1};" $connectionString = [string]::Format($connectionTemplate, $server, $database) $connection=New-Object System.Data.SqlClient.SqlConnection($connectionString) $cmd=$connection.CreateCommand() $cmd.CommandText = $SelectQuery $SqlAdapter = New-Object System.Data.SqlClient.SqlDataAdapter($cmd) $dataset = New-Object System.Data.DataTable $rowCount=$SqlAdapter.Fill($dataset) if ($rowCount -gt 0) { if(!(Test-Path -path "$MainPath\$Date\")) { New-Item "$MainPath\$Date\" -type directory } $dataset.Tables[0] | Export-Csv $filename -encoding "unicode" } $connection.Close() }