Skip to content

Instantly share code, notes, and snippets.

View krymtkts's full-sized avatar
🤘

KURIYAMA Takatoshi krymtkts

🤘
View GitHub Profile
@krymtkts
krymtkts / Test-ConsoleWindowWithoutBufferCleaning.ps1
Last active January 20, 2024 08:14
Test-ConsoleWindowWithoutBufferCleaning
# test script for interactive console window.
# currently cannot prevent mouse scrolling.
function Test-ConsoleWindowWithoutBufferCleaning {
# backup cursor x position.
$x = [Console]::CursorLeft
# add lines to the end of the screen for scrolling using the PSReadLine method.
# https://github.com/PowerShell/PSReadLine/blob/e57f7d691d8df8c1121fddf47084f96aea74a688/PSReadLine/DisplayBlockBase.cs#L17-L24
$h = [Console]::WindowHeight
0..($h - 1) | ForEach-Object { [Console]::Write("`n") }
param (
[Parameter(Mandatory,
Position = 0,
ValueFromPipeline,
ValueFromPipelineByPropertyName)]
[string]
$WorkGroup,
[Parameter(Mandatory,
Position = 1,
<#
.SYNOPSIS
Download Google Sheet as CSV.
.DESCRIPTION
Download Google Sheet as CSV using GCP OAuth Client.
.PARAMETER OAuthClientSecretsPath
The path to the JSON file for the OAuth 2.0 Client Secrets created on GCP.
Get-IAMUsers | ForEach-Object {
do {
$j = Request-IAMServiceLastAccessedDetail -Arn $_.Arn
Start-Sleep -Seconds 1
$r = Get-IAMServiceLastAccessedDetail -JobId $j
} until (
$r.JobStatus.Value -eq 'COMPLETED'
)
$d = $r.ServicesLastAccessed | Sort-Object -Descending -Property LastAuthenticated | Select-Object -First 1
[PSCustomObject]@{
@krymtkts
krymtkts / New-CWGraphSource.ps1
Created January 23, 2023 03:17
generate CloudWatch graph souce for IOPS / Throughput of EBS.
[CmdletBinding()]
param (
[Parameter(Mandatory)]
[ValidateNotNullOrEmpty()]
[string[]]
$VolumeIds,
[Parameter(Mandatory)]
[ValidateNotNullOrEmpty()]
[ValidateSet('IOPS', 'Throughput')]
[string]
@krymtkts
krymtkts / scripts-for-virtualbox.ps1
Last active October 23, 2022 07:15
Scripts for VirtualBox. I am not currently using it, but for those who need it.
function Start-VBoxMachine() {
vboxmanage list vms | Select-Pocof -CaseSensitive | Out-String -Stream | Select-String -Pattern '\{(.+)\}' | ForEach-Object { vboxmanage startvm ($_.Matches[0].Groups['1'].Value) --type headless }
}
function Stop-VBoxMachine() {
vboxmanage list runningvms | Select-Pocof -CaseSensitive | Out-String -Stream | Select-String -Pattern '\{(.+)\}' | ForEach-Object { vboxmanage controlvm ($_.Matches[0].Groups['1'].Value) poweroff }
}
function Get-RunningVBoxMachines() {
vboxmanage list runningvms
# AWS.Tools.* modules must be imported first to get all property information.
Get-Module -Name *AWS* | Import-Module
Get-Command *Tag* | Where-Object -Property Source -Like '*aws*' | ForEach-Object {
[pscustomobject]@{
Name = $_.Name
TagParameterType = $_.Parameters.Values | Where-Object -Property Name -Like '*tag*' | Select-Object -ExpandProperty ParameterType
}
} | Where-Object -Property TagParameterType -NE $Null | Group-Object TagParameterType
@krymtkts
krymtkts / Get-EC2InstanceTypeHistory.ps1
Last active July 19, 2022 08:44
get hashtable of EC2 instance type history from https://instancetyp.es.
$timeline = Invoke-RestMethod -Method Get https://instancetyp.es/timeline.json
$releases = $timeline.instances | ForEach-Object {
[pscustomobject]@{
instanceType = ($_.instance_type -split '\.')[0]
releaseYear = $_.release_year
}
} | Group-Object -Property instanceType | ForEach-Object {
$_.Group[0]
} | Group-Object -Property releaseYear
@krymtkts
krymtkts / converterplus.js
Created March 7, 2022 06:20
Patched version of converterplus.js of evermonkey.
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
@krymtkts
krymtkts / return-to-the-previous-context-menu.ps1
Created February 4, 2022 03:06
Return to the previous context menu in Windows 11.
$path = 'HKCU:\Software\Classes\CLSID\{86ca1aa0-34aa-4e8b-a509-50c905bae2a2}\InprocServer32'
New-Item -Path $path -Force
Split-Path $path -Parent | Get-ChildItem
Set-ItemProperty -Path $path -Name '(Default)' -Value ''
Get-ItemProperty $path
Stop-Process -Name explorer -Force