none
Need a small help in a Power shell script RRS feed

  • Question

  • Hi There,

    I am using below powershell code to fetch the TCP port number for SQL instances running on remote server.

    $namespace = gwmi -computername (get-content "C:\Users\Public\Poweshell_Work\Drivespace\DB-Status\serverlist.txt") -Namespace "root\microsoft\sqlserver" -Class "__Namespace" -Filter "name like 'ComputerManagement%'" | sort desc | select -ExpandProperty name -First 1

    $variable = Get-WmiObject -computername (get-content "C:\Users\Public\Poweshell_Work\Drivespace\DB-Status\serverlist.txt") -Namespace "root\microsoft\SqlServer\$namespace" -Class ServerNetworkProtocolProperty | where{$_.IPAddressName -eq 'IPAll' -and $_.propertystrval -ne ''}

    $port = $variable | select PropertyStrVal | where{$_.propertystrval -ne ''}

    -----Its running fine and giving the output as below

    @{PropertyStrVal=60704} :- where 60704 is the port number

    But want to know how to get only number (60704) instaed of string part.

    I would like port variable should store only 60704 i.e. $port = 60704

    Thanks in Advance

    Friday, September 15, 2017 2:09 AM

Answers