首页 > 解决方案 > 检查存在的路径和 IF...Test-path PS

问题描述

实际文件配置: clustername=GLA-CLU2

fswmain=\DC01\SQL-FSW1

fswdr=\DC01\SQL-FSW2

我的实际脚本:

### BEGIN OF Passing as Variables, the configuration values separated with '=' and Retrieved from the indicated TXT file:
Get-Content '.\FSW_pathConf.txt' | Foreach-Object {
   $Vconfvalue = $_.Split('=')
   New-Variable -Name $Vconfvalue[0] -Value $Vconfvalue[1] }
### END OF Passing values as Variables
### Testing Each Path defined into configuration file
$currentfsw = Get-clusterresource -cluster $clustername | where-object {$_.ResourceType -like "File Share Witness"} | get-clusterparameter -Name "sharepath" | Select Value
Write-Host "`r"
Write-Host "the current file share witness configuration On Cluster: '$($Clustername)' is: '$($currentfsw)' " 

if($currentfsw -is "$fswmain") {Test-Path -Path "$fswmain" -IsValid}

else{Set-ClusterQuorum -Cluster $Clustername -NodeAndFileShareMajority "$fswdr"}


if($currentfsw -is "$fswdr") { Test-Path -Path "$fswdr" -IsValid}

else{Set-ClusterQuorum -Cluster $Clustername -NodeAndFileShareMajority "$fswmain" }

我想做什么,我正在努力:

如果 $fswmain 有效则返回“OK,current fsw is working”并在此处停止此脚本

如果不是 $currentfsw 无效,则运行以下命令以切换到 $fswdr

然后,仅当 $currentfsw 不等于 $fswmain

如果 $fswdr 有效则返回“OK,current fsw is working”并在此处停止此脚本

如果没有运行下面的命令切换到 $fswmain

任何人都可以在这里带来一些帮助吗?我对 powershell 和 sysadmin 很陌生

谢谢你。

标签: powershellcluster-computingpowershell-2.0sysadmin

解决方案


推荐阅读