1

I'm trying to format an array into a string. What I'm doing is this:

$PysicalMemory | Format-Table @{n="Capacity(GB)";e={$_.Capacity/1GB}}, Speed

This gives me the output in this form:

Capacity(GB) Speed
------------ -----
           4  1600
           4  1600

But I would like to format it in a single string like this, but I have no luck:

4GB1600/4GB1600
1
  • Can you post where you got $PysicalMemory from? Commented Oct 24, 2018 at 9:24

1 Answer 1

3

this requires a slightly different method than you used, but it DOES give the output you seem to want & is easily tweaked ...

$CIM_RAM = @(Get-CimInstance CIM_PhysicalMemory)

$RAM_Info = foreach ($CR_Item in $CIM_RAM)
    {
    '{0}GB{1}Mhz' -f ($CR_Item.Capacity / 1GB), $CR_Item.Speed
    }

$RAM_Info -join '/'

output = 2GB800Mhz/2GB800Mhz/2GB800Mhz/2GB800Mhz

yes, my ddr2 ram is really that slow. [grin]

Sign up to request clarification or add additional context in comments.

4 Comments

I would also add that if you want to store it for use later, you should store it in a variable like this $PhysicalMemoryString = $RAM_Info -join '/'
@Joseph - the reason i used a different format for the strings was to make it very, very obvious that the exact layout of the string can easily be tweaked as desired. your suggestion exactly fits the OPs request, but may not make the teaching point. i approved the edit ... but i am still not sure that was the correct thing to do. [sigh ...]
Maybe add it as a another line perhaps? Maybe it would cause a little confusion, lol. I don't know. I'd have to know the OP's Powershell skills, I guess... I certainly see your point though.
Thank you very much for the answers. I saw Lee's post before it got edited and understand both of them (although my Powershell skills are very limited I must admit).

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.