Neally Bot<\/li>\n<\/ul>","upvoteCount":0,"datePublished":"2022-01-15T02:01:24.000Z","url":"https://community.spiceworks.com/t/need-help-in-optimizing-windows-cluster-health-script/822154/2","author":{"@type":"Person","name":"Neally","url":"https://community.spiceworks.com/u/Neally"}},{"@type":"Answer","text":"it has 195 line code so unable to attach the script<\/p>","upvoteCount":0,"datePublished":"2022-01-15T02:19:41.000Z","url":"https://community.spiceworks.com/t/need-help-in-optimizing-windows-cluster-health-script/822154/3","author":{"@type":"Person","name":"dinu03","url":"https://community.spiceworks.com/u/dinu03"}},{"@type":"Answer","text":"
Please read the link that I posted. \nOnly paste the relevant parts of the script.<\/p>\n
We don’t have to review 200 lines of code to read credentials….<\/p>","upvoteCount":0,"datePublished":"2022-01-15T02:21:15.000Z","url":"https://community.spiceworks.com/t/need-help-in-optimizing-windows-cluster-health-script/822154/4","author":{"@type":"Person","name":"Neally","url":"https://community.spiceworks.com/u/Neally"}},{"@type":"Answer","text":"
Below is Credentials Part\n<\/code><\/pre>\n#=======================================================================\n#Servers and credentials\n$ClusterServers = \"Cluster01\",\n \"Cluster02\", \n \"Cluster03\",\n \"Cluster04\"\n \n$Servers = $ClusterServers\n$Cred = Get-Credential \"domain\\$env:username\"\n \n#=======================================================================\n<\/code><\/pre>","upvoteCount":0,"datePublished":"2022-01-15T02:27:26.000Z","url":"https://community.spiceworks.com/t/need-help-in-optimizing-windows-cluster-health-script/822154/5","author":{"@type":"Person","name":"dinu03","url":"https://community.spiceworks.com/u/dinu03"}},{"@type":"Answer","text":"Dont want to send output in email it has to be in html as windowsclusterhealth.html<\/p>\n
#=======================================================================\n# Looping servers\nForEach ($Server in $Servers) \n{\n $Server = $Server.Trim()\n $DNSCheck = $null\n $DNSCheck = ([System.Net.Dns]::GetHostByName((\"$Server\")))\n \n If($DNSCheck)\n {\n $Server = $DNSCheck.hostname\n \n $ClusRes = $null\n $ClusOwn = $null\n $ClusNod = $null\n $CheckService = $null\n \n Write-Host \"Processing $Server\" -ForegroundColor Green\n \n # Check if cluster service exist\n Try\n {\n $CheckService = Invoke-Command -ComputerName $Server -ErrorAction Stop -ScriptBlock{Get-Service -Name ClusSvc } -Credential $Cred\n }\n Catch \n {\n $_.Exception.Message\n Continue\n }\n \n If(!$CheckService)\n {\n Continue\n }\n Else\n {\n Try\n {\n #Checking cluster recources:\"\n $ClusRes = Invoke-Command -ComputerName $Server -ErrorAction Stop -ScriptBlock{Get-ClusterResource | Select-Object ownernode,iscoreresource,name,resourcetype,state,characteristics | Sort-Object IsCoreResource -Descending } -Credential $Cred | Select-Object * -ExcludeProperty PSComputerName,RunspaceId,PSShowComputerName\n $output += '<p>'\n $output += '<h4>Cluster recources:</h4>'\n $output += '<p>'\n $output += Create-HTMLTable $ClusRes\n $output += '</p>'\n \n #Checking cluster owner nodes:\"\n $ClusOwn = Invoke-Command -ComputerName $Server -ErrorAction Stop -ScriptBlock{Get-ClusterGroup | Select-Object cluster,Iscoregroup,ownernode,state,name} -Credential $Cred | Select-Object * -ExcludeProperty PSComputerName,RunspaceId,PSShowComputerName\n $output += '<p>'\n $output += '<h4>Cluster owner nodes:</h4>'\n $output += '<p>'\n $output += Create-HTMLTable $ClusOwn\n $output += '</p>'\n \n #Checking cluster nodes:\"\n $ClusNod = Invoke-Command -ComputerName $Server -ErrorAction Stop -ScriptBlock{Get-ClusterNode | Select-Object cluster,name,state,nodeweight} -Credential $Cred | Select-Object * -ExcludeProperty PSComputerName,RunspaceId,PSShowComputerName\n $output += '<p>'\n $output += '<h4>Cluster nodes:</4>'\n $output += '<p>'\n $output += Create-HTMLTable $ClusNod\n $output += '</p>'\n \n # End\n $output += '</body></html>'\n $output = $output | Out-String\n Break\n }\n Catch\n {\n $_.Exception.Message\n Continue\n }\n }\n }\n}\n \n#=======================================================================\n#Continue if report was created\nIf(!($ClusRes -and $ClusOwn -and $ClusNod))\n{\n Write-Warning 'Failed to create report'\n}\nElse\n{\n # Use loop to do 5 attempts in case of failure\n $n=1\n do\n {\n $ErrorMessage = $null\n Write-Host Attempt $n - Sending email\n \n #Send email\n Send-MailMessage -ErrorAction SilentlyContinue -ErrorVariable SendError -To $emailTo -Subject $subject -BodyAsHtml $output -SmtpServer $smtpServer -port $port -From $emailFrom -Priority $priority\n \n $ErrorMessage = $SendError.exception.message\n If($ErrorMessage)\n {\n Write-Warning $ErrorMessage\n Start-Sleep -Seconds 5\n }\n \n $n++\n } \n until ( $SendError.exception.message -eq $null -or $n -eq 6 )\n \n If($SendError.exception.message -eq $null)\n {\n Write-Host `nEmail has been sent to $emailto -ForegroundColor Yellow\n }\n Else\n {\n Write-Host `nFailed to sent email to $emailto -ForegroundColor Yellow\n }\n}\n#=======================================================================\n \npause\n<\/code><\/pre>","upvoteCount":0,"datePublished":"2022-01-15T02:30:33.000Z","url":"https://community.spiceworks.com/t/need-help-in-optimizing-windows-cluster-health-script/822154/6","author":{"@type":"Person","name":"dinu03","url":"https://community.spiceworks.com/u/dinu03"}},{"@type":"Answer","text":"Any update guys ?<\/p>","upvoteCount":0,"datePublished":"2022-01-17T20:55:09.000Z","url":"https://community.spiceworks.com/t/need-help-in-optimizing-windows-cluster-health-script/822154/7","author":{"@type":"Person","name":"dinu03","url":"https://community.spiceworks.com/u/dinu03"}}]}}
Neally
(Neally)
January 15, 2022, 2:01am
2
There is no script?
What have you tried to get the credentials?
What have you tried to get the HTML output?
What exactly is the WinRM error? What have you tried to fix it?
We’re happy to help but not a script writing service.
If you post code, please use the ‘Insert Code’ button. Please and thank you!
Hi, and welcome to the PowerShell forum!
Don’t apologize for being a “noob” or “newbie” or “n00b.” There’s just no need – nobody will think you’re stupid, and the forums are all about asking questions. Just ask!
Use a descriptive subject. Don’t say “Need help” or “PowerShell Help”, actually summarize what the problem is. It helps the rest of us keep track of which problem is which.
Don’t post massive scripts. We’re all volunteers and we don’t have time to read all that, nor will we copy…