PowerShellによるDFSレプリケーショングループの自動作成

10614 ワード

実行環境:Windows Server 2012 R 2
 
DFSレプリケーションの概要
DFSレプリケーショングループPowerShellスクリプトコマンド
このスクリプトは、DFS依存ドメインであることに注意してください.このサーバがドメイン管理上に存在しないか、ドメイン内に存在しない場合は、エラーが発生します.
このスクリプトは、ドメイン内の任意のサーバで実行できます.
スクリプトは、デフォルトの計画で使用されるインタリーブ型トポロジーを作成します.
レプリケーション・グループが存在するかどうかを検出すると、レプリケーション・グループ・タイムズ・エラーを表示する場合があります.
 
#   DFS  
# author:lttr
# date:2019-08-09
# eg. # C:\dfsr.ps1 -Domain "test.to" -DfsN "DFSN01" -GroupName "RG01" -FolderName "dfs" -ShareFolderPhysicalPath "C:\DFShare\dfs" -SourceComputerName "WIN01" -servers "WIN02","WIN03","WIN04" [CmdletBinding()] param ( # [Parameter(Mandatory=$true,Position=0)][string]$Domain, # DFS [Parameter(Mandatory=$true,Position=1)][string]$DfsN, # [Parameter(Mandatory=$true,Position=2)][string]$GroupName, # [Parameter(Mandatory=$true,Position=3)][string]$FolderName, # [Parameter(Mandatory=$true,Position=4)][string]$ShareFolderPhysicalPath, # DFS [Parameter(Mandatory=$true,Position=6)][String[]]$servers ) # function SET-Share($DriveLetter,$ShareFolderPhysicalPath,$ShareFolderNetworkPath,$Server){ if(!(Test-Path \\$Server\$DriveLetter$\$ShareFolderPhysicalPath)){ $null = New-Item -Path \\$Server\$DriveLetter$\$ShareFolderPhysicalPath -type directory -Force } $Shares = [WMICLASS]"\\$Server\root\cimv2:WIN32_Share" $null = $Shares.Create($DriveLetter+":\"+$ShareFolderPhysicalPath,$ShareFolderNetworkPath,0) } try { # if(Get-DfsnFolderTarget -Path "\\$Domain\$DfsN\$FolderName" -ErrorAction SilentlyContinue) { Write-Host "DFS [$GroupName] !" -ForegroundColor Red }else{ # $null = New-DfsReplicationGroup -GroupName $GroupName | New-DfsReplicatedFolder -GroupName $GroupName -FolderName $FolderName -DfsnPath "\\$Domain\$DfsN\$FolderName" -WarningAction silentlyContinue | Add-DfsrMember -ComputerName $servers # for($i=0;$i -le $servers.Length-1;$i++){ for($j=$i+1;$j -le $servers.Length-1;$j++){ $null = Add-DfsrConnection -GroupName $GroupName -SourceComputerName $servers[$i] -DestinationComputerName $servers[$j] } } foreach ($server in $servers) { # $null = New-DfsnFolderTarget -Path "\\$Domain\$DfsN\$FolderName" -TargetPath "\\$server.$Domain\$FolderName" -State "Online" -ReferralPriorityClass "sitecostnormal" # SET-Share ($ShareFolderPhysicalPath -split ":")[0] ($ShareFolderPhysicalPath -split ":\\")[-1] $FolderName $server # $null = Set-DfsrMembership -GroupName $GroupName -FolderName $FolderName -ComputerName $server -PrimaryMember $True -ContentPath $ShareFolderPhysicalPath -Force } # DFSR Update-DfsrConfigurationFromAD -ComputerName $servers # if(Get-DfsnFolderTarget -Path "\\$Domain\$DfsN\$FolderName" -ErrorAction SilentlyContinue) { Write-Host " DFS [$GroupName] !" -ForegroundColor Green }else{ Write-Host " DFS [$GroupName] !" -ForegroundColor Red } } } catch { Write-Host " DFS [$GroupName] !" -ForegroundColor Red }