prepend each object

Microsoft Windows
Post Reply
qwerty
Posts: 7
Joined: 2021-Dec-20, 2:40 pm

prepend each object

Post 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.
User avatar
Simon Sheppard
Posts: 87
Joined: 2021-Jul-10, 7:46 pm
Contact:

Re: prepend each object

Post 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')"
Last edited by Simon Sheppard on 2021-Dec-22, 10:42 am, edited 1 time in total.
Reason: fix missing quote
qwerty
Posts: 7
Joined: 2021-Dec-20, 2:40 pm

Re: prepend each object

Post 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.
Post Reply