0

This is what I'm working on

$First = Read-Host "Enter First Name"
$Last = Read-Host "Enter Last Name"
$FirstIntitial = $First.Substring(0,1)
$LastInitial = $Last.Substring(0,1)
$FirstLastInitial = $FirstIntitial.ToUpper()+$LastInitial.ToUpper()
$Location = Read-Host "Enter Location"
$Department = Read-Host "Enter Department"
$Database
$Password = $FirstLastInitial+"Company"
Write-Host $Password
$SecurePassword = $Password | ConvertTo-SecureString -AsPlainText -Force

When i run it I get the error:

"Cannot process argument transformation on parameter 'Password'. Cannot convert the "System.Security.SecureString" value of type "System.String" to type "System.Security.SecureString"

Im very new to powershell and this is written based on what ive found on google. How am I supposed to convert the password to a securestring?

user71317
  • 101
  • 2
  • 3
  • I do not get errors either. At this point knowing you environment might be helpful. What version of PowerShell and what OS? Or if nothing else close your scripting session. Open a new one and paste in the code from the question here and run it again. Might be nice to know what _you_ are typing in for you tests.... in case the answer is there. – Matt Aug 26 '15 at 00:36
  • Im testing it on a server 2008 server. I am running it through the exchange management shell. The name I am testing it with is Jack Smith. – user71317 Aug 26 '15 at 00:40
  • Powershell version? Can you run this on different systems? – Matt Aug 26 '15 at 00:42
  • `"JSCompany" | ConvertTo-SecureString -AsPlainText -Force` Does this code even work for you? Shouldnt matter that you are running in EMS but I just ran this one mine and didnt get an issue there. – Matt Aug 26 '15 at 00:45
  • the exchange management shell is running PSVersion 2.0 – user71317 Aug 26 '15 at 00:45
  • It works if i type it by itself but when i run it as part of the script i get the error. Im running the script by calling it from the EMS cmd line, c:\\pathtoscript\scriptname.ps1 – user71317 Aug 26 '15 at 00:50
  • That would tell me there is something wrong with the script. If you copy and paste what you have here into a new script and run it does it work? – Matt Aug 26 '15 at 02:16
  • Just to be sure, because things like this happen even to the best: Are you double sure, that you use `$SecurePassword` later in your script instead of `$Password`? – Manuel Batsching Aug 26 '15 at 08:19
  • I found the error. Later in my script i was using $SecurePassword with quotes around it to set the users password but I Shouldnt have used the quotes. – user71317 Aug 26 '15 at 16:52

0 Answers0