Pass password into -credential
<p>I am trying to login into a computer.
I have been playing with various versions and determined that my past questions were when I didn't know what I was really trying to do.</p>

<p>I discovered that I was on the incorrect PC when running the script.</p>

<p>When I now run the script on the correct PC, the following code requires me to enter the password.</p>

<pre><code>gwmi win32_service –credential domain\username –computer PC#
</code></pre>

<p><strong>Is there a way with my current script above, to enforce the username and password without user entry?</strong> I have to do this for 100s of PCs so I want to loop through all of them without the user having to input the password 100s of times.</p>

<hr>

<p>I tried doing the following:</p>

<pre><code>$Username = 'domain\username'
$Password = 'password'

$pass = ConvertTo-SecureString -AsPlainText $Password -Force

$SecureString = $pass
# Users you password securly
$MySecureCreds = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $Username,$SecureString –computer PC#
</code></pre>

<p>However, I get an error of <code>A parameter cannot be found that matches parameter name 'computer'.</code></p>

<p>also tried:</p>

<pre><code>$MySecureCreds = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $Username,$SecureString 
# Sets yous credentials to be used
#$RemoteConn = New-PSSession -ComputerName "PC#" -Credential $MySecureCreds -Authentication default
</code></pre>

<p>but the RemoteConn didn't work</p>