Darren Bowden
asked on
Why wouldn't a Read-Host input not get applied later in script?
First off I would like to say I am new to powershell scripting and am experimenting with some ideas. However I keep running into an error and not sure why. Any advice would be much appreciated. I am doing this in a windows 2016 environment.
$domainname = (Read-Host "Enter name for domain.")
Install-WindowsFeature AD-Domain-Services -IncludeManagementTools
Import-Module ADDSDeployment
Install-ADDSForest -DomainName "$domainmane"
Set-TimeZone -Id "Mountain Standard Time"
I get:
Install-ADDSForest : Cannot bind argument to parameter 'DomainName' because it is an empty string.
I have also tried it as:
$domainname = Read-Host "Enter name for domain."
$domain = -domainname $domainname
Install-WindowsFeature AD-Domain-Services -IncludeManagementTools
Import-Module ADDSDeployment
Install-WindowsFeature ADDSForest
Set-TimeZone -Id "Mountain Standard Time"
However any time I attempt this I receive the following error:
Install-WindowsFeature : A parameter cannot be found that matches parameter name 'DomainName'.
At line:10 char:35
+ Install-WindowsFeature ADDSForest -DomainName "$domainmane"
+ ~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [Install-WindowsFeature], ParameterBindingException
+ FullyQualifiedErrorId : NamedParameterNotFound,Mic rosoft.Win dows.Serve rManager.C ommands.Ad dWindowsFe atureComma nd
Thank you in advance!
$domainname = (Read-Host "Enter name for domain.")
Install-WindowsFeature AD-Domain-Services -IncludeManagementTools
Import-Module ADDSDeployment
Install-ADDSForest -DomainName "$domainmane"
Set-TimeZone -Id "Mountain Standard Time"
I get:
Install-ADDSForest : Cannot bind argument to parameter 'DomainName' because it is an empty string.
I have also tried it as:
$domainname = Read-Host "Enter name for domain."
$domain = -domainname $domainname
Install-WindowsFeature AD-Domain-Services -IncludeManagementTools
Import-Module ADDSDeployment
Install-WindowsFeature ADDSForest
Set-TimeZone -Id "Mountain Standard Time"
However any time I attempt this I receive the following error:
Install-WindowsFeature : A parameter cannot be found that matches parameter name 'DomainName'.
At line:10 char:35
+ Install-WindowsFeature ADDSForest -DomainName "$domainmane"
+ ~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [Install-WindowsFeature], ParameterBindingException
+ FullyQualifiedErrorId : NamedParameterNotFound,Mic
Thank you in advance!
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Putting Set-StrictMode -Version 2.0 as first statement can help with that. You get an error whenever an unitialized variable is used to get values.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
footech is absolutely correct. "adding a echo -domainname at the end of the read-host" doesn't make any sense, sorry.
ASKER
Answer was not suggested, so the solution I found im giving as information for anyone else having the same problem.