Currently My code is
Invoke-sqlcmd -query "Select * from master.sys.table" -ServerInstance myserver -database -mydb | convert-csv | select -skip 2 | .\7z.exe a -si tgzip $gzipedfilename
The problem here is, Invoke-sqlcmd is producing huge resultset and which in turn putting huge pressure on convert-csv and it's throwing out of memory exception.
Is there a way Invoke-sqlcmd produces the csv resultset directly?