Customize Shared Folders - Windows Server Essentials
Applies To: Windows Server 2012 R2 Essentials
During the Initial Configuration of the server, a set of default server folders are created. This includes shared folders and the client computer backup folder, which are created in the largest data partition on Disk 0. To customize the location and specify additional server folders, create a new storage registry key.
To create a new Storage registry key
On the server, move your mouse to the upper right corner of the screen, and click Search.
In the Search box, type regedit, and then click the Regedit application.
In the navigation pane, expand HKEY_LOCAL_MACHINE, expand SOFTWARE, and then expand Microsoft.
Right-click Windows Server, click New, and then click Key.
Name the key Storage.
In the navigation pane, right-click the new Storage registry key, click New, and then click DWORD (32-bit) Value.
Name the string CreateFoldersOnSystem.
Right-click CreateFoldersOnSystem, and then click Modify. The Edit String dialog box appears.
Set the value of this new key to 1, and then click OK.
After setting the key, use either of the following two methods to move the folders to a different location or create additional folders.
Use the PostIC.cmd script to move the folders to a different location or to create additional folders. See the following example: Example 1: Create a custom folder and move the default folders to a new location from PostIC.cmd by using Windows PowerShell.
Use the Windows Server Solutions SDK to move the folders to a different location or to create additional folders. See the following example: Example 2: Create a custom folder and move an existing folder by using the Windows Server Solutions SDK.
Optionally, leave the data folders on the system drive. This allows the customer or reseller to determine the layout of the data folders on the data drives.
Example 1: Create a custom folder and move the default folders to a new location from PostIC.cmd by using Windows PowerShell
Create a PostIC.cmd file for running post Initial Configuration tasks as detailed in the Add Post-Initial Configuration Customizations (PostIC.cmd) - Windows Server Essentials section.
Using Notepad, create a file named customizefolders.ps1 in the C:\Windows\Setup\Scripts folder, and then paste the following Windows PowerShell® commands into the file (unmark appropriate lines depending on the desired behavior).
# Move the Documents folder to D:\ServerFolders #Get-WssFolder -name Documents| Move-WssFolder - NewDrive D:\ -Force # Check for last error. If last error is not null, exit with return code 1 #If ($error[0] -ne $null) { exit 1} # Move all folders to D:\ServerFolders #foreach( $folder in Get-WssFolder ) #{ # Move-WssFolder $folder -NewDrive D:\ -Force #} # Check for last error. If last error is not null, exit with return code 1 #If ($error[0] -ne $null) { exit 1} # Create a custom folder named Custom Folder #Add-WssFolder -Name CustomFolder -Path D:\ServerFolders\CustomFolder -Description "Custom Folder" # Check for last error. If last error is not null, exit with return code 1 #If ($error[0] -ne $null) { exit 1} exit 0
Add the following line to the PostIC.cmd file to run this script.
REM Lower the execution policy "%programfiles%\Windows Server\bin\WssPowershell.exe" "Set-ExecutionPolicy RemoteSigned" REM Execute the folder customization script "%programfiles%\Windows Server\bin\WssPowershell.exe" -NoProfile -Noninteractive -command ". %windir%\setup\scripts\customizefolders.ps1;exit $LASTEXITCODE" Set error_level=%ERRORLEVEL% REM Restore the execution policy to default "%programfiles%\Windows Server\bin\WssPowershell.exe" "Set-ExecutionPolicy Restricted" Set ERRORLEVEL=%error_level%
Example 2: Create a custom folder and move an existing folder by using the Windows Server Solutions SDK
The code that you create can be complied as an executable, and then called from the PostIC.cmd file or called directly from an installed add-in.
static void Main(string[] args)
{
StorageManager storageManager = new StorageManager();
//Connect to the StorageManager
storageManager.Connect();
//Move the Documents folder to D:\ServerFolders
Folder targetFolder = storageManager.Folders.First(folder => folder.Name == "Documents");
MoveFolderRequest moveRequest = targetFolder.GetMoveRequest(@"D:\");
moveRequest.MoveFolder();
//Verify operation was successful, if so print result
if (moveRequest.Status == OperationStatus.Succeeded)
{
Console.WriteLine("Folder {0} now located at {1}", targetFolder.Name, targetFolder.Path);
}
string newFolderName = "New Custom Folder";
string newFolderLocation = @"C:\ServerFolders\New Custom Folder";
//Create add request based with specific name and location
CreateFolderRequest request = storageManager.GetCreateFolderRequest(newFolderName, newFolderLocation);
//Give Guest user read only permission to folder
request.PermissionsByName.Add(new NamePermission("Guest", Permission.ReadOnly));
//Create the new folders
request.CreateFolder();
//Verify operation was successful, if so print result
if( request.Status == OperationStatus.Succeeded)
{
Folder newFolder = storageManager.Folders.First(folder => folder.Path == newFolderLocation);
Console.WriteLine("Folder {0} created at {1}", newFolder.Name, newFolder.Path);
}
}
See Also
Concepts
Preparing the Image for Deployment - Windows Server Essentials
Testing the Customer Experience - Windows Server Essentials
Other Resources
Windows Deployment Tools Technical Reference
Windows Server Solutions SDK