-
varキーワードによる変数宣言。変数宣言の場所がどこなのかわからないので。
-
classキーワードによるクラス構文。オブジェクト指向としての機能は基本不要だけど、変数と操作メソッドをセットで扱いたいことがある。
-
usingによるリソース破棄構文。try/finallyはネストが深くなりすぎるので。
-
三項演算子(?)とnull合体演算子(??)のサポート。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function New-IseCustomSnippet | |
| { | |
| param ( | |
| [ValidateNotNullOrEmpty()] | |
| [Parameter(Mandatory)] | |
| [string] $Title, | |
| [ValidateNotNullOrEmpty()] | |
| [string] $Description = "Description", | |
| [string] $Author = "", | |
| [Parameter(Mandatory)] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using System; | |
| using System.Runtime.InteropServices; | |
| public static class Program | |
| { | |
| [DllImport("libc")] | |
| static extern void printf(string format, int value); | |
| [DllImport("libc")] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $xmlDocument = [xml] "<root><elem>abcd</elem></root>" | |
| $xmlElement = $xmlDocument.root | |
| Invoke-Command localhost -ScriptBlock { | |
| $arg = $using:xmlDocument | |
| Write-Host ("Type={0}, Value={1}" -f $arg.GetType(), $arg.OuterXml) | |
| } | |
| Invoke-Command localhost -ScriptBlock { | |
| $arg = $using:xmlElement |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #global variable | |
| $global:ctx = @{ | |
| VmName = "Windows 8.1" | |
| Operation = "" | |
| Session = $null | |
| ComputerName = "TestPC" | |
| DomainJoin =@{ | |
| Name = "TEST.local" | |
| Credential = Get-SavedCredential -Id DomainAdmin |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #Write-Host "Load script files..." -ForegroundColor DarkGray | |
| $scriptFiles = Get-ChildItem "$PSScriptRoot\*.ps1" -Exclude "*.Tests.ps1" -Recurse | |
| foreach ($script in $scriptFiles) | |
| { | |
| #Write-Host "`tLoad script:" $script.Name -ForegroundColor DarkGray | |
| try | |
| { | |
| #TODO: Suppress $Error entry recorded after module loading completed(can't suppress inside psm1 module?) | |
| . $script.FullName |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $N = 1000 | |
| $services = Get-Service | |
| # 1.Powershell v2 'where' filtering syntax | |
| $sw = [Diagnostics.Stopwatch]::StartNew() | |
| foreach ($i in 1..$N) | |
| { | |
| $services | where { $_.Status -eq 'Running' } > $null | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $ErrorActionPreference = "Stop" | |
| function Main | |
| { | |
| if ($Host.Name -ne "Windows PowerShell ISE Host"){ | |
| return | |
| } | |
| $menus = $psISE.CurrentPowerShellTab.AddOnsMenu.Submenus | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $ErrorActionPreference = "Stop" | |
| function Main | |
| { | |
| $list = New-Object Collections.ArrayList | |
| foreach ($year in 2010..2013) | |
| { | |
| foreach ($month in 1..12) | |
| { | |
| $date = New-Object DateTime($year, $month, 1) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Set-StrictMode -Version Latest | |
| $ErrorActionPreference = "Stop" | |
| function Main | |
| { | |
| Add-TypeDefinition | |
| $sw = [Diagnostics.Stopwatch]::StartNew() | |
| $task1 = [PSContext]::StartNew({ Get-Process; sleep 2;}) |