共有フォルダーのカスタマイズ

適用対象: Windows Server 2016 Essentials、Windows Server 2012 R2 Essentials、Windows Server 2012 Essentials

既定では、サーバー フォルダーはディスク 0 の最大のデータ パーティションに作成されます。 パートナーは次の手順で、場所をカスタマイズし、追加のサーバー フォルダーを指定できます。

  1. カスタム パーティション構成を使用して、工場出荷時イメージを作成し、sysprep を使用する前に新しい Storage レジストリ キーを作成します。 初期構成 (IC) 中に、記憶域の IC タスクがこのレジストリ キーを確認します。 レジストリ キーが存在する場合、既定のサーバー フォルダーが C:\ServerFolders ディレクトリに作成されます。

    新しい Storage レジストリ キーを作成するには

    1. サーバーで、カーソルを画面の右上隅に移動して、[検索] をクリックします。

    2. 検索ボックスに「regedit」と入力して、[Regedit] アプリケーションをクリックします。

    3. ナビゲーション ウィンドウで、[HKEY_LOCAL_MACHINE]、[SOFTWARE]、[Microsoft] の順に展開します。

    4. [Windows Server] を右クリックし、[新規] をクリックし、[キー] をクリックします。

    5. キーの名前を「Storage」にします。

    6. ナビゲーション ウィンドウで、新しい Storage レジストリ キーを右クリックし、[DWORD (32 ビット) 値] をクリックします。

    7. 文字列の名前を「CreateFoldersOnSystem」にします。

    8. [CreateFoldersOnSystem] を右クリックし、[修正] をクリックします。 [文字列の編集] ダイアログ ボックスが表示されます。

    9. この新しいキーの値を 1 に設定し、[OK] をクリックします。

  2. PostIC.cmd スクリプトを使用して、フォルダーを別の場所に移動するか、追加のフォルダーを作成します。 例については、「例 1: Windows PowerShell を使用して、カスタム フォルダーを作成し、既定のフォルダーを PostIC.cmd から新しい場所に移動する」を参照してください。

  3. Windows Server Solutions SDK を使用して、フォルダーを別の場所に移動するか、追加のフォルダーを作成します。 例については、「例 2: Windows Server Solutions SDK を使用して、カスタム フォルダーを作成し、既存のフォルダーを移動する」を参照してください。

    パートナーは必要に応じてデータ フォルダーをドライブ C に残しておくことができます。これにより、エンド ユーザーまたは再販業者はデータ ドライブのデータ フォルダーのレイアウトを決定できるようになります。

例 1: Windows PowerShell を使用して、カスタム フォルダーを作成し、既定のフォルダーを PostIC.cmd から新しい場所に移動する

  1. 初期構成後のタスクを実行するための PostIC.cmd ファイルの作成」セクションで詳細に説明されているように、初期構成後のタスクを実行するための PostIC.cmd ファイルを作成します。

  2. メモ帳を使用して、customizefolders.ps1 という名前のファイルを C:\Windows\Setup\Scripts フォルダー内に作成し、次の Windows PowerShell® コマンドをファイルに貼り付けます (目的の動作に応じて該当する行のマークを解除します)。

    # 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
    
  3. このスクリプトを実行するために、PostIC.cmd ファイルに次の行を追加します。

    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%
    

例 2: Windows Server Solutions SDK を使用して、カスタム フォルダーを作成し、既存のフォルダーを移動する

作成したコードは、実行可能ファイルとしてコンパイルし、PostIC.cmd ファイルから呼び出すか、インストール済みのアドインから直接呼び出すことができます。

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);
 }
}

参照

イメージの作成とカスタマイズ追加のカスタマイズデプロイのイメージの準備カスタマー エクスペリエンスのテスト