Skip to content

Instantly share code, notes, and snippets.

@srpomeroy
srpomeroy / Remove-BCDTimeout.ps1
Created December 21, 2017 19:19
Remove default OS timeout in Windows
$bcdConfig = & bcdedit.exe /enum
foreach($line in $bcdConfig) {
if ($line -like "timeout*") {
$timeout = $line.replace('timeout','').replace(' ','')
if($timeout -ne 0) {
Write-Output "Changing timeout from $timeout to 0"
& bcdedit.exe /timeout 0
BREAK
}
@srpomeroy
srpomeroy / RightScale - Call Additional Script on Terminate.ps1
Created February 24, 2017 04:18
RightScale/Rightlink10/RSC Call additional script on terminate
$erroractionpreference = "Stop"
$rightlink_dir = 'C:\Program Files\RightScale\RightLink'
$decom_reason = & "${rightlink_dir}\rsc.exe" rl10 show /rll/proc/shutdown_kind
$rightScriptID = "123456789"
If ($decom_reason -eq "terminate") {
Write-Output "Instance is terminating. Running script..."
#Run RightScript
@srpomeroy
srpomeroy / RightScale - Schedule Snapshot.ps1
Created February 24, 2017 04:16
RightScale/Rightlink10/RSC Use PowerShell Job to schedule a snapshot by running a script in RightScale via RSC.
$errorActionPreference = "stop"
$scriptId = "12345678"
$rsc = 'C:\Program Files\RightScale\RightLink\rsc.exe'
$snapshot_Name = $ENV:SNAPSHOT_NAME
$snapshot_Save = $ENV:KEEP_SNAPSHOTS
$scheduledTask_Time =$ENV:SCHEDULED_TASK_TIME
$scheduledTask_Name = "RightScale Snapshot - $ENV:SNAPSHOT_NAME"
if(($ENV:ENABLE_SNAPSHOT -eq $true) -and (!($ENV:KEEP_SNAPSHOTS) -or !($ENV:SCHEDULED_TASK_TIME))) {
Write-Output "Error! Must provide value for KEEP_SNAPSHOTS and SCHEDULED_TASK_TIME!"
@srpomeroy
srpomeroy / GetRightScaleAPIStatus.ps1
Created November 29, 2016 18:58
PowerShell example of retrieving RightScale API Status
((Invoke-WebRequest -Uri "http://status.rightscale.com" -Headers @{"accept"="application/json"} | ConvertFrom-Json).components | Where-Object {$_.name -eq "Cloud Management API 1.5"}).status
@srpomeroy
srpomeroy / GetRightScaleAPIStatus.sh
Last active November 29, 2016 18:54
CURL/JQ example of retrieving RightScale API Status
curl -sS -H "accept: application/json" http://status.rightscale.com | jq '.components[] | select(.name == "Cloud Management API 1.5") | .status'
@srpomeroy
srpomeroy / Get-RightScaleSystemStatus.ps1
Created November 29, 2016 18:24
PowerShell example of retrieving RightScale system status
$headers = @{"accept"="application/json"}
$statusPageContent = Invoke-WebRequest -Uri "http://status.rightscale.com" -Headers $headers
$components = ($statusPageContent | ConvertFrom-Json).components
$componentObject = @()
foreach ($component in $components) {
$componentObject += [pscustomobject]@{
"name" = $component.name
"status" = $component.status
}
@srpomeroy
srpomeroy / Get-AllStorageAccountTotals.ps1
Last active October 29, 2016 02:24
Enumerates through all storage accounts in an Azure Resource Manage subscription and returns the total number of Storage Accounts, Containers and Blobs as well as the total time to execute.
$subsciptionId = "<Azure Subscription ID>"
Select-AzureRmSubscription -SubscriptionId $subsciptionId
$startTime = Get-Date
$storageAccounts = Get-AzureRmStorageAccount
$totalStorageAccounts = $($storageAccounts.Count)
$totalContainers = $null
$totalBlobs = $null
@srpomeroy
srpomeroy / RightScale_PowerShell_API_Examples.ps1
Created October 29, 2016 00:30
Examples on how to use PowerShell with RightScale API
# Provide API Refresh Token - http://docs.rightscale.com/cm/dashboard/settings/account/enable_oauth.html
$oauthRefreshToken = "<API_REFRESH_TOKEN>"
## Get a bearer access token from Cloud Management
$oauthUrl = "https://my.rightscale.com/api/oauth2"
$oauthHeaders = @{"X_API_VERSION"="1.5"}
$oauthBody = @{"grant_type"="refresh_token";"refresh_token"=$oauthRefreshToken}
$oauthResult = Invoke-RestMethod -Method Post -Uri $oauthUrl -Headers $oauthHeaders -Body ($oauthBody | ConvertTo-Json) -ContentType "application/json"
$accessToken = $oauthResult.access_token
param(
$Computer ='dc01.contoso.com',
$Minutes = -240
)
if ($Minutes -ge 0) {$Minutes = 0 - $Minutes}
$SelectOuput = @(
@{n='ComputerName';e={$_.MachineName}},
@{n='Time';e={$_.TimeCreated}},
#PowerShell
#This script will allow you to remotely enable RDP via PowerShell Remoting
$Server = Read-Host -Prompt "Name of server:"
Invoke-Command -ComputerName $Server -Credential (Get-Credential) -ScriptBlock {
Set-ItemProperty -Path 'HKLM:\SYSTEM\CurrentControlSet\Control\Terminal Server' -Name fDenyTSConnections -Value 0
Set-ItemProperty -Path 'HKLM:\SYSTEM\CurrentControlSet\Control\Terminal Server\WinStations\RDP-Tcp' -Name UserAuthentication -Value 1
Set-NetFirewallRule -DisplayGroup 'Remote Desktop' -Enabled True }