This recipe walks you through adding secondary data files to a filegroup using PowerShell and SMO.
In this recipe,
we will add data files to the FGActive
filegroup we created for the TestDB
database in the previous recipe. If you don't have this filegroup yet, execute the following T-SQL statement in Management Studio to create the filegroup:
ALTER DATABASE [TestDB] ADD FILEGROUP [FGActive] GO
In this recipe, we will accomplish this T-SQL equivalent:
ALTER DATABASE [TestDB] ADD FILE ( NAME = N'datafile1', FILENAME = N'C:\Temp\datafile1.ndf') TO FILEGROUP [FGActive] GO
Open the PowerShell console by going to Start | Accessories | Windows PowerShell | Windows PowerShell ISE.
Import the
SQLPS
module and create a new SMO Server object, as follows:#import SQL Server module Import-Module SQLPS -DisableNameChecking #replace this with your instance name $instanceName = "KERRIGAN" $server = New-Object -TypeName Microsoft.SqlServer...