> For the complete documentation index, see [llms.txt](https://www.osdeploy.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://www.osdeploy.com/archive/pscloudscript.md). Agents can also search and read this documentation through its [MCP server](https://www.osdeploy.com/~gitbook/mcp).

# PSCloudScript

22.1.17

{% 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](https://www.osdeploy.com/archive/pscloudscript/ps-cmdlets.md)
{% endcontent-ref %}

{% content-ref url="/pages/GM0D469cCoPNkUmT6U1h" %}
[GitHub Gist](https://www.osdeploy.com/archive/pscloudscript/github-gist.md)
{% endcontent-ref %}

{% content-ref url="/pages/fge04aHLEOwb9dostM96" %}
[GitHub Git Repo](https://www.osdeploy.com/archive/pscloudscript/github-git-repo.md)
{% endcontent-ref %}

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

{% content-ref url="/pages/9EXWjJuNGYW4J1uIgNkF" %}
[Command Shortening](https://www.osdeploy.com/archive/pscloudscript/command-shortening.md)
{% endcontent-ref %}

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

{% content-ref url="/pages/ti6puavAbsGf9NcKUBKx" %}
[OSD PowerShell Module](https://www.osdeploy.com/archive/pscloudscript/osd-powershell-module.md)
{% endcontent-ref %}

{% content-ref url="/pages/Y10fg2NcoZclOa80xsj8" %}
[PSCloudScript Examples](https://www.osdeploy.com/archive/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
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

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

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://www.osdeploy.com/archive/pscloudscript.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
