i'm trying to retrieve some information from SQL server and assign it to a variable:
$query = "select top 1 * from [DB1].[dbo].[table1] where servername='ABC-CDE-SVR1'"
$svrParams = Invoke-Sqlcmd -Query $query -ServerInstance "ADMNSVR"
in this case $svrParams
is a System.Object with a bunch of parameters:
:\> $svrParams
ServerCode : 6
ServerName : ABC-CDE-SVR1
Environment_Abbr : SVR1
ServerWithInstanceFlag : False
EnvironmentTypeCode : 3
ActiveFlag : True
PrimaryDriveLetter : Z:
I'm trying to pull them one by one by assigning to new variables like this:
$backupDrive = $svrParams.PrimaryDriveLetter | Out-String
The issue is that the variable still comes out System.Object type. So when i'm trying to concatenate it with another string, i get 2-line result:
:\> $DBbackupLocation = "$backupDrive" + "\Backup\Data\"
:\> $DBbackupLocation
Z:
\Backup\Data\
Please let me know if there is a way to extract the plain text out of the object. Tried [string] before the variable with the same result.