Solved

powershell get sql virtual

Posted on 2013-01-03
5
394 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
  • 2
  • 2
5 Comments
 
LVL 25

Expert Comment

by:TempDBA
Comment Utility
Not clear with your question. Please explain a bit more.
0
 

Author Comment

by:bibi92
Comment Utility
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
Comment Utility
Does this work?
Get-ClusterSQL Cluster | Select -ExpandProperty ServerInstance
0
 
LVL 40

Accepted Solution

by:
Subsun earned 500 total points
Comment Utility
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
Comment Utility
Thanks regards bibi
0

Featured Post

Control application downtime with dependency maps

Visualize the interdependencies between application components better with Applications Manager's automated application discovery and dependency mapping feature. Resolve performance issues faster by quickly isolating problematic components.

Join & Write a Comment

This script checks a path to see if a folder exists. If the folder does exist you will get output "The folder has previously been created. No action taken" If not it will create the folder. Then adds one user modify permission to the folder. It …
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
This video discusses moving either the default database or any database to a new volume.
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

772 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now