0

I have an Azure project with a WorkerRole for which I have a StartUp task. The startup task is a simple .cmd file (startup.cmd), which calls a powershell script (PerformanceCounterInstaller.ps1). It appears the .cmd file gets executed just fine and it can find the .ps1 file (if the path or name of the .ps1 file is incorrect, I see mentions of it in the err.out file). However, the actual content of the .ps1 file seems to be ignored completely (Write-Output commands, Start-Transcript, Creation of performance counter, ...). I don't get any feedback or any data showing any of the attempted operations were performed.

The only data I have in err.out and std.out is coming from the .cmd file and I can't locate any transcript file.

Regards, Mario.

The content of the relevant files can be found below.

------Content of ServiceDefinition.csdef : ------

<?xml version="1.0" encoding="utf-8"?>
<ServiceDefinition name="WindowsAzure2" xmlns="http://schemas.microsoft.com/ServiceHosting/2008/10/ServiceDefinition" schemaVersion="2012-10.1.8">
  <WorkerRole name="MBAzureTestServiceWorkerRole" vmsize="Small">
    <Startup>
      <Task commandLine="StartupTasks\startuptasks.cmd" executionContext="elevated" taskType="simple" />
    </Startup>
    <Imports>
      <Import moduleName="Diagnostics" />
    </Imports>
  </WorkerRole>
</ServiceDefinition>

------Content of startuptasks.cmd : ------

cd %~dp0
echo %date% %time% >>std.out
echo %date% %time% >>err.out
powershell -ExecutionPolicy Unrestricted './PerformanceCounterInstaller.ps1'  >>std.out   2>> err.out
EXIT /B 0

------Content of PerformanceCounterInstaller.ps1 : ------

$serviceName = "Test Service"

# Write-Output "This is a test of the broadcasting system..."

Start-Transcript -Path startup_transcript.txt 
Stop-Transcript
[more stuff]

2 Answers 2

0

I think the problem is because you are redirecting output of PowerShell into std.out. I remember that this is a popular bug in PowerShell v2.0. Try to replace this line

powershell -ExecutionPolicy Unrestricted './PerformanceCounterInstaller.ps1'  >>std.out   2>> err.out

with this line

powershell -ExecutionPolicy Unrestricted './PerformanceCounterInstaller.ps1'

Sign up to request clarification or add additional context in comments.

Comments

0

The problem seem to have been the use of the single quote (i.e. ') around the ps1 file name and path inside the .cmd file. Using the double quotes (i.e. ") makes it behave properly...

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.