Reputation: 933
This script works great to accept some read-host prompts and create a website with an app pool tied to it. The password prompt works except our most common password is !$Pass!123!! and it will not allow me to receive it as input. How do you allow these characters to be used?
Import-Module WebAdministration
# Get Web Site Variables $WebSite = Read-Host -Prompt "DNS name for Web Site" $AppPoolName = Read-Host -Prompt "Application Pool Name" [string]$AppPoolUser = Read-Host -Prompt "Application Pool Username Domain not required ex. PXML.Proxy$" $Password = Read-Host -Prompt "Application Pool Account Password, try ` before $ in password" $HostHeader = Read-Host -Prompt "Host Header Name" # cmd /c C:\scripts\BaseIIS.cmd $WebServer $AppPool $AppPoolUser $Password $HostName New-Item -path d:\Websites -itemtype directory New-Item -path d:\Logs -itemtype directory New-Item -path d:\Logs\$WebSite -itemtype directory New-Item -path d:\websites\$WebSite -itemtype directory
Upvotes: 0
Views: 3981
Reputation: 60938
The problem in the input isn't the dollar sign($)
but the starting exclamation mark(!)
You need to escape it with another one.
You password need to be inputed as: !!$Pass!123!!
Read here to know more about this
Why not using get-credential
cmdlet:
$cred = Get-Credential -Message "Insert Username and Passsword"
$cred.GetNetworkCredential().UserName
Jacob
$cred.GetNetworkCredential().Password
!$Pass!123!!
or you can use:
$Password = Read-Host -Prompt "Application Pool Account Password" -assecurestring
[String]$Password = [Runtime.InteropServices.Marshal]::PtrToStringAuto([Runtime.InteropServices.Marshal]::SecureStringToBSTR($Password))
Upvotes: 4
Reputation: 26170
this doesn't seem to be a problem with V3 :
PS>$t=Read-Host
!$Pass!123!!
PS>$t
!$Pass!123!!
Upvotes: 0