Skip to content

Using PowerShell

dfinke edited this page Feb 22, 2021 · 2 revisions

Setup A Few PowerShell Scripts

Template

The powershell template has been already provided along with this release. The template looks like:

# Template for basic PowerShell automation
name: Custom PowerShell Automation

on:
  workflow_dispatch:

jobs:
  build:
    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v2

      - name: Run the scripts
        shell: pwsh
        run: |
$command

Notes:

Few important points the template says:

  • It instructs GitHub Actions to run only on workflow_dispatch, i.e. on manual trigger.
  • It tells the tool that it accepts a command which needs to be supplied by the -command argument.

Usage:

Lets see a simplified usage of things:

  • Create a new repository pstest and clone it locally under custom/ folder.
    New-GHRepo $repoName -clone    
  • Now, put all your scripts inside the fresh cloned repository.
    $defaultPath = "./custom"
    
    '"Hello World"' > $defaultPath/$repoName/hello.ps1
    '"Howdy"' > $defaultPath/$repoName/howdy.ps1
    '"So long"' > $defaultPath/$repoName/bye.ps1
    '"Fare thee well"' > $defaultPath/$repoName/farewell.ps1
  • Now its time to push these to GitHub. The below command will automatically commit the files and push it to GitHub. Note, Invoke-GHPush takes in a repository name cloned under custom/ folder.
    Invoke-GHPush $repoName
  • Time for the actual hack. Specify your command through the -command parameter. You can specify multiple commands using bash separators like && or semicolons ;. Also we instruct Invoke-Advantage to save the runtime logs locally.
    Invoke-Advantage -owner dfinke -repo pstest -template basic-powershell -c './hello.ps1 && ./howdy.ps1' --save-logs ./logsdir

That's it! Now go ahead and check your results. PSAdvantage is as flexible as your thoughts!

Wiki Index

Clone this wiki locally