1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

WindowsServer2016から同2022にファイルサーバを移行した話

Last updated at Posted at 2023-11-15

ワークグループ環境にある WindowsServer 2016 を WindowsServer 2022 に移行しました。
実施メモを共有します。

いずれも新サーバ側のオペレーションです。
PowerShell は管理者モードで起動して下さい。

ファイルサーバの構築

ファイルサービスをインストール

Install-WindowsFeature FS-FileServer

共有フォルダ作成と共有の設定

mkdir E:\FooBar_Share
New-SmbShare -Name "FooBar_Share" -Path "E:\FooBar_Share" -FullAccess "Everyone"

旧サーバからファイルをコピー

xxx.xxx.xxx.xxxは旧サーバのIPアドレスです。

旧サーバの共有ディスクをマウント

net use \\xxx.xxx.xxx.xxx /user:username "password"

ファイルをACL付きでコピー

robocopy \\xxx.xxx.xxx.xxx\FooBar_Share E:\FooBar_Share /B /COPYALL /DCOPY:DAT /MIR /R:0 /W:0 /NP /LOG+:D:\robocopy.txt

アクセス権の付け替え

ワークグループ環境の場合、ACL付きでコピーすると、コピー先では「不明なアカウント」としてSIDが表示されます。
image.png
SIDは、UNIXでいうUID/GIDみたいなもので、NTFSのアクセス許可はSIDに紐づいています。
これを、新サーバで作成したローカルアカウント(ユーザーおよびグループ)に付け替えます。

さすがに手作業で付け替えるのは有り得ないので、誰かがPowerShellかなにかで便利ツールを作っているだろうと探したところ、マイクロソフトの SubInACL というコマンドラインツールを見つけました。
結構有名なツールらしく、出自からも安心感があるのですが、すでに配布は終了していたため、Webアーカイブからダウンロードします。

ACLのSIDを既存アカウントにマッピングするには、

subinacl /file           E:\FooBar_Share\  /replace=S-1-5-21-9999...9999=Example_Users
subinacl /subdirectories E:\FooBar_Share\* /replace=S-1-5-21-9999...9999=Example_Users

みたいな感じで指定しますが、細かいことはsubinacl /helpで確認して下さい。
最新のOSで動くか不安でしたが、問題なく付け替えできました。

付け替えるには、SIDがどのアカウントを差していたか知る必要があります。
次のコマンドで確認して下さい。

SIDとグループ名の対応表を得る
Get-WmiObject Win32_Group | Format-Table Caption,SID
SIDとユーザー名の対応表を得る
Get-WmiObject Win32_UserAccount | Format-Table Caption, Description, SID

おまけ

ついでにローカルアカウントの棚卸をしておきます。

アカウントの一覧を最終ログオン日時でソートします。

旧サーバで実行
Get-LocalUser | Sort-Object -Property LastLogon | Format-Table -Property Name,FullName,LastLogon

長期間ログオン実績のないアカウントを除き新サーバに追加します。

新サーバで実行
New-LocalUser -Name yamada.taro -FullName "山田 太郎" -Description "Desc" -PasswordNeverExpires -Password (ConvertTo-SecureString "パスワード" -AsPlainText -Force)
Add-LocalGroupMember -Group Users -Member yamada.taro
1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?