Is it possible to create a Database in SQL Server with powershell?

前端 未结 7 2100
隐瞒了意图╮
隐瞒了意图╮ 2020-12-09 04:39

I am trying to create a empty database in SQL server using powershell and SMO but cannot seem to find a way of doing it. Is this possible?

Connection script for sql

相关标签:
7条回答
  • 2020-12-09 05:06

    Far too much hassle above if you ask me, this works just fine:

    $s = New-PSSession -ComputerName SQLDB -Credential DOMAIN\USER
    
    Invoke-Command -Session $s -ScriptBlock {Invoke-Sqlcmd -ServerInstance SQLDB\INSTANCE -InputFile C:\Users\USER\Downloads\CREATEDB.sql}
    

    Only thing is - you will need to have your DB script already formed and called from thus said location. This is easier for me though due to this being a small part of a bigger script - i dont want to bloat my script if i dont have to and can call SQL scripts from a repo.

    0 讨论(0)
提交回复
热议问题