Export SQL objects using dbatools

128 views Asked by At

I am trying to export objects from SQL databases (including SQL Agent jobs) using the following scripts:

$SourceServer = "***";
$folder = "c:\temp\sqljobs\"

Get-DbaAgentJob -SqlInstance $SourceServer | ForEach-Object { Export-DbaScript -InputObject $_ -Path ($folder + $_.Name + “.sql”) }



$SourceServer = "***";
$SourceDB = "***";
$folder = "c:\temp\sqltables\"

Get-DbaDBTable -SqlInstance $SourceServer -Database $SourceDB | ForEach-Object { Export-DbaScript -InputObject $_ -Path ($folder + $_.Name + “.sql”) }

The objects are being correctly exported but a folder is created in the root folder with the objectname and inside I have the sql script with the server name and timestamp.

I was wondering if I can generate the sql script itself directly to root folder without creating the folder with the object name.

0

There are 0 answers