powershell - 检查存在的路径和 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 很陌生
谢谢你。
解决方案
推荐阅读
- azure - Azure 应用程序网关未在后端池中显示来自其他 VNet 的 VM
- java - 如何在 swagger yaml 文件中使用属性定义 java 枚举?
- java - 如何在java中将项目与文件分开
- .net - 在 Docker 映像中使用“dotnet”测试 Nuget 身份验证凭据
- celery - Celery & SQS 指数重试策略
- html - (Css)表格对齐中的表格:我该如何解决这个问题?
- jenkins - Jenkinsfile 签出不同的仓库并更新文件
- python - 使用 AssertEqual 函数时简单的硒测试失败
- kotlin - 使用对象映射器(在 kotlin 中)从 S3 读取没有键名的 json 文件(大约 180 MB)到数据类
- google-chrome - 生成灯塔报告时可以更改用户代理吗?