Your command will not work because since sqlcmd is not a Cmdlet. This means sqlcmd will only return text, instead of a PowerShell object.
To solve this, you should instead use a Cmdlet from a module like the Microsoft official sqlserver or the community made dbatools.
sqlserver:
# Run this once to get the module if you don't already have it (requires PowerShell Get)
Install-Module sqlserver
# Invoke this every time you begin a new instance (new terminal window or new script)
Import-Module sqlserver
Invoke-SqlCmd -ServerInstance 'yourserver\instance' -Query 'SELECT * FROM whatever' |
Select-Object -Property ColumnNameHere
dbatools:
Disclaimer: I have made non-code contributions to dbatools in the past but I am not officially affiliated with them
# Run this once to get the module if you don't already have it (requires PowerShell Get)
Install-Module dbatools
# Invoke this every time you begin a new instance (new terminal window or new script)
Import-Module dbatools
Invoke-DbaQuery -SqlInstance 'yourserver\instance' -Query 'SELECT * FROM whatever' |
Select-Object -Property ColumnNameHere
sqlcmdas the data it returns, I have found it to be hard to work with. I switched toInvoke-sqlcmdfromsqlserverpowershell module. learn.microsoft.com/en-us/sql/powershell/…Invoke-SqlCmdfromsqlserverorInvoke-DbaQueryfromdbatools(I personally recommenddbatools)