Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
从文本文件中检索值并将其用作PowerShell中的变量_Powershell_Powershell 2.0_Powershell 3.0_Sysadmin - Fatal编程技术网

从文本文件中检索值并将其用作PowerShell中的变量

从文本文件中检索值并将其用作PowerShell中的变量,powershell,powershell-2.0,powershell-3.0,sysadmin,Powershell,Powershell 2.0,Powershell 3.0,Sysadmin,请不要杀我,因为我是Windows系统管理的新手;)几个月前开始,因此我需要一些帮助: 基本上,我希望使用从文本文件发布的值作为变量: ($Clustername和$NewFSWPath)如以下PS代码所述: $ClusterName = "GLA-CLU" $NewFSWPath = "\\DC01\SQL-CLU" #As quorum file share witness is a cluster core resource, the only

请不要杀我,因为我是Windows系统管理的新手;)几个月前开始,因此我需要一些帮助:

基本上,我希望使用从文本文件发布的值作为变量: ($Clustername和$NewFSWPath)如以下PS代码所述:

$ClusterName = "GLA-CLU"
$NewFSWPath = "\\DC01\SQL-CLU"


#As quorum file share witness is a cluster core resource, the only way to remove an existing FSW in PS is to switch the cluster to node majority. It will remove the existing Cluster File Share Witness from the chosen cluster
Set-ClusterQuorum -Cluster $ClusterName -NodeMajority
#Set New Quorum File Share Witness for the cluster
#Add-ADGroupMember $FileShareSecurityGroup -Members "$ClusterName"
$t = $host.ui.RawUI.ForegroundColor
$host.ui.RawUI.ForegroundColor = "Yellow"
Write-Output "Setting A New Location for File Share Witness on cluster: '$($ClusterName)':"
Write-Host "`r"
$host.ui.RawUI.ForegroundColor = $t
Set-ClusterQuorum -Cluster $ClusterName -NodeAndFileShareMajority $NewFSWPath
Write-Host "`r"
$host.ui.RawUI.ForegroundColor = $t
$host.ui.RawUI.ForegroundColor = "Yellow"
Write-Output "Checking New File Share Witness Availablity:"
$host.ui.RawUI.ForegroundColor = $t
Get-clusterresource -cluster $ClusterName | where-object {$_.ResourceType -like "File Share Witness"} | get-clusterparameter
非常感谢。
谢谢。

假设您的TEXT\u FILE.TXT只包含两行:

Clustername = GLA-CLU
NewFSWPath = \\DC01\SQL-CLU
然后

输出:

GLA-CLU
\\DC01\SQL-CLU

现在,您可以根据需要在脚本中使用变量
$ClusterName
$NewFSWPath

假设您的TEXT_FILE.TXT只包含两行:

Clustername = GLA-CLU
NewFSWPath = \\DC01\SQL-CLU
然后

输出:

GLA-CLU
\\DC01\SQL-CLU

现在,您可以根据需要在脚本中使用变量
$ClusterName
$NewFSWPath

谢谢,但我已使用以下方法对其进行了排序:

Get-Content 'fswsiteconf.txt' | Foreach-Object{
$var = $_.Split('=')
New-Variable -Name $var[0] -Value $var[1] }
现在使用上面提到的代码对我来说是可行的 你认为解决办法是什么


谢谢你的帮助。

谢谢,但我还是用以下方法解决了问题:

Get-Content 'fswsiteconf.txt' | Foreach-Object{
$var = $_.Split('=')
New-Variable -Name $var[0] -Value $var[1] }
现在使用上面提到的代码对我来说是可行的 你认为解决办法是什么


谢谢你的帮助。

这里的问题到底是什么?如何从文本文件中提取值?在这种情况下,显示文件并告诉我们要提取的值在那里。嗨,谢谢。我需要的是替换变量的值(请参阅我复制的脚本):$ClusterName=“GLA-CLU”>>相反,必须存储此值并从现有文本文件$NewFSWPath=“\\DC01\SQL-CLU”>>中检索此值,相反,此值必须存储在文本文件中,例如文本文件为:Clustername=GLA-CLU NewFSWPath=\\DC01\SQL CLU然后看一看,这里的问题到底是什么?如何从文本文件中提取值?在这种情况下,显示文件并告诉我们要提取的值在那里。嗨,谢谢。我需要的是替换变量的值(请参阅我复制的脚本):$ClusterName=“GLA-CLU”>>相反,必须存储此值并从现有文本文件$NewFSWPath=“\\DC01\SQL-CLU”>>中检索此值,相反,此值必须存储在文本文件中,例如文本文件为:Clustername=GLA-CLU NewFSWPath=\\DC01\SQL CLU然后查看,谢谢。我设法修复了它,使用:Get Content'fswsiteconf.txt'| Foreach对象{$var=$\.Split('=')新变量-Name$var[0]-Value$var[1]}它是这样工作的。你认为呢?如果它能工作并满足你的需求,那么就是它,你应该使用它。您的问题在这里有答案-->谢谢。我设法修复了它,使用:Get Content'fswsiteconf.txt'| Foreach对象{$var=$\.Split('=')新变量-Name$var[0]-Value$var[1]}它是这样工作的。你认为呢?如果它能工作并满足你的需求,那么就是它,你应该使用它。您的问题在这里有解决方案-->