Set DataFile Size

Apr 12, 2012 at 11:08 PM

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 2: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 4:50 PM
Edited Apr 13, 2012 at 4:52 PM

Thanks for the reply, that made it work.