New‑SqlDscDataFile - dsccommunity/SqlServerDsc GitHub Wiki

SYNOPSIS

Creates a new DataFile object for a SQL Server FileGroup and adds it to the FileGroup.

SYNTAX

Standard (Default)

New-SqlDscDataFile -FileGroup <FileGroup> -Name <String> -FileName <String> [-PassThru] [-Force]
 [-WhatIf] [-Confirm] [<CommonParameters>]

FromSpec

New-SqlDscDataFile -FileGroup <FileGroup> -DataFileSpec <DatabaseFileSpec> [-PassThru] [-Force]
 [-WhatIf] [-Confirm] [<CommonParameters>]

AsSpec

New-SqlDscDataFile -Name <String> -FileName <String> [-AsSpec] [-Size <Double>] [-MaxSize <Double>]
 [-Growth <Double>] [-GrowthType <String>] [-IsPrimaryFile] [-WhatIf]
 [-Confirm] [<CommonParameters>]

DESCRIPTION

This command creates a new DataFile object and automatically adds it to the specified FileGroup's Files collection. The DataFile object represents a physical database file (.mdf, .ndf, or .ss for snapshots).

EXAMPLES

EXAMPLE 1

$serverObject = Connect-SqlDscDatabaseEngine -InstanceName 'MyInstance'
$database = $serverObject.Databases['MyDatabase']
$fileGroup = New-SqlDscFileGroup -Database $database -Name 'PRIMARY'
New-SqlDscDataFile -FileGroup $fileGroup -Name 'MyDatabase_Data' -FileName 'C:\Data\MyDatabase_Data.mdf' -Force

Creates a new DataFile for a regular database with a FileGroup and adds it to the FileGroup.

EXAMPLE 2

$serverObject = Connect-SqlDscDatabaseEngine -InstanceName 'MyInstance'
$database = $serverObject.Databases['MyDatabase']
$fileGroup = New-SqlDscFileGroup -Database $database -Name 'PRIMARY'
$dataFile = New-SqlDscDataFile -FileGroup $fileGroup -Name 'MySnapshot_Data' -FileName 'C:\Snapshots\MySnapshot_Data.ss' -PassThru -Force

Creates a new sparse file for a database snapshot and returns the DataFile object.

EXAMPLE 3

$serverObject = Connect-SqlDscDatabaseEngine -InstanceName 'MyInstance'
$database = $serverObject.Databases['MyDatabase']
$fileGroup = $database.FileGroups['PRIMARY']
$dataFile = New-SqlDscDataFile -FileGroup $fileGroup -Name 'AdditionalData' -FileName 'C:\Data\AdditionalData.ndf' -PassThru -Force

Creates an additional DataFile and returns it for further processing.

EXAMPLE 4

$dataFileSpec = New-SqlDscDataFile -Name 'MyDB_Primary' -FileName 'D:\SQLData\MyDB.mdf' -AsSpec

Creates a DatabaseFileSpec object that can be used with New-SqlDscFileGroup -AsSpec or passed to New-SqlDscDatabase.

EXAMPLE 5

$dataFileSpec = New-SqlDscDataFile -Name 'MyDB_Primary' -FileName 'D:\SQLData\MyDB.mdf' -Size 102400 -MaxSize 5242880 -Growth 10240 -GrowthType 'KB' -IsPrimaryFile -AsSpec

Creates a DatabaseFileSpec object with all properties set directly via parameters.

PARAMETERS

-AsSpec

Returns a DatabaseFileSpec object instead of a SMO DataFile object. This specification object can be used with New-SqlDscFileGroup -AsSpec or passed directly to New-SqlDscDatabase to define data files before the database is created.

When this parameter is used, the command always returns a DatabaseFileSpec object, regardless of the PassThru parameter, and the FileGroup parameter is not available.

Type: SwitchParameter
Parameter Sets: AsSpec
Aliases:

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

-DataFileSpec

Specifies a DatabaseFileSpec object that defines the data file configuration including name, file path, size, growth, and other properties.

Type: DatabaseFileSpec
Parameter Sets: FromSpec
Aliases:

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

-FileGroup

Specifies the FileGroup object to which this DataFile will belong. The DataFile will be automatically added to this FileGroup's Files collection.

Type: FileGroup
Parameter Sets: Standard, FromSpec
Aliases:

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

-FileName

Specifies the physical path and filename for the DataFile. For database snapshots, this should point to a sparse file location (typically with an .ss extension). For regular databases, this should be the data file path (typically with .mdf or .ndf extension).

Type: String
Parameter Sets: Standard, AsSpec
Aliases:

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

-Force

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

Type: SwitchParameter
Parameter Sets: Standard, FromSpec
Aliases:

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

-Growth

Specifies the amount by which the data file grows when it requires more space. The value is interpreted according to the GrowthType parameter (kilobytes or percentage). Only valid when used with the -AsSpec parameter to create a DatabaseFileSpec object.

Type: Double
Parameter Sets: AsSpec
Aliases:

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

-GrowthType

Specifies the type of growth for the data file. Valid values are 'KB', 'MB', or 'Percent'. Only valid when used with the -AsSpec parameter to create a DatabaseFileSpec object.

Type: String
Parameter Sets: AsSpec
Aliases:

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

-IsPrimaryFile

Specifies that this data file is the primary file in the PRIMARY filegroup. Only valid when used with the -AsSpec parameter to create a DatabaseFileSpec object.

Type: SwitchParameter
Parameter Sets: AsSpec
Aliases:

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

-MaxSize

Specifies the maximum size to which the data file can grow, in kilobytes. Only valid when used with the -AsSpec parameter to create a DatabaseFileSpec object.

Type: Double
Parameter Sets: AsSpec
Aliases:

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

-Name

Specifies the logical name of the DataFile.

Type: String
Parameter Sets: Standard, AsSpec
Aliases:

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

-PassThru

Returns the DataFile object that was created and added to the FileGroup. Only available when using the Standard or FromSpec parameter sets. When using the AsSpec parameter set, a DatabaseFileSpec object is always returned.

Type: SwitchParameter
Parameter Sets: Standard, FromSpec
Aliases:

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

-Size

Specifies the initial size of the data file in kilobytes. Only valid when used with the -AsSpec parameter to create a DatabaseFileSpec object.

Type: Double
Parameter Sets: AsSpec
Aliases:

Required: False
Position: Named
Default value: None
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

None

This cmdlet does not generate output by default when using Standard or FromSpec parameter sets without PassThru.

Microsoft.SqlServer.Management.Smo.DataFile

When using the Standard or FromSpec parameter sets with the PassThru parameter.

DatabaseFileSpec

When using the AsSpec parameter to create a specification object.

NOTES

RELATED LINKS

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