Eldo issac
asked on
Comparing in Powershell
Hello Guys,
I have written the following code for getting the cluster status:
The input in the Server.txt file will be like this:
The output of the code will be:
The thing is I want this code to even check if the entries in the __SERVER column is not same. I mean there shouldn't be a single machine name for two or more logical instances. If that is the case a mail should be triggered. I'm not able to figure out how the looping constructs should be in this case conceptually.
Kindly give your inputs and edits.
I have written the following code for getting the cluster status:
cls
$computers = Get-Content D:\Abhi\Server.txt
foreach ($line in $computers)
{
Get-WmiObject -Class win32_bios -cn $line | Select __Server, @{N="InstanceName";E={$line}}
}
The input in the Server.txt file will be like this:
LogicalName1
LogicalName2
LogicalName3
LogicalName4
The output of the code will be:
__SERVER InstanceName
-------- ------------
MachineName1 LogicalName1
MachineName2 LogicalName2
MachineName3 LogicalName3
MachineName4 LogicalName4
The thing is I want this code to even check if the entries in the __SERVER column is not same. I mean there shouldn't be a single machine name for two or more logical instances. If that is the case a mail should be triggered. I'm not able to figure out how the looping constructs should be in this case conceptually.
Kindly give your inputs and edits.
ASKER
Hello oBdA,
Thanks for your reply. The comparison is working fine. Only thing is $Result is coming like this:
I need the Instance name as the one mentioned in input txt file.
Kindly suggest an edit for this.
Thanks for your reply. The comparison is working fine. Only thing is $Result is coming like this:
__SERVER InstanceName
-------- ------------
M1 \\M1\root\cimv2:Win32_BIOS.Name="Def a...
I need the Instance name as the one mentioned in input txt file.
Kindly suggest an edit for this.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Hello oBdA,
Thank you very much for your code, it works perfectly. Just one more favor, in our environment we also have 3 SQL instances running on 2 machines. Like this:
Is there an edit that u can suggest in your code, so that I can do monitoring on this cluster as well. Meaning, in this all the three logical instances shouldn't be online on a single machine.
Kindly give your comments.
Thank you very much for your code, it works perfectly. Just one more favor, in our environment we also have 3 SQL instances running on 2 machines. Like this:
__SERVER InstanceName
-------- ------------
MachineName1 LogicalName1
MachineName1 LogicalName2
MachineName2 LogicalName3
Is there an edit that u can suggest in your code, so that I can do monitoring on this cluster as well. Meaning, in this all the three logical instances shouldn't be online on a single machine.
Kindly give your comments.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Open in new window