Skip to content

Instantly share code, notes, and snippets.

@altrive
altrive / PowerShellv4_DynamicKeyword.md
Last active August 3, 2023 02:28
Test code of PowerShell v4 Dynamic Keyword

Define DynamicKeyword

Define DynamicKeyword 'ExecTest'

Note: Don't copy&paste from following code. PowerShell SyntaxHighlighter remove some lines. Instead, use RAW view.

#Requires -Version 4.0
Set-StrictMode -Version Latest
@altrive
altrive / PowerShellSyntaxHighlighterTest.md
Last active December 19, 2015 02:59
PowerShell Syntax Highlighter remove lines in some condition?.

Raw Text

START
::Test
[test]
test]::
[test::
[test]:
[test]::
@altrive
altrive / Get-EventLogError.ps1
Last active November 12, 2019 16:22
PowerShell utility function to find EventLog errors.
function Get-EventLogError
{
[CmdletBinding()]
param(
[Parameter(Mandatory,ParameterSetName="FromLastBootupTime")]
[switch] $FromLastBootupTime,
[Parameter(Mandatory,ParameterSetName="FromLastQueryTime")]
[switch] $FromLastQueryTime,
[Parameter(Mandatory,ParameterSetName="Range")]
[DateTime] $From,
@altrive
altrive / SavedCredential.ps1
Last active October 9, 2020 09:38
Credential management utilities for PowerShell
#Requires -Version 3
#Credential file path
$script:CredentialsFile = Join-Path $env:TEMP "SavedCredentials\Credentials.xml"
function Set-SavedCredential()
{
[CmdletBinding()]
param(
[Parameter(Mandatory)]
@altrive
altrive / Test-NetConnection.Tests.ps1
Last active November 12, 2019 16:22
PowerShell v4 new cmdlet "Test-NetConnection"
#if ComputerName is not supplied. Connect to "internetbeacon.msedge.net" by default
Test-NetConnection
#Test ping(ICMP protocol)
Test-NetConnection "google.com"
#Ping with TraceRoute
Test-NetConnection "google.com" -TraceRoute
#Set Remote ComputerName
@altrive
altrive / PSRemotingMemo.md
Last active December 20, 2015 04:19
PSRemotingメモ

1.PSSessionの作り方

PSSessionは同時接続数の制限があるので、毎回作成してるとすぐに枯渇します。 このためセッション名を付与し、再利用可能であれば使いまわします。

以下、接続サンプル

#Session parameter
$params=@{
    ComputerName   = $ipAddress
@altrive
altrive / ShowDialogCrash.md
Created August 14, 2013 01:16
PowerShell crash when calling ShowDialog
@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 / 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 / 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"