# init $who=whoami $computer=hostname $server="my-server.domain.com" # before the main command, let's call the API Invoke-WebRequest ("http://{2}:5000/my_command/start/{0}/{1}" -f ($who -replace "\\", "@"), $computer, $server) -Method POST # main command my_action # after the main command, let's call the API Invoke-WebRequest ("http://{2}:5000/my_command/end/{0}/{1}" -f ($who -replace "\\", "@"), $computer, $server) -Method POST