This project is read-only.

Set DataFile Size

Apr 13, 2012 at 12:08 AM

Is there a way to set the size of a data file with SQLPSX?  The Get-SqlDataFile returns a SMO data file object, and the does have a set_size function.  However when I run it I get Cannot set the Value property for PSMEMberInfo object of type "System.Management.Automation.PSMethod".

$File = Get-SqlDatabase "localhost" "AdventureWorks" | Get-SqlDataFile



Apr 13, 2012 at 3:29 AM

Try the following code which I've tested successfully:

import-module sqlserver

$file = get-sqldatabase localhost AdventureWorks | Get-SqlDataFile

file.size = 2500



The key is calling the alter method. With many of the SMO classes changes are not committed until the alter method of the underlying object is called.

Apr 13, 2012 at 5:50 PM
Edited Apr 13, 2012 at 5:52 PM

Thanks for the reply, that made it work.