2

I'm king of novice when it comes to Powershell. I wanted to create Powershell scripts that are more verbose as it executes various commands.

For example in the following code, I want it to clearly display what it doing, and regardless of whether the command was executed successfully Or Not, I want it to print out the results of the execution of the command in question:

Import-Module IISAdministration

Stop-WebSite 'ArtemisDEV'

$a = ".\blabBlah.csproj /t:Clean" Invoke-Expression "$msbuild $a"

$b = ".\blabBlah.csproj /t:Build /p:Configuration=Dev" Invoke-Expression "$msbuild $b"

Could someone please modify the aforementioned code, and show it such a way that it will print out more verbose output statements?

mklement0
  • 382,024
  • 64
  • 607
  • 775
crazyTech
  • 1,379
  • 3
  • 32
  • 67
  • 2
    Have a look at ```try { } catch { } finally { }``` - https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_try_catch_finally?view=powershell-7.1. the general pattern is ```try { } catch { } finally { }``` – mclayton May 27 '21 at 13:45
  • @Johann, to avoid duplication I've decided to delete the answer here and have reposted it (with minor enhancements) to the linked duplicate [here](https://stackoverflow.com/a/70020655/45375). – mklement0 Nov 19 '21 at 18:43

0 Answers0