Skip to content

Instantly share code, notes, and snippets.

@altrive
altrive / Microsoft.PowerShellISE_profile.ps1
Last active February 7, 2023 07:11
Sample code to defer PowerShell modules loading.
#Register OnIdle event to load PS moduless.
Register-EngineEvent -SourceIdentifier ([Management.Automation.PsEngineEvent]::OnIdle) -MaxTriggerCount 1 -Action {
Import-Module TabExpansion++
#Import-Module FunctionExplorer
Import-Module VariableExplorer
Import-Module PSCodeAnalyzer.ISEAddin
Import-Module Altrive.ISEExtensions
#Remove current Job (No Need to get job result)
$EventSubscriber.Action | Remove-Job -Force -ErrorAction Ignore
@altrive
altrive / SpeechAPI.ps1
Last active December 24, 2015 01:19
Speech API test
#Requires -Version 3.0
function Main
{
[Threading.Thread]::CurrentThread.CurrentCulture = "ja-jp"
[Threading.Thread]::CurrentThread.CurrentUICulture = "en-us"
$sw = [Diagnostics.Stopwatch]::StartNew()
Write-Verbose ($LocalizedData.OperationStarted) -Verbose
@altrive
altrive / GetRelativeFilePath.ps1
Last active December 24, 2015 00:59
Get relative file path.
$basePath = [Environment]::GetFolderPath([Environment+SpecialFolder]::MyDocuments)
$targetPath = [Environment]::GetFolderPath([Environment+SpecialFolder]::AdminTools)
Write-Host ("Get relative path")
Write-Host ("From : {0}" -f $basePath)
Write-Host ("To : {0}" -f $targetPath )
Write-Host ("Result: {0}" -f $ExecutionContext.SessionState.Path.NormalizeRelativePath($targetPath, $basePath))
@altrive
altrive / Set-ISEStatusText.ps1
Created September 25, 2013 21:29
Sample Cmdlet to set PowerShell ISE status bar text
function Main
{
$sw = [Diagnostics.Stopwatch]::StartNew()
1..10 | % {
Set-ISEStatusText ("Step.{0}: Executing operation..." -f $_)
sleep 1
}
Set-ISEStatusText ("Elapsed: {0}[ms]" -f $sw.ElapsedMilliseconds) -Force
@altrive
altrive / Test
Created September 23, 2013 20:43
$sw = [Diagnostics.stopwatch]::StartNew()
sleep 1
Write-Host ("Elapsed: {0}[ms]" -f ($sw.ElapsedMilliseconds))
Write-Host ("Elapsed: {0}[ms]" -f ($sw.ElapsedMilliseconds))
function Install-PSModule
{
[CmdletBinding()]
param(
[Parameter(Mandatory)]
[string] $ModuleName,
[Parameter(Mandatory,ParameterSetName="Local")]
[string] $Path,
[ValidateSet("User","System","ProgramFiles","Local")]
[string] $Target = "User"
@altrive
altrive / Invoke-RestMethod_Bug.md
Last active January 30, 2018 21:31
When query RSS/ATOM/ODATA xml data souce by using Invoke-RestMethod cmdlet. returned only about half of items.

Summary

When query RSS/ATOM/ODATA xml data souce by using Invoke-RestMethod cmdlet. returned only about half of items.

Test Code

$requestUrl = "http://blogs.msdn.com/b/powershell/rss.aspx"
@altrive
altrive / Find-GitHubRepository.ps1
Last active November 12, 2019 16:21
List GitHub PowerShell repositories using GitHub Search API.
function Main
{
#Execute Query(Note:Github Search API return up to 1000 results for each search.)
$results = Find-GitHubRepository -Filter "language:powershell+created:>=2013-12-01&sort=stars" -Verbose
#Show Results
Write-Host ("Total Repositry Count : {0}" -f $results.total_count)
Write-Host ("Returned Repository Count: {0}" -f $results.items.Count)
$selectedItems = $results.items | select name, description, html_url, fork | Out-GridView -OutputMode Multiple
@altrive
altrive / Out-HtmlView.ps1
Created August 14, 2013 01:39
Cmdlet to show object tree in HtmlView
#TODO:support for non serializable object(example:PSCustomObject)
function Out-HtmlView
{
[CmdletBinding()]
param(
[Parameter()]
[int]$Depth = 2,
[Parameter(Mandatory,ValueFromPipeLine)]
$InputObject
)
@altrive
altrive / ShowDialogCrash.md
Created August 14, 2013 01:16
PowerShell crash when calling ShowDialog