New‑SqlDscFileGroup - dsccommunity/SqlServerDsc GitHub Wiki

SYNOPSIS

Creates a new FileGroup object for a SQL Server database.

SYNTAX

Standalone (Default)

New-SqlDscFileGroup -Name <String> [-WhatIf] [-Confirm]
 [<CommonParameters>]

WithDatabaseFromSpec

New-SqlDscFileGroup -Database <Database> -FileGroupSpec <DatabaseFileGroupSpec> [-Force]
 [-WhatIf] [-Confirm] [<CommonParameters>]

WithDatabase

New-SqlDscFileGroup -Database <Database> -Name <String> [-Force] [-WhatIf]
 [-Confirm] [<CommonParameters>]

AsSpec

New-SqlDscFileGroup -Name <String> [-AsSpec] [-Files <DatabaseFileSpec[]>] [-ReadOnly] [-IsDefault]
 [-WhatIf] [-Confirm] [<CommonParameters>]

DESCRIPTION

This command creates a new FileGroup object that can be used when creating or modifying SQL Server databases. The FileGroup object can contain DataFile objects. The FileGroup can be created with or without an associated Database, allowing it to be added to a Database later using Add-SqlDscFileGroup.

EXAMPLES

EXAMPLE 1

$serverObject = Connect-SqlDscDatabaseEngine -InstanceName 'MyInstance'
$database = $serverObject.Databases['MyDatabase']
$fileGroup = New-SqlDscFileGroup -Database $database -Name 'MyFileGroup'

Creates a new FileGroup named 'MyFileGroup' for the specified database.

EXAMPLE 2

$serverObject = Connect-SqlDscDatabaseEngine -InstanceName 'MyInstance'
$database = $serverObject.Databases['MyDatabase']
$fileGroup = New-SqlDscFileGroup -Database $database -Name 'PRIMARY'

Creates a new PRIMARY FileGroup for the specified database.

EXAMPLE 3

$fileGroup = New-SqlDscFileGroup -Name 'MyFileGroup'
Add-SqlDscFileGroup -Database $database -FileGroup $fileGroup

Creates a standalone FileGroup that can be added to a Database later.

EXAMPLE 4

$fileGroupSpec = New-SqlDscFileGroup -Name 'PRIMARY' -AsSpec

Creates a DatabaseFileGroupSpec object that can be passed to New-SqlDscDatabase.

EXAMPLE 5

$primaryFile = New-SqlDscDataFile -Name 'MyDB_Primary' -FileName 'D:\SQLData\MyDB.mdf' -Size 102400 -IsPrimaryFile -AsSpec
$fileGroupSpec = New-SqlDscFileGroup -Name 'PRIMARY' -Files @($primaryFile) -IsDefault $true -AsSpec

Creates a DatabaseFileGroupSpec object with files and properties set directly via parameters.

PARAMETERS

-AsSpec

Returns a DatabaseFileGroupSpec object instead of a SMO FileGroup object. This specification object can be passed to New-SqlDscDatabase to define file groups before the database is created.

Type: SwitchParameter
Parameter Sets: AsSpec
Aliases:

Required: True
Position: Named
Default value: False
Accept pipeline input: False
Accept wildcard characters: False

-Database

Specifies the Database object to which this FileGroup will belong. This parameter is optional. If not specified, a standalone FileGroup is created that can be added to a Database later.

Type: Database
Parameter Sets: WithDatabaseFromSpec, WithDatabase
Aliases:

Required: True
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

-FileGroupSpec

Specifies a DatabaseFileGroupSpec object that defines the file group configuration including name, properties, and data files.

Type: DatabaseFileGroupSpec
Parameter Sets: WithDatabaseFromSpec
Aliases:

Required: True
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

-Files

Specifies an array of DatabaseFileSpec objects to include in the file group. Only valid when using -AsSpec.

Type: DatabaseFileSpec[]
Parameter Sets: AsSpec
Aliases:

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

-Force

Specifies that the FileGroup object should be created without prompting for confirmation. By default, the command prompts for confirmation when the Database parameter is provided.

Type: SwitchParameter
Parameter Sets: WithDatabaseFromSpec, WithDatabase
Aliases:

Required: False
Position: Named
Default value: False
Accept pipeline input: False
Accept wildcard characters: False

-IsDefault

Specifies whether this file group should be the default file group. Only valid when using -AsSpec.

Type: SwitchParameter
Parameter Sets: AsSpec
Aliases:

Required: False
Position: Named
Default value: False
Accept pipeline input: False
Accept wildcard characters: False

-Name

Specifies the name of the FileGroup to create.

Type: String
Parameter Sets: Standalone, WithDatabase, AsSpec
Aliases:

Required: True
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

-ReadOnly

Specifies whether the file group should be read-only. Only valid when using -AsSpec.

Type: SwitchParameter
Parameter Sets: AsSpec
Aliases:

Required: False
Position: Named
Default value: False
Accept pipeline input: False
Accept wildcard characters: False

-Confirm

Prompts you for confirmation before running the cmdlet.

Type: SwitchParameter
Parameter Sets: (All)
Aliases: cf

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

-WhatIf

Shows what would happen if the cmdlet runs. The cmdlet is not run.

Type: SwitchParameter
Parameter Sets: (All)
Aliases: wi

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

CommonParameters

This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters.

INPUTS

None

This cmdlet does not accept input from the pipeline.

OUTPUTS

Microsoft.SqlServer.Management.Smo.FileGroup

When creating a FileGroup with or without an associated Database (not using -AsSpec).

DatabaseFileGroupSpec

When using the -AsSpec parameter to create a specification object.

NOTES

RELATED LINKS

⚠️ **GitHub.com Fallback** ⚠️