Ok, so this is my first time posting on here and my first time writing PowerShell. My school computer maintenance and repair class requested from all the students that one of them create a PowerShell script that calculates a computers ram. The one I created calculates total physical ram, total ram usable by the user, and the modules in the computer and how much is on each module. However, after successfully coding it, I need a bit of advice as to tweaking the code so it can be use for my school.
The first part of my program opens up and talks about what each line means, follows by total physical ram, user accessible ram, and then the way the cards are set up. This leads right into a text that says to close the program. What I want to add in (I am a beginner at PowerShell by the way) is a way for the user to rerun the application if any of the variables from the program come up as zero (cause obviously the computer has ram of some sort if the computer is running). Right now its a Read-Host "Rerun memsrch ('y'/'n')?"
The other thing I want to add in is the ability for the user to select if the code is for the local computer or a distant machine. The user then could select the computer via IP or computer name. Below is the code I have now so everyone can see.
# Mesa Public Schools
$mps="Mesa Public Schools Information Technology Services"
$mps
# User Help
$print="The first section calculates your total physical memory,
the second line calculates the ram available to the user,
and the third line shows how the ram is divided up among
the ram cards.`n"
$print
#where I want to put a line of code to allow user to select if its local or remote
$ram = get-wmiobject win32_computersystem | select totalPhysicalMemory
Write-Host "Total usable RAM capacity"
$ramOutput = get-wmiobject win32_computersystem | select totalPhysicalMemory | foreach {$_.totalPhysicalMemory}
"RAM: " + "{0:N2}" -f ($ram.TotalPhysicalMemory/1GB) + "GB"
Get-WMIObject -class win32_physicalmemory | Format-Table devicelocator, capacity -a
Write-Host "Summary of System Memory"
Get-WmiObject -class Win32_PhysicalMemory | Measure-Object -Property Capacity -Sum
# Coded BY
$credits="Coded by Michael Meli"
$credits
#where I want to have the code reloop to the part of the code where
#you first select if the computer is local or remote.
Read-Host "Rerun memsrch (y/n)?"
I also have a bit of experience with HTML 4.01 and HTML 5 code, so I understand the basics of constructs and arguments, but aside from that a large part of powershell at the moment is above my head, so don't get to technical cause I don't want my brain to explode. :P Also note that the code if for computers running windows 8.1, but must be compatible with windows 7 as well. This also is not for a grade in my class either, it's extra credit.
NOTESfield of a comment-based help section in your script instead