You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Set-DFSnRoot无法设置映射驱动器引用路径,需激活指定DFS目标

DFS文件夹目标激活与优先级调整问题解决

需求说明

在Windows Server中创建了映射驱动器,使用DFS路径\\platdc.local\DFSPLAT2\DBBSETUP2-Plat,需要完成两项操作:

  • 检查该DFS路径当前活动的引用路径
  • 若PlatDC-PrimaryFileServer未处于活动状态,通过PowerShell脚本将其激活

尝试的无效代码

$referralPath = "\\Plat2-Secondary\DBBSETUP2-Plat"

$referralPriority = 1

$timeToLive = 300

$dfsFolderTarget = Get-DfsnFolderTarget -Path "\\platdc.local\DFSPLAT2\DBBSETUP2-Plat"

$referral = @{
    Path = $referralPath
    ReferralPriority = $referralPriority
}

$dfsFolderTarget.ReferralPriority = $referral

Set-DfsnFolderTarget -InputObject $dfsFolderTarget -TimeToLive $timeToLive

问题分析

原代码错误地将哈希表赋值给ReferralPriority属性,该属性仅接受数值类型;同时未准确定位到PlatDC-PrimaryFileServer对应的文件夹目标对象,导致操作无效。

修正后的脚本

1. 检查当前DFS活动引用路径

# 获取目标DFS文件夹的所有关联目标
$dfsTargets = Get-DfsnFolderTarget -Path "\\platdc.local\DFSPLAT2\DBBSETUP2-Plat"

# 输出所有目标的状态、优先级信息
Write-Host "当前DFS文件夹目标详情:"
$dfsTargets | Select-Object Path, State, ReferralPriorityClass, ReferralPriorityRank | Format-Table -AutoSize

2. 激活PlatDC-PrimaryFileServer并设置优先级

# 定义关键参数
$primaryTargetPath = "\\PlatDC-PrimaryFileServer\DBBSETUP2-Plat"
$dfsRootPath = "\\platdc.local\DFSPLAT2\DBBSETUP2-Plat"
$ttlValue = 300

# 定位目标服务器对应的DFS文件夹目标
$primaryTarget = Get-DfsnFolderTarget -Path $dfsRootPath | Where-Object { $_.Path -eq $primaryTargetPath }

if ($primaryTarget) {
    # 若目标处于离线状态,先设置为在线
    if ($primaryTarget.State -ne "Online") {
        Set-DfsnFolderTarget -Path $dfsRootPath -TargetPath $primaryTargetPath -State Online
    }

    # 设置为最高优先级(High类+Rank1)
    Set-DfsnFolderTarget -Path $dfsRootPath -TargetPath $primaryTargetPath `
        -ReferralPriorityClass High -ReferralPriorityRank 1 -TimeToLive $ttlValue

    Write-Host "已成功激活PlatDC-PrimaryFileServer并设置为高优先级"
} else {
    Write-Host "未找到PlatDC-PrimaryFileServer对应的DFS文件夹目标"
}

修正要点

  • 直接通过Set-DfsnFolderTarget命令指定目标路径与参数,避免对象属性赋值错误
  • 使用ReferralPriorityClass(优先级类别)+ReferralPriorityRank(优先级排名)组合设置优先级,High类+Rank1为最高优先级
  • 先检查目标状态,确保离线目标先切换为在线
  • 精准筛选目标服务器对应的文件夹目标,避免误操作其他节点

内容的提问来源于stack exchange,提问作者Shritej Murmadkar

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.31 04:18:23