I'm writing a PowerShell script to make some modifications to the Advanced Logging that's already in place on a few servers. The main issue I'm having is with the command below that was generated using Configuration Editor:
.\appcmd.exe set config "wh01-02.testlab.com" -section:system.webServer/advancedLogging/server /+"logDefinitions.[baseFileName='Log404'].filter.condition.[operator='0'].[field='Status',operator='Equals',value='404']" /commit:apphost
When I run this script, I get the following error:
ERROR ( message:Cannot find requested collection element. )
Kinda stumped on this one. Ideas anyone?
Ok, figured it out. Looks like I needed to create the 'And' operator first, then run the command:
.\appcmd.exe set config "wh01-02.testlab.com" -section:system.webServer/advancedLogging/server /+"logDefinitions.[baseFileName='Log404'].filter.condition.[operator='And']" /commit:apphost
.\appcmd.exe set config "wh01-02.testlab.com" -section:system.webServer/advancedLogging/server /+"logDefinitions.[baseFileName='Log404'].filter.condition.[operator='And'].[field='Status',operator='Equals',value='404',caseSensitive='False',regularExpression='False']" /commit:apphost
Related
I have created some global credentials in Jenkins, and I want to pass them to a powershell command that starts the execution of a protractor test suite.
The credentials are created properly, the bindings are also done as you can see int he image below:
The thing is, I need these credentials to use them when running the automation tests. The powershell command that I execute is the next one:
npm run test -- --userName=${env:ECASUSER} --password=${env:ECASPWD}
After I start the job the command is called inside the windows agent as expected, triggering the tests. When the test are using those credentials to authenticate it seems they are empty strings.
In the job console log, both credentials appear to be there but displayed like this (****).
I have tried a lot of solution none of them work. Am I doing something wrong here?
After some time spent to this, I reached the conclusion that this never worked. Or maybe it did at some point but, yeah it simply stopped.
Basically, Jenkins is not passing credentials to Windows batch or Power shell commands. My automation tests were running on blanks.
The only solution, that I found to this problem, is this one:
Create a new binding: Username and Password(conjoined) - here create a new job parameter containing the credentials. Let's say the parameter is named USERPASS;
Create a new 'Windows batch command' section where you save the credentials to a file in you test project (amazingly this one works) - your credentials will be saved to the file like this: "username:password". This is how you save the credentials:
echo %USERPASS% > "%WORKSPACE%\password.txt"
Change the automation test project to retrieve the credentials from the file;
Delete the file after the tests are completed.
I believe it should have been
npm run test --userName=${ECASUSER} --password=${ECASPWD}
and make sure you don't pass unnecessary --
Let me know if that doesn't work, I have other ideas
I using following link to create :
https://console.bluemix.net/docs/containers/cs_tutorials.html#cs_cluster_tutorial
In Lesson3, Step 3 "Verify that the KUBECONFIG environment variable is set properly.", I am unable to set the variable KUBECONFIG.
I am able to execute the following command:
ibmcloud ks cluster-config clusternameabc
I am getting following message
The configuration for clusternameabc was downloaded successfully. Export environment variables to start using Kubernetes, with the following message:
SET KUBECONFIG=C:\Users\AAA.bluemix\plugins\container-service\clusters\customernameabc\kube-config-hou02-clusternameabc.yml
When I run the above SET command in powershell, I just get the prompt back with environment variable not set.
When I do
$Env:KUBECONFIG=C:\Users\AAA.bluemix\plugins\container-service\clusters\customernameabc\kube-config-hou02-clusternameabc.yml
Notepad gets opened and this file is shown. I want to just set the environment variable and unable to. Can someone please tell me what I am doing wrong? I tried searching and could not find answers and IBM documentation has only Mac examples.
In Powershell
1) $env:KUBECONFIG = "C:\Users\AAA.bluemix\plugins\container-service\clusters\customernameabc\kube-config-hou02-clusternameabc.yml"
2) ls env:KUBECONFIG
Slightly easier to remember.
Based on my tests, you have to wrap the value of the environment environment in double quotes, like so:
$Env:KUBECONFIG="C:\Users\AAA.bluemix\plugins\container-service\clusters\customernameabc\kube-config-hou02-clusternameabc.yml"
Then, you can check the environment variables in PowerShell via this command:
Get-ChildItem Env:
Try this:
$Env:KUBECONFIG = ibmcloud cs cluster-config --export clusternameabc | Select -First 1 | % {$_.replace("SET KUBECONFIG=","")}
I am adding wsp file as it already exist now I need to update it..
Its giving me a error message on management shell that
A solution with the same name and id already exist.
I am writing this command in management shell.
Add-SPSolution "c:\Deploy\WSP\{file name}.wsp"
Like this
Add-SPSolution "c:\Deploy\WSP\SharePointProject2.wsp"
There are two ways you can achieve this:
Use 'Update-SPSolution' Or
Remove solution using 'Remove-SPSolution' and add again using
'Add-SPSolution'
All,
Note: I have updated the question after some feedback.
Thanks to #jisaak for his help so far.
I have the need to run a PowerShell script that adds TCP bindings and some other stuff when I deploy my Cloud Service.
Here is my Cloud Service Project:
Here is my Cloud Service Project and Webrole project:
Here is my task in ServiceDefinition.csdef:
And here is the PowerShell script I want to run:
here is my attempt at the Startup.cmd:
When I deploy I get this in the Azure log:
And this in the powershell log:
Any help would be very much appreciated.
I think I am nearly there but following other people syntax on the web doesn't seem to get me there.
thanks
Russ
I think the issue is that the working directory of the batch command interpreter when it runs Startup.cmd runs is not as expected.
The Startup.cmd is located in the \approot\bin\Startup directory but the working directory is \approot\bin.
Therefore the command .\RoleStartup.ps1 is not able to find the RoleStartup.ps1 as it is looking in the bin directory not in the bin\Startup directory.
Solutions I know to this are:
Solution 1:
Use ..\Startup\RoleStartup.ps1 to call the RoleStartup.ps1 from Startup.cmd.
Soltuion 2:
Change the current working directory in Startup.cmd so that the relative path .\RoleStartup.ps1 is found. I do this by CHDIR %~dp0 (see here) to change into the directory that contains Startup.cmd.
Solution 3:
As Don Lockhart's answer suggested, do not copy the Startup directory to the output, instead leave it set as "Content" in the Visual Studio project. This means the files within it will exist in the \approot\Startup directory on the Azure instance. (You would then want to make sure that the Startup folder is not publically accessible via IIS!). Then update the reference to Startup.cmd in ServiceDefinition.csdef to ..\Startup\Startup.cmd, and update the reference to RoleStartup.ps1 in Startup.cmd to ..\Startup\RoleStartup.ps1. This works on the fact that the working directory is bin and uses ..\Startup to always locate the Startup directory relative to it.
You don't need to set the executionpolicy within your cmd - just call the script. Also, you should use a relative path because you can't rely that there is C disk.
Change your batch to:
powershell -executionpolicy unrestricted -file .\RoleStartup.ps1
Right click on the RoleStartup.ps1 and Startup.cmdin Visual Studio and ensure that the Copy to Output directory is set to copy always.
If this still doesn't work, remove the startup call in your csdef, deploy the service, rdp into it and try to invoke the script by yourself to retrieve any errors.
Edit:
Try to adopt your script as below:
Import-Module WebAdministration
$site = $null
do # gets the first website until the result is not $null
{
$site = Get-WebSite | select -first 1
Sleep 1
}
until ($site)
# get the appcmd path
$appcmd = Join-Path ([System.Environment]::GetFolderPath('System')) 'inetsrv\appcmd.exe'
# ensure the appcmd.exe is present
if (-not (Test-Path $appcmd))
{
throw "appcmd.exe not found in '$appcmd'"
}
# The rest of your script ....
I've found it easier in the past to not copy the content to the output directory. I have approot\bin as the working directory. My startUp task element's commandLine attribute uses a relative reference to the .cmd file like so:
The .cmd file references the PowerShell script relatively from the working directory as well:
PowerShell -ExecutionPolicy Unrestricted -f ..\StartUp\RoleStartup.ps1
Ok,
So I am coming back to this after many different attempts to make it work.
I have tried using:
Startup config in the ServiceDefinition.csdef
I have tried registering a scheduled task on the server that scans the Windows Azure log looking for [System[Provider[#Name='Windows Azure Runtime 2.6.0.0'] and EventID=10004]]
Nothing worked either due to security or the timing of events and IIS not being fully setup yet.
So I finally bit the bullet and used my Webrole.cs => public override bool OnStart() method:
Combined with this in the ServiceDefinition.csdef:
Now it all works. This was not the most satisfying result as some of the other ways to do it felt more elegant. Also, many others posted that they got the other ways of doing it to work. Maybe I would have got there eventually but my time was restricted.
thanks
Russ
I use Yii command line inside web Root folder (C:\xampp\htdocs\myapps\cmd.exe). My command looks like this:
D:\xampp\htdocs\YiiRoot\framework\yiic shell
normally it will works, but now it didn't; I just get no output:
Sorry for late answer.
Have you configured access rules since last time you used it? If index.php isn't accessible without login anymore, the yiic tool will fail. You can overcome that by specifying the path to the config file:
protected\yiic shell protected\config\main.php
I experienced the same thing and in the end I discovered yiic file was unexpectedly empty!
A way to discover what happens behind the scenes is to comment "rem echo off" at the beginning of yiic.bat file.