1

Please do not kill me as I am a newbie in Windows system administration ;) started few months ago and so I would kindly need a bit of help:

Basically , I would like to use values issued from a text file as variables: ($Clustername and $NewFSWPath) as described into the piece of PS code below:

$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

Much appreciated. Thank you.

3
  • 1
    What exactly is the question here? How to extract values from a text file? In that case, show the file and tell us what the values to extract are in there. Commented Nov 27, 2020 at 12:45
  • Hi, Thanks. What I need is to replace the values for variables (see the script I copied): $ClusterName = "GLA-CLU" >> Instead this value must be stored and retrieved from an existing text file $NewFSWPath = "\\DC01\SQL-CLU" >> same, Instead this value must be stored in a text file for example TEXT FILE will be: Clustername=GLA-CLU NewFSWPath=\\DC01\SQL-CLU Commented Nov 27, 2020 at 12:57
  • Then have a look at Get-Content, Add-Content and Set-Content Commented Nov 27, 2020 at 13:02

2 Answers 2

1

Thanks, but I managed to sort it out using:

Get-Content 'fswsiteconf.txt' | Foreach-Object{
$var = $_.Split('=')
New-Variable -Name $var[0] -Value $var[1] }

It works for me now using the piece of code indicated above What do you think as a solution?

Thanks for your help.

Sign up to request clarification or add additional context in comments.

Comments

0

Assuming your TEXT_FILE.TXT contains only two lines:

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

then

$Path = "C:\TEXT_FILE.TXT"
$Lines = [System.IO.File]::ReadLines($Path)
$Token = $Lines.Split('=').Trim()
$ClusterName = $Token[1]
$NewFSWPath = $Token[3]

Write-Host $ClusterName
write-host $NewFSWPath

output:

GLA-CLU
\\DC01\SQL-CLU

now you can use your variables $ClusterName, $NewFSWPath in your script as required.

2 Comments

Thanks. I managed to fix it, using: Get-Content 'fswsiteconf.txt' | Foreach-Object{ $var = $_.Split('=') New-Variable -Name $var[0] -Value $var[1] } it works this way. what do you think ?
If it works and fulfils your requirements then that's it, you should use it. your question has solution in here -- > stackoverflow.com/questions/12368142/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.