I am trying to run the sql script.sql file from powershell and save the result in a .sql file. Overview: restoring a SQL database requires a preliminary restoration of the user's backup and permissions, and after the restoration is complete, we need to output (back up the user permissions that we previously performed) to the database.
heres my script, and when I execute, I see an empty file.
Add-PSSnapin SqlServerProviderSnapin100; $server = 'DBA_Test'; $database = 'Test'; $mydata = invoke-sqlcmd -inputfile "C:\users\security.sql" -serverinstance $server -database $database | Format-Table -HideTableHeaders -AutoSize $mydata | out-file C:\users\output.sql; Remove-PSSnapin SqlServerCmdletSnapin100;
Can someone help me with this?
Thanks in advance
sql-server powershell
Robin16
source share