PS Cmdlets
22.1.16
Invoke-RestMethod
Invoke-Expression
Order
Sponsor
Last updated
22.1.16
Last updated
PS C:\> Invoke-RestMethod -Uri https://raw.githubusercontent.com/OSDeploy/PSCloudScript/main/ps-cmdlets.txt
This is a test to see if this raw content can be saved as a PowerShell string
PS C:\> irm https://raw.githubusercontent.com/OSDeploy/PSCloudScript/main/ps-cmdlets.txt
This is a test to see if this raw content can be saved as a PowerShell string
PS C:\> $String = irm raw.githubusercontent.com/OSDeploy/PSCloudScript/main/ps-cmdlets.txt
PS C:\> $String
This is a test to see if this raw content can be saved as a PowerShell stringPS D:\> $String = @'
Write-Host 'This is PowerShell String'
'@
PS D:\> Invoke-Expression -Command $String
This is PowerShell String
PS D:\> Invoke-Expression $String
This is PowerShell String
PS D:\> iex $String
This is PowerShell StringPS D:\> $StringFunction = @'
function Test-PowerShell
{
[CmdletBinding()]
param()
Write-Host 'This is a PowerShell Function'
Write-Verbose 'And this is a Verbose PowerShell Function'
}
'@
PS D:\> Invoke-Expression -Command $StringFunction
PS D:\> Test-PowerShell
This is a PowerShell Function
PS D:\> Test-PowerShell -Verbose
This is a PowerShell Function
VERBOSE: And this is a Verbose PowerShell Function#Command in parenthesis is processed first in both of these examples
Invoke-Expression -Command (Invoke-RestMethod -Uri $Uri)
#Alternate using Alias
iex(irm $Uri)
#Pipeline can be used
Invoke-RestMethod -Uri $Uri | Invoke-Expression
#Alternate using Alias
irm $Uri | iex