getting this error when running packer to aws
==> amazon-ebs: < : The term ‘<’ is not recognized as the name of a cmdlet, function, script file, or operable program. Check the
==> amazon-ebs: spelling of the name, or if a path was included, verify that the path is correct and try again.
==> amazon-ebs: At C:\Windows\Temp\script-5e80d1ae-09d8-1b0d-69bc-c71ff29e901c.ps1:1 char:1
==> amazon-ebs: +
==> amazon-ebs: + ~
==> amazon-ebs: + CategoryInfo : ObjectNotFound: (<:String) , CommandNotFoundException
==> amazon-ebs: + FullyQualifiedErrorId : CommandNotFoundException
==> amazon-ebs:
==> amazon-ebs: set-ExecutionPolicy : Windows PowerShell updated your execution policy successfully, but the setting is overridden by
==> amazon-ebs: a policy defined at a more specific scope. Due to the override, your shell will retain its current effective
==> amazon-ebs: execution policy of Bypass. Type “Get-ExecutionPolicy -List” to view your execution policy settings. For more
==> amazon-ebs: information please see “Get-Help Set-ExecutionPolicy”.
==> amazon-ebs: At C:\Windows\Temp\script-5e80d1ae-09d8-1b0d-69bc-c71ff29e901c.ps1:5 char:1
==> amazon-ebs: + set-ExecutionPolicy Unrestricted -Scope LocalMachine -Force -ErrorAct …
==> amazon-ebs: + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
==> amazon-ebs: + CategoryInfo : PermissionDenied: (
[Set-ExecutionPolicy], SecurityException
==> amazon-ebs: + FullyQualifiedErrorId : ExecutionPolicyOverride,Microsoft.PowerShell.Commands.SetExecutionPolicyCommand
This doesn’t seems to be a problem with packer but with the windows shell.
What’s the command you are trying to execute?
this is the script
write-output "Running User Data Script"
write-host "(host) Running User Data Script"
set-ExecutionPolicy Unrestricted -Scope LocalMachine -Force -ErrorAction Ignore
Don’t set this before Set-ExecutionPolicy as it throws an error
$ErrorActionPreference = “stop”
Remove HTTP listener
Remove-Item -Path WSMan:\Localhost\listener\listener* -Recurse
$Cert = New-SelfSignedCertificate -CertstoreLocation Cert:\LocalMachine\My -DnsName “packer”
New-Item -Path WSMan:\LocalHost\Listener -Transport HTTPS -Address * -CertificateThumbPrint $Cert.Thumbprint -Force
WinRM
write-output “Setting up WinRM”
write-host “(host) setting up WinRM”
cmd.exe /c winrm quickconfig -q
cmd.exe /c winrm set “winrm/config” ‘@{MaxTimeoutms=“1800000”}’
cmd.exe /c winrm set “winrm/config/winrs” ‘@{MaxMemoryPerShellMB=“1024”}’
cmd.exe /c winrm set “winrm/config/service” ‘@{AllowUnencrypted=“true”}’
cmd.exe /c winrm set “winrm/config/client” ‘@{AllowUnencrypted=“true”}’
cmd.exe /c winrm set “winrm/config/service/auth” ‘@{Basic=“true”}’
cmd.exe /c winrm set “winrm/config/client/auth” ‘@{Basic=“true”}’
cmd.exe /c winrm set “winrm/config/service/auth” ‘@{CredSSP=“true”}’
cmd.exe /c winrm set “winrm/config/listener?Address=*+Transport=HTTPS” “@{Port="5986
”;Hostname="packer
";CertificateThumbprint="$($Cert.Thumbprint)
"}"
enable=yes
cmd.exe /c netsh Advfirewall set allprofiles state off
cmd.exe /c net stop winrm
cmd.exe /c sc config winrm start= auto
cmd.exe /c net start winrm
also this is not working choco.ps1
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
Write-Host "Let's do Chocolatey"
# Install Chocolatey
iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))
# Globally Auto confirm every action
choco feature enable -n allowGlobalConfirmation
Write-Host "Did Chocolatey"
Can you use a format block? It’s hard to read.
<
write-output “Running User Data Script”
write-host “(host) Running User Data Script”
set-ExecutionPolicy Unrestricted -Scope LocalMachine -Force -ErrorAction Ignore
Don’t set this before Set-ExecutionPolicy as it throws an error
$ErrorActionPreference = “stop”
Remove HTTP listener
Remove-Item -Path WSMan:\Localhost\listener\listener* -Recurse
$Cert = New-SelfSignedCertificate -CertstoreLocation Cert:\LocalMachine\My -DnsName “packer”
New-Item -Path WSMan:\LocalHost\Listener -Transport HTTPS -Address * -CertificateThumbPrint $Cert.Thumbprint -Force
WinRM
write-output “Setting up WinRM”
write-host “(host) setting up WinRM”
cmd.exe /c winrm quickconfig -q
cmd.exe /c winrm set “winrm/config” ‘@{MaxTimeoutms=“1800000”}’
cmd.exe /c winrm set “winrm/config/winrs” ‘@{MaxMemoryPerShellMB=“1024”}’
cmd.exe /c winrm set “winrm/config/service” ‘@{AllowUnencrypted=“true”}’
cmd.exe /c winrm set “winrm/config/client” ‘@{AllowUnencrypted=“true”}’
cmd.exe /c winrm set “winrm/config/service/auth” ‘@{Basic=“true”}’
cmd.exe /c winrm set “winrm/config/client/auth” ‘@{Basic=“true”}’
cmd.exe /c winrm set “winrm/config/service/auth” ‘@{CredSSP=“true”}’
cmd.exe /c winrm set “winrm/config/listener?Address=*+Transport=HTTPS” “@{Port="5986
”;Hostname="packer
";CertificateThumbprint="$($Cert.Thumbprint)
“}”
#cmd.exe /c netsh advfirewall firewall set rule group=“remote administration” new enable=yes
cmd.exe /c netsh Advfirewall set allprofiles state off
#cmd.exe /c netsh firewall add portopening TCP 5986 “Port 5986”
cmd.exe /c net stop winrm
cmd.exe /c sc config winrm start= auto
cmd.exe /c net start winrm
As the error message tells you: 1st line, 1st character. Whatever the <
should do, it’s breaking the script.
The script is still not shown in a formatted block and hard to read.
What is not working with the choco.ps1
script? An error message would be nice to have.
how should i be specifying a powershell script in the json file?
this is whast i have
“provisioners”: [
{
“type”: “powershell”,
“scripts”: [
“./scripts/disable-uac.ps1”,
“./scripts/SetupWinRM.ps1”
]
}
inside the powershell script, do i need to use ?
Do you intentionally ignore my questions and pointers, and then ask opposing questions?
I’m out of here, that’s too stupid for me.