New‑SqlDscDataFile - dsccommunity/SqlServerDsc GitHub Wiki
Creates a new DataFile object for a SQL Server FileGroup and adds it to the FileGroup.
New-SqlDscDataFile -FileGroup <FileGroup> -Name <String> -FileName <String> [-PassThru] [-Force]
[-WhatIf] [-Confirm] [<CommonParameters>]
New-SqlDscDataFile -FileGroup <FileGroup> -DataFileSpec <DatabaseFileSpec> [-PassThru] [-Force]
[-WhatIf] [-Confirm] [<CommonParameters>]
New-SqlDscDataFile -Name <String> -FileName <String> [-AsSpec] [-Size <Double>] [-MaxSize <Double>]
[-Growth <Double>] [-GrowthType <String>] [-IsPrimaryFile] [-WhatIf]
[-Confirm] [<CommonParameters>]
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).
$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.
$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.
$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.
$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.
$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.
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: FalseSpecifies 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: FalseSpecifies 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: FalseSpecifies 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: FalseSpecifies 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: FalseSpecifies 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: FalseSpecifies 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: FalseSpecifies 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: FalseSpecifies 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: FalseSpecifies 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: FalseReturns 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: FalseSpecifies 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: FalsePrompts 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: FalseShows 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: FalseThis cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters.