powershell get sql virtual

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
bibi92Asked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
SubsunConnect With a Mentor Commented:
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
 
TempDBACommented:
Not clear with your question. Please explain a bit more.
0
 
bibi92Author Commented:
I search how I can modify the function for display only test\test12 and not
ServerInstance
--------------
test\test12
Thanks
bibi
0
 
SubsunCommented:
Does this work?
Get-ClusterSQL Cluster | Select -ExpandProperty ServerInstance
0
 
bibi92Author Commented:
Thanks regards bibi
0
All Courses

From novice to tech pro — start learning today.