Skip to content

Instantly share code, notes, and snippets.

@speaktech-account
Created October 27, 2018 10:39
Show Gist options
  • Save speaktech-account/0ff45190881fb3d3ea4fe0fb514993ea to your computer and use it in GitHub Desktop.
Save speaktech-account/0ff45190881fb3d3ea4fe0fb514993ea to your computer and use it in GitHub Desktop.
How to export / import Windows share permission settings ref: https://qiita.com/speaktech/items/2785e989557be4635700
# 例1) ディレクトリの移動
PS D:\Tmp> Set-Location -Path D:\Tmp\share
PS D:\Tmp\share>
# 例2) カレントディレクトリのパスを出力
PS D:\Tmp\share> Get-Location
Path
----
D:\Tmp\share
# 例3) カレントディレクトリのオブジェクトを変数に代入し、メンバーへアクセス
PS D:\Tmp\share> $pwd = Get-Location
PS D:\Tmp\share> $pwd.Path
D:\Tmp\share
# 例4)共有アクセス権設定を出力
PS D:\Tmp> Get-SmbShare -Special $false
Name ScopeName Path Description
---- --------- ---- -----------
share * D:\tmp\share
Users * C:\Users
# 例5)Dドライブ上の共有アクセス権設定のみ出力
PS D:\Tmp> Get-SmbShare -Special $false | ? { $_.Path -like "D:\*" }
Name ScopeName Path Description
---- --------- ---- -----------
share * D:\tmp\share
# 例6)Dドライブ上の共有アクセス権設定をXmlファイルへエクスポート
PS D:\Tmp> $shareFolder = Get-SmbShare -Special $false | ? { $_.Path -like "D:\*" }
PS D:\Tmp> $shareFolder | Export-Clixml -Path D:\Tmp\SmbShare.xml
# 例7)Dドライブ上の共有アクセス権設定をXmlファイルからインポート
PS D:\Tmp> Import-Clixml -Path D:\Tmp\SmbShare.xml
Name ScopeName Path Description
---- --------- ---- -----------
share * D:\tmp\share
# 例8)インポートした共有アクセス権設定を詳細に出力
PS D:\Tmp> Import-Clixml -Path D:\Tmp\SmbShare.xml | Get-SmbShareAccess
Name ScopeName AccountName AccessControlType AccessRight
---- --------- ----------- ----------------- -----------
share * Everyone Allow Full
# 例9)インポートした共有アクセス権設定を反映
PS D:\Tmp> Import-Clixml -Path D:\Tmp\SmbShare.xml | New-SmbShare
Name ScopeName Path Description
---- --------- ---- -----------
share * D:\Tmp\share
# 例10)共有アクセス権設定を詳細に出力
PS D:\Tmp> Get-SmbShare -Special $false | Get-SmbShareAccess
Name ScopeName AccountName AccessControlType AccessRight
---- --------- ----------- ----------------- -----------
Users * BUILTIN\Administrators Allow Full
Users * Everyone Allow Full
share * Everyone       Allow Full
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment