Is there any way to get the "Get-ItemPropertyValue" output separated by semicolon each element and the whole output between quoutes?
For example:
Get-ItemPropertyValue -Path 'HKLM:\SYSTEM\CurrentControlSet\Services\LanManServer\Parameters' -Name NullSessionPipes
Now the output is:
netlogon samr lsarpc
The desired output is:
"netlogon,samr,lsarpc"
I tried the backtick escape character, but unfortunately no luck.
Many thanks for help!
Start by using the -join
operator on the desired string values to create a string like netlogon,samr,lsarpc
:
$values = Get-ItemPropertyValue -Path 'HKLM:\SYSTEM\CurrentControlSet\Services\LanManServer\Parameters' -Name NullSessionPipes |Where-Object { $_ <# this will remove empty values #> }
$string = $values -join ','
Now we just need to embed it in a string surrounded by literal "
's, my preference would be to use the -f
operator:
'"{0}"' -f $string