Add support for remote scripts to pwsh troubleshooter (#3051)
Add the ability to pull a Gist (or other downloadable script) and execute it. --- #### Does this PR need a docs update or release note? - [ ] ✅ Yes, it's included - [ ] 🕐 Yes, but in a later PR - [x] ⛔ No #### Type of change <!--- Please check the type of change your PR introduces: ---> - [x] 🌻 Feature - [ ] 🐛 Bugfix - [ ] 🗺️ Documentation - [x] 🤖 Supportability/Tests - [ ] 💻 CI/Deployment - [ ] 🧹 Tech Debt/Cleanup #### Issue(s) <!-- Can reference multiple issues. Use one of the following "magic words" - "closes, fixes" to auto-close the Github issue. --> * #<issue> #### Test Plan <!-- How will this be tested prior to merging.--> - [x] 💪 Manual - [ ] ⚡ Unit test - [ ] 💚 E2E
This commit is contained in:
parent
e4be050ac1
commit
3cf3e664aa
@ -3,6 +3,11 @@ from m365pnp/powershell:2.1.1-alpine-3.14
|
||||
RUN Install-Module PowerShellGet -Force
|
||||
RUN Install-Module Microsoft.Graph -Force -RequiredVersion 1.25.0 -Scope AllUsers
|
||||
|
||||
COPY ./Execute-Script.ps1 /tpm/Execute-Script.ps1
|
||||
RUN Move-Item -Path /tpm/Execute-Script.ps1 -Destination $ENV:PATH.Split(":")[0]
|
||||
|
||||
# If you add other powershell commands this needs to be last since it sets
|
||||
# the profile to run auth for the user which will then try to run for subsequent connads
|
||||
COPY ./Auth-Graph.ps1 /tmp/Auth-Graph.ps1
|
||||
RUN Move-Item -Path /tmp/Auth-Graph.ps1 -Destination $PROFILE.AllUsersAllHosts
|
||||
|
||||
|
||||
15
src/cmd/graph_pwsh/Execute-Script.ps1
Normal file
15
src/cmd/graph_pwsh/Execute-Script.ps1
Normal file
@ -0,0 +1,15 @@
|
||||
[CmdletBinding()]
|
||||
|
||||
Param (
|
||||
[Parameter(Mandatory = $True, HelpMessage = "Powershell script URL")]
|
||||
[string]$ScriptURL
|
||||
)
|
||||
|
||||
Invoke-WebRequest -Uri $ScriptURL -OutFile ./script.ps1
|
||||
|
||||
Write-Host "Executing the following script"
|
||||
Write-Host "=============================="
|
||||
cat ./script.ps1
|
||||
Write-Host "=============================="
|
||||
|
||||
./script.ps1
|
||||
@ -6,7 +6,7 @@ their environment.
|
||||
|
||||
One convenient mechanism to accomplish this without going down to the level of
|
||||
wrapping individual Graph API calls is to use the
|
||||
[Microsoft Graph PowerShell](https://learn.microsoft.com/en-us/powershell/microsoftgraph/overview?view=graph-powershell-1.0).
|
||||
[Microsoft Graph Powershell](https://learn.microsoft.com/en-us/powershell/microsoftgraph/overview?view=graph-powershell-1.0).
|
||||
It provides a convenient wrapper and great coverage of the API surface.
|
||||
|
||||
## Build container
|
||||
@ -17,6 +17,8 @@ Before using the tool you want to build the container that packages it.
|
||||
docker build -t corso/graph_pwsh:latest .
|
||||
```
|
||||
|
||||
A prebuilt image is also available currently available as `gmatev/graph_pwsh`.
|
||||
|
||||
## Prerequisites
|
||||
|
||||
### Docker
|
||||
@ -82,10 +84,25 @@ docker run --rm -it -v $(pwd):/usr/pwsh --env-file env_names corso/graph_pwsh \
|
||||
pwsh -c "Get-MgUserMessage -UserId <userID or UPN> -MessageID <messageID>"
|
||||
```
|
||||
|
||||
### Running a remote script
|
||||
|
||||
In some cases, it may be prudent to run a more complex Powershell script that strings
|
||||
a number of commands together. While it is possible to compact the sctipt to a single line,
|
||||
that is quite inconvenient.
|
||||
|
||||
Instead, it is possible to stash the desired script somewhere publically accessible (e.g. Gist)
|
||||
and execute the container which will pull it and then execute it. This can be done using the
|
||||
`Execute-Script.ps1` command as follows.
|
||||
|
||||
```sh
|
||||
docker run --rm -it -v $(pwd):/usr/pwsh --env-file env_names corso/graph_pwsh \
|
||||
pwsh -c "Execute-Script.ps1 -ScriptUrl <script download URL>"
|
||||
```
|
||||
|
||||
## Debug output
|
||||
|
||||
To see the requests and responses made by the specific Graph PowerShell commands, add `-Debug` to you command,
|
||||
similar to the example below.
|
||||
To see the requests and responses made by the specific Graph Powershell commands, add `-Debug` to you command,
|
||||
similar to the example below.
|
||||
|
||||
```sh
|
||||
# This is the equivalent of GET https://graph.microsoft.com/v1.0/users
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user