title: Flexibly getting a list of printers for a computer on a domain
body: <p>I am attempting to work on a script to call all printers including network printers for a computer on a domain. I first found how to do this for one computer:</p>
  <pre><code>$printerList = Get-CimInstance -ClassName Win32_Printer -ErrorAction Stop -ComputerName $env:COMPUTERNAME | Select-Object Name
  </code></pre>
  <p>Without including the environmental variable part '$env:' I was only able to get a list of local printers not any network/shared printers.</p>
  <p>My specific issue came up when trying to have the -ComputerName parameter be another variable that was an expandable string. This is important since I will need the script to be able to take a user input and have the command run without them having to manually type it out. I would run something like this:</p>
  <pre><code>$a = '$env:'+&quot;$ComputerName&quot; 
  
  $printerList = Get-CimInstance -ClassName Win32_Printer -ErrorAction Stop -ComputerName $a | Select-Object Name
  </code></pre>
  <p>But then I get the error:</p>
  <pre><code>Get-CimInstance : The WS-Management service cannot process the request because port $ComputerName:port/wsman is invalid.
  + ... Printers3 = Get-CimInstance -ClassName Win32_Printer -ErrorAction Sto ...
  +                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      + CategoryInfo          : NotSpecified: (:) [Get-CimInstance], CimException
      + FullyQualifiedErrorId : Microsoft.Management.Infrastructure.CimException,Microsoft.Management.Infrastructure.CimCmdlets.GetCimInstanceCommand
  </code></pre>
  <p>Not sure what this means but it is strange that it works manually but not when trying to expand the string.</p>