Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 407
  • Last Modified:

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
0
bibi92
Asked:
bibi92
  • 2
  • 2
1 Solution
 
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
 
SubsunCommented:
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
 
bibi92Author Commented:
Thanks regards bibi
0

Featured Post

Free Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now