PSCloudScript
22.1.17
I'm still adding content to this guide, so please be patient
I've been spending a fair amount lately playing around with running PowerShell scripts that are saved on the internet and I thought it would be helpful to share what I have leared on this ... so this guide will be focused on executing PowerShell scripts that are saved on the Internet, what I call a PSCloudScript

Method

The method for running a PowerShell script on the internet is to get the raw content of a URL using Invoke-RestMethod, and then execute the result using Invoke-Expression
1
Invoke-RestMethod -Uri $Uri | Invoke-Expression
Copied!
The following command lines are identical to the method above, just formatted differently. My preference is iex(irm $Uri) as it is short and works for both PowerShell and CMD with minimal effort
PowerShell
1
#full command
2
Invoke-Expression -Command (Invoke-RestMethod -Uri $Uri)
3
4
#using alias
5
iex(irm $Uri)
6
7
#pipeline
8
Invoke-RestMethod -Uri $Uri | Invoke-Expression
9
10
#pipeline using alias
11
irm $Uri | iex
Copied!
Command Prompt
1
rem full command
2
powershell Invoke-Expression -Command (Invoke-RestMethod -Uri $Uri)
3
4
rem using alias
5
powershell iex(irm $Uri)
Copied!

KeyVault Secret Method

I'm jumping ahead here, but here is the command line for executing a PowerShell script saved as an Azure Key Vault Secret
PowerShell
1
iex(AzKeyVaultSecret $VaultName $SecretName -As)
Copied!

Content

Sponsor

OSDeploy is sponsored by Recast Software and their Systems Management Tools
Home
Recast Software
Sponsored by Recast Software