Skip to content

Instantly share code, notes, and snippets.

@msnelling
Created March 30, 2016 07:44
Show Gist options
  • Save msnelling/751d5dfbb8f360b40f9fa7d621295a4f to your computer and use it in GitHub Desktop.
Save msnelling/751d5dfbb8f360b40f9fa7d621295a4f to your computer and use it in GitHub Desktop.
Strip ANSI codes from Terraform output
function Remove-ANSICodes
{
param([string][Parameter(ValueFromPipeline=$true)]$String)
$String -replace '\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[m|K]', ''
}
function Run-Command
{
param([string]$Command)
Get-RemoteSettings
Write-Output "Running $Command..."
$Cmd = "terraform $Command"
& ([ScriptBlock]::Create($Cmd)) | Out-String | Remove-ANSICodes
if ($LASTEXITCODE -ne 0)
{
throw "Error executing command: $Cmd"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment