Solved

powershell get sql virtual

Posted on 2013-01-03
5
398 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
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

Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

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

This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
The Nano Server Image Builder helps you create a custom Nano Server image and bootable USB media with the aid of a graphical interface. Based on the inputs you provide, it generates images for deployment and creates reusable PowerShell scripts that …
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

820 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