Current setup:
Manually launched Windows server 2019 instance with nodes app in AWS.
Below commands are working fine with this instance
Pm2 delete myapp
Pm2 start
Issue :
We have created AMI of the above instance and launched it with a cloudformation template.
In the userdata of cloudformation template, we have made some changes in the config file of nodejs and restarting the nodes app with the above commands.
Output:
config file modified successfully with cloduformation userdata
Error:
The above commands (Pm2 delete myapp and Pm2 start) failed in the execution of userdata. below is the userdata log.
The errors from user scripts: pm2 : The term 'pm2' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the
spelling of the name, or if a path was included, verify that the path is correct and try again.
At C:\Windows\TEMP\UserScript.ps1:15 char:1
+ pm2 delete RenderWorker
+ ~~~
+ CategoryInfo : ObjectNotFound: (pm2:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
pm2 : The term 'pm2' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the
spelling of the name, or if a path was included, verify that the path is correct and try again.
At C:\Windows\TEMP\UserScript.ps1:16 char:1
+ pm2 start
+ ~~~
+ CategoryInfo : ObjectNotFound: (pm2:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
Other findings:
Pm2 command is available with newly launched ec2 instance.
C:\Users\Administrator>pm2
usage: pm2 [options] <command>
pm2 -h, --help all available commands and options
pm2 examples display pm2 usage examples
pm2 <command> -h help on a specific command
Access pm2 files in ~/.pm2
Userdata in cloudofrmation:
UserData:
Fn::Base64: !Sub |
<powershell>
$config = '{
"MyENV": "${MyENV}",
"UR1L": "${URL1}",
"URL2": "${URL2}",
"BUCKET": "${MyBucket}",
"PATH": "${Mypath}"
}'
echo $config
$config | Set-Content C:\Projects\myapp\settings\config.json
cd 'C:\Projects\myapp'
pm2 delete RenderWorker
pm2 start
</powershell>
<runAsLocalSystem>true</runAsLocalSystem>
<persist>true</persist>
I doubt that you can run pm2 directly like that because the path to pm2 does not exist under SYSTEM path.
You are likely required to include the full path of it as follows to run the command.
For example, your pm2 resides under C:\etc\ then you need to include as follows:
C:\etc\.pm2 delete RenderWorker
C:\etc\.pm2 start
or if you are familiar with the path, you can make it as an environment variable.
Related
This is the code i have written in my tut63.js file
code
console.log('Hello World');
when i type node tut63.js in terminal it was suppose to show " Hello World ".
But instead it is showing this error in terminal.
code
PS C:\Users\m\Desktop> node.tut63.js
The term 'node.tut63.js' is not recognized as the name of a cmdlet, function, script file, or oper
able program. Check the spelling of the name, or if a path was included, verify that the path is c
orrect and try again.
At line:1 char:14
node.tut63.js <<<<
CategoryInfo : ObjectNotFound: (node.tut63.js:String) [], CommandNotFoundException
FullyQualifiedErrorId : CommandNotFoundException
I have made a folder name notes and my terminal is present in notes folder currently and I am trying to move further in a file called web.js ,so I used command cd web/ which isn't seem to work and is always throwing error I also tried *cd ./web/ , cd .\web* ,nothing is working don't know why ? can anyone help me out? I need to open npm in my web.js file but not able to do so...
Kindly Help:)!
This is the error :
Devlopment\Notes\web\' because it does not exist.
At line:1 char:1
+ cd web/
+ ~~~~~~~
+ CategoryInfo : ObjectNotFound: (C:
\Web Devlopment\Notes\web\:String) [Set-Locat
ion], ItemNotFoundException
+ FullyQualifiedErrorId : PathNotFound,Micros
oft.PowerShell.Commands.SetLocationCommand```
If you need to rund web.js you can use
node web.js
cd works only with folders. You can cd into notes but web.js is a file that you can run via scripts.
I am getting this error:
Generating script.
Script contents:
docker run -p 9988:1433 aneste:mssql
========================== Starting Command Output ===========================
"C:\windows\system32\cmd.exe" /D /E:ON /V:OFF /S /C "CALL "D:\a\_temp\31deb425-e236-4cf3-bfe7-aed9ce46dd35.cmd""
.\start : The term '.\start' is not recognized as the name of a cmdlet,
function, script file, or operable program. Check the spelling of the name, or
if a path was included, verify that the path is correct and try again.
At line:1 char:76
+ ... e = 'Stop'; $ProgressPreference = 'SilentlyContinue'; .\start -sa_pas ...
+ ~~~~~~~
+ CategoryInfo : ObjectNotFound: (.\start:String) [], ParentConta
insErrorRecordException
+ FullyQualifiedErrorId : CommandNotFoundException
##[error]Cmd.exe exited with code '1'.
I have tried to search for a solution for a while now but can't seem to find one, not eaven sure what causes it, docker ls outputs the docker image correctly.
EDIT:
Yaml file
I am getting the error below:
2020-09-17T10:05:00.724 [Error] ERROR: Error logging into WVD: The
term 'Get-AutomationPSCredential' is not recognized as the name of a
cmdlet, function, script file, or operable program.Check the spelling
of the name, or if a path was included, verify that the path is
correct and try again.Exception :Type :
Microsoft.PowerShell.Commands.WriteErrorExceptionMessage : Error
logging into WVD: The term 'Get-AutomationPSCredential' is not
recognized as the name of a cmdlet, function, script file, or operable
program.Check the spelling of the name, or if a path was included,
verify that the path is correct and try again.HResult :
-2146233087CategoryInfo : NotSpecified: (:) [Write-Error], WriteErrorExceptionFullyQualifiedErrorId :
Microsoft.PowerShell.Commands.WriteErrorException,_TimerTrigger1_InvocationInfo
:MyCommand : _TimerTrigger1_HistoryId : 1InvocationName :
_TimerTrigger1_CommandOrigin : InternalScriptStackTrace : at <ScriptBlock>, D:\home\site\wwwroot\TimerTrigger1\run.ps1: line
158Microsoft.Azure.WebJobs.Script.Workers.Rpc.RpcException : Result:
ERROR: Error logging into WVD: The term 'Get-AutomationPSCredential'
is not recognized as the name of a cmdlet, function, script file, or
operable program.Check the spelling of the name, or if a path was
included, verify that the path is correct and try again.Exception
:Type : Microsoft.PowerShell.Commands.WriteErrorExceptionMessage :
Error logging into WVD: The term 'Get-AutomationPSCredential' is not
recognized as the name of a cmdlet, function, script file, or operable
program.Check the spelling of the name, or if a path was included,
verify that the path is correct and try again.HResult :
-2146233087CategoryInfo : NotSpecified: (:) [Write-Error], WriteErrorExceptionFullyQualifiedErrorId :
Microsoft.PowerShell.Commands.WriteErrorException,_TimerTrigger1_InvocationInfo
:MyCommand : _TimerTrigger1_HistoryId : 1InvocationName :
_TimerTrigger1_CommandOrigin : InternalScriptStackTrace : at <ScriptBlock>, D:\home\site\wwwroot\TimerTrigger1\run.ps1: line
158Exception: Error logging into WVD: The term
'Get-AutomationPSCredential' is not recognized as the name of a
cmdlet, function, script file, or operable program.Check the spelling
of the name, or if a path was included, verify that the path is
correct and try again.Stack:
I have seen information online that suggests it is part of the module "AzureAutomationAuthoringToolkit", but I don't understand how I install this into the environment the Function App runs in.stuff and am following a blog post below to try and get the auto-start up shut down working. I am fairly certain that I have followed this correctly. To me the error suggests that the environment doesn't have the module loaded.
https://www.ciraltos.com/auto-start-and-stop-session-hosts-in-windows-virtual-desktop-spring-update-arm-edition-with-an-azure-function/
I don't think you can use the command Get-AutomationPSCredential in the azure function, it is an Internal cmdlet belongs to the internal module Orchestrator.AssetManagement.Cmdlets, it is only available when you're executing runbooks in the Azure sandbox environment, or on a Windows Hybrid Runbook Worker.
So in your case, your option is to use the script in the automation powershell runbook, then use Invoke-WebRequest in the timer trigger to invoke the web request to the webhook URL of the runbook to start the runbook(As the script should be ran every 5 mins said by author).
Invoke-WebRequest -Uri <Webhook URI> -Method Post
For more details, you could refer to the link mentioned in the Github repo.
I'm trying to download and run a PowerShell script (from blob storage) using the Run Powershell artifact on an existing VM in Azure DevTest labs.
I get the following error and I assume I am doing something stupid.
& : The term './script.ps1' is not recognized as the name of a cmdlet,
function, script file, or operable program. Check the spelling of the name, or
if a path was included, verify that the path is correct and try again.
At line:1 char:3
+ & ./script.ps1
+ ~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (./script.ps1:String) [], Comman
dNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
Here is my setup...
I have also tried the JSON array syntax, which gave the same result, and an invalid URL which gave a 404 error so it seems as if it is downloading my script but then failing to find it.
Below is info I wrote a while back.
Few items to note:
Folder structure is not supported as of this writing. Therefore, script needs to be at the root of the container
Ensure your blob is public
First you will need your file in Azure storage. Once uploaded in your container, click the file to get to its properties and copy the URL field.
As an example, I have created the following Run.ps1 script file and uploaded it to storage as a blob:
param ( [string]$drive = "c:\" )
param ( [string]$folderName = "DefaultFolderName" )
New-Item -Path $drive -Name $folderName -ItemType "directory"
Now, while adding the 'Run PowerShell' artifact to the VM, we provide the following information:
File URI(s): URL field copied from earlier step. (eg. https://myblob.blob.core.windows.net/mycontainer/Run.ps1)
Script to Run: Name of the PS1 script, (eg. Run.ps1)
Script Arguments: Arguments as you would write them at the end of your command (eg. -drive "d:\" -folderName "MyFolder")