Page 1 of 1

prepend each object

Posted: 2021-Dec-20, 2:48 pm
by qwerty
I'm relatively new to powershell, so forgive me for what is likely a simple question. Is there a way to prepend text to individual objects like this:

Code: Select all

$objects = systeminfo.exe /FO CSV 2>&1| ConvertFrom-Csv; $objects.'Total Physical Memory'; $objects.'Available Physical Memory'; $objects.'Virtual Memory: Max Size'; $objects.'Virtual Memory: Available'; $objects.'Virtual Memory: In Use'
I'd like to prepend different text to each object. For example, I'd like the output of $objects.'Total Physical Memory' to be something like this:

TPM:32,606 MB

For $objects.'Available Physical Memory', I'd like:

APM:23,045 MB

Thank you in advance.

Re: prepend each object

Posted: 2021-Dec-20, 8:11 pm
by Simon Sheppard
Hi querty

That can be done using the Subexpression operator inside a string.

Code: Select all

$objects = systeminfo.exe /FO CSV 2>&1| ConvertFrom-Csv; $objects.'Total Physical Memory'; $objects.'Available Physical Memory'; $objects.'Virtual Memory: Max Size'; $objects.'Virtual Memory: Available'; $objects.'Virtual Memory: In Use'

"TPM: $($objects.'Total Physical Memory') APM: $($objects.'Available Physical Memory')"

Re: prepend each object

Posted: 2021-Dec-21, 1:18 pm
by qwerty
Thank you, Simon. That worked like a charm. I just had to add the single quote ' back in front of Total Physical Memory. Thank you also for the links for more information.