# PSCloudScript

{% hint style="info" %}
**I'm still adding content to this guide, so please be patient**
{% endhint %}

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`

```powershell
Invoke-RestMethod -Uri $Uri | Invoke-Expression
```

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

{% code title="PowerShell" %}

```powershell
#full command
Invoke-Expression -Command (Invoke-RestMethod -Uri $Uri)

#using alias
iex(irm $Uri)

#pipeline
Invoke-RestMethod -Uri $Uri | Invoke-Expression

#pipeline using alias
irm $Uri | iex
```

{% endcode %}

{% code title="Command Prompt" %}

```batch
rem full command
powershell Invoke-Expression -Command (Invoke-RestMethod -Uri $Uri)

rem using alias
powershell iex(irm $Uri)
```

{% endcode %}

## 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

{% code title="PowerShell" %}

```powershell
iex(AzKeyVaultSecret $VaultName $SecretName -As)
```

{% endcode %}

## Content

{% content-ref url="/pages/FZg4e1eiEAE1TiXEeqz3" %}
[PS Cmdlets](/guides/pscloudscript/ps-cmdlets.md)
{% endcontent-ref %}

{% content-ref url="/pages/GM0D469cCoPNkUmT6U1h" %}
[GitHub Gist](/guides/pscloudscript/github-gist.md)
{% endcontent-ref %}

{% content-ref url="/pages/fge04aHLEOwb9dostM96" %}
[GitHub Git Repo](/guides/pscloudscript/github-git-repo.md)
{% endcontent-ref %}

{% content-ref url="/pages/nmjIBhzSrqSfnvSwcbAP" %}
[Content-Type | Azure Static Web App](/guides/pscloudscript/content-type-or-azure-static-web-app.md)
{% endcontent-ref %}

{% content-ref url="/pages/9EXWjJuNGYW4J1uIgNkF" %}
[Command Shortening](/guides/pscloudscript/command-shortening.md)
{% endcontent-ref %}

{% content-ref url="/pages/nHTupr0CBzxXmELh058P" %}
[Azure Key Vault Secret](/guides/pscloudscript/azure-key-vault-secret.md)
{% endcontent-ref %}

{% content-ref url="/pages/ti6puavAbsGf9NcKUBKx" %}
[OSD PowerShell Module](/guides/pscloudscript/osd-powershell-module.md)
{% endcontent-ref %}

{% content-ref url="/pages/Y10fg2NcoZclOa80xsj8" %}
[PSCloudScript Examples](/guides/pscloudscript/pscloudscript-examples.md)
{% endcontent-ref %}

## Sponsor

OSDeploy is sponsored by [Recast Software](https://www.recastsoftware.com/?utm_source=osdeploy\&utm_medium=ad\&utm_campaign=web) and their Systems Management Tools

{% embed url="<https://www.recastsoftware.com/?utm_source=osdeploy&utm_medium=ad&utm_campaign=web>" %}
Sponsored by Recast Software
{% endembed %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://www.osdeploy.com/guides/pscloudscript.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
