title: powershell get info about computer
body: <p>I'm trying to create a powershell script (getting more advanced... JK. Powershell offers more features than the batch file, and I want to use some of them.)</p>
  
  <p>So, here's my batch script: </p>
  
  <pre><code>:Start 
  @echo off 
  set /p password="Password:" 
  :Nextcomp 
  set /p computer="Computer name:" 
  wmic /user:username /password:%password% /node:"%computer%" memorychip get capacity 
  set /P c=Do you want to get info about another computer (y/n)? 
  if /I "%c%" EQU "y" goto :Nextcomp 
  if /I "%c%" EQU "n" goto :End goto :choice 
  pause 
  :End
  </code></pre>
  
  <p>And here's what I found: <a href="https://www.opentechguides.com/how-to/article/powershell/132/get-system-info-remotely.html" rel="nofollow noreferrer">Script</a>
  I modified it for my needs, but whenever I try to run this script, I get it the wrong way - it's displaying me the entire script, and only in the end is it asking me about the computer name:</p>
  
  <pre><code>$resultstxt = "C:\Users\user\Documents\results.csv"
  Param(
       [Parameter(Mandatory=$true, Position=0, HelpMessage="Password?")]
       [SecureString]$password
     )
  $pw = [Runtime.InteropServices.Marshal]::PtrToStringAuto([Runtime.InteropServices.Marshal]::SecureStringToBSTR($password))
  $Computer = Read-Host -Prompt 'Computer name'
  $out = @()
  If (!(Test-Connection -ComputerName $Computer -Count 1 -Quiet)) { 
      Write-Host "$Computer not on network."
      Continue 
  }
  foreach($object in $HostList) {
  $RAM = get-wmiobject -user user -password $pw -computername $object.("Computer")-class win32_physicalmemory 
  $DeviceInfo= @{}
  $DeviceInfo.add("RAM", "$([math]::floor($RAM.Capacity/ (1024 * 1024 * 1024 )) )" + " GB" )
  $DeviceInfo.add("Computer Name", $vol.SystemName)
  $out += New-Object PSObject -Property $DeviceInfo | Select-Object "RAM"
  Write-Verbose ($out | Out-String) -Verbose             
  $out | Export-CSV -FilePath $resultstxt -NoTypeInformation
  </code></pre>
  
  <p>}</p>
  
  <p>As you might have guessed, I have a lot more fields, but they all are similar, and I borrowed from a lot of sources, but mainly from the "Script" link.</p>
  
  <p>What I want is:</p>
  
  <ol>
  <li>Hide the password</li>
  <li>Export the information to CSV, with each new computer (see 3.) added following the current computer (on the next line)</li>
  <li>Ask if I want to get the info about another computer, with "y" key for yes, "n" for no.</li>
  <li>Make the script work</li>
  </ol>
  
  <p>I found about the problem 1, but I haven't tested it yet, so... will it work? Next, I found about problem 2, but it would display all info in a not-easy-to-read format, and not everything I need, and all in one cell. Finally, about 3, I found, but it wouldn't work. I can't say I dug the entire Internet, but I'm hoping you guys (and gals?) can help me figure it out. It shouldn't be that hard to resolve these 3 issues, it's not a super complicated script after all, right? My current script is only 31 lines, including the whitespaces.</p>