title: How to log the PowerShell commands that were run
body: <p>I am new to PowerShell so this is probably obvious or I am barking up the wrong tree with my approach. But searching on here and Google have not helped me (maybe searching for the wrong terminology?)</p>
  
  <p>I am trying to write a simple PowerShell script (which works/runs no problem). However, I also have a requirement to log the process (the commands run and any output) to a txt file which I am struggling to achieve. I have tried to use the start-transcript and add the <code>-verbose</code> common parameter, but it is not working as I would expect.</p>
  
  <p>My end goal is for the script to run on one of our servers which will stop a service, stop any related processes for the service, and then start the service again. But for this example of not being able to log what is happening I have simplified it to just starting and stopping a process. My example is below:</p>
  
  <pre><code>Start-Transcript -path "C:\tester.txt" 
  
  Write-Host "starting the shell command"
  
  Start-Process notepad -verbose
  Start-Sleep -s 5
  Stop-Process -processname notepad -verbose
  
  Stop-Transcript
  </code></pre>
  
  <p>The script runs, Notepad opens, waits for 5 seconds, and then closes again. However, the verbose output is only created for the stop-process command which results in only the write-host message and the stop-process being written to my transaction/logfile. However I need it to write to my file that the Notepad process was started and then stopped.</p>