dbatools is a community-maintained PowerShell module for automating SQL Server administration and migration. It provides a practical alternative when native tools do not cover every task, while avoiding custom SQL client code that may be harder to maintain. section 7.0 section 1.4.1
Use dbatools to:
- Create SQL Server databases and database objects from PowerShell. section 7.0
- Support operational workflows such as adding servers to a SQL database, searching asset records, and updating one or more server entries. section 7.0
- Choose a maintained community solution when Microsoft modules lack required coverage, while comparing it against direct SQL access and other tools. section 1.4.1
Create a SQL Express database
Set the target instance and database name, package the parameters, and call New-DbaDatabase with Simple recovery for a non-mission-critical asset-management database. section 7.0
Listing 7.1 Creating PoshAssetMgmt database
$SqlInstance = "$($env:COMPUTERNAME)\SQLEXPRESS"
$DatabaseName = 'PoshAssetMgmt'
$DbaDatabase = @{
SqlInstance = $SqlInstance
Name = $DatabaseName
RecoveryModel = 'Simple'
}
New-DbaDatabase @DbaDatabase
The listing shows the minimal parameterized pattern for creating a database with dbatools: define the SQL instance, name, and recovery model, then splat them into New-DbaDatabase. section 7.0
