Solved

powershell get sql virtual

Posted on 2013-01-03
5
402 Views
Last Modified: 2013-01-04
Hello,

When I execute this powershell function :

function Get-ClusterSQL
{
    param($cluster)
   
    gwmi -class "MSCluster_Resource" -namespace "root\mscluster" -computername $cluster  | where {$_.type -eq "SQL Server"} | Select @{n='VirtualServerName';e={$_.PrivateProperties.VirtualServerName}}, @{n='InstanceName';e={$_.PrivateProperties.InstanceName}}, `
    @{n='ServerInstance';e={("{0}\{1}" -f $_.PrivateProperties.VirtualServerName,$_.PrivateProperties.InstanceName).TrimEnd('\')}}
   
}

The result is

VirtualServerName                       InstanceName                            ServerInstance
-----------------                       ------------                            --------------
Test                                    Test12                                  Test\Test12

How can I modify the function for having the result test\test12?

Thanks

Regards

bibi
0
Comment
Question by:bibi92
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 25

Expert Comment

by:TempDBA
ID: 38741186
Not clear with your question. Please explain a bit more.
0
 

Author Comment

by:bibi92
ID: 38741202
I search how I can modify the function for display only test\test12 and not
ServerInstance
--------------
test\test12
Thanks
bibi
0
 
LVL 40

Expert Comment

by:Subsun
ID: 38741711
Does this work?
Get-ClusterSQL Cluster | Select -ExpandProperty ServerInstance
0
 
LVL 40

Accepted Solution

by:
Subsun earned 500 total points
ID: 38741775
Or if you want to modify the function itself.. Then you can simply add
| Select -ExpandProperty ServerInstance at the end of gwmi command in function..
function Get-ClusterSQL
{
    param($cluster)
   
    gwmi -class "MSCluster_Resource" -namespace "root\mscluster" -computername $cluster  | where {$_.type -eq "SQL Server"} | Select `
    @{n='ServerInstance';e={("{0}\{1}" -f $_.PrivateProperties.VirtualServerName,$_.PrivateProperties.InstanceName).TrimEnd('\')}} | 
    Select -ExpandProperty ServerInstance
   
}

Open in new window

0
 

Author Closing Comment

by:bibi92
ID: 38743184
Thanks regards bibi
0

Featured Post

Are You Headed to Black Hat USA 2017?

Getting ready for Black Hat next week? Kick things off with the WatchGuard Badge Challenge and test your puzzle and cipher skills. Do you have what it takes to earn our limited edition Firebox Badge? Get started today - https://crimsonthorn.net

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A recent project that involved parsing Tableau Desktop and Server log files to extract reusable user queries for use in other systems. I chose to use PowerShell to gather the data, and SharePoint to present it...
In previous parts of this Nano Server deployment series, we learned how to create, deploy and configure Nano Server as a Hyper-V host. In this part, we will look for a clustering option. We will create a Hyper-V cluster of 3 Nano Server host nodes w…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question