Running the following sqlcmd in PowerShell:
$unassignedCnt = sqlcmd -W -k 1 -S MSSQLSERVER -E -Q "SET NoCount ON; SELECT Count(DISTINCT SP.SubnetKey) AS 'UnassignedCount' FROM [Control].[dbo].[Subnet] AS SP Left OUTER JOIN [Control].[rw_current].[QIP_Subnet] AS Q ON SP.KeyHash = Q.__key_Hash; SET NoCount OFF; "
Write-Host $unassignedCnt
This returns the following formatted result:
UnassignedCount --------------- 1
I would like to have only:
1
Can I achieve this through the SQL command or do I need to post process the result? If so what's the simplest approach?
Write-Host $unassignedCnt->Write-Host $unassignedCnt.UnassignedCount$unassignedCnt.GetType().FullName?$unassignedCnt->$unassignedCnt[0].UnassignedCount. Adjust the index if the first item is not the one you want.