実行すると以下の様になり、暗黙的にOut-Defaultが呼び出されているのがわかる。
PS C:\> Write-Output "Hello World."
Called Out-Default | Value Type = string
Called Out-Default | Input value = Hello World.
Hello World.
# | |
# Install ADDS/GPMC/RSAT(ADTools) Components | |
# | |
Add-WindowsFeature AD-Domain-Services, GPMC, RSAT-ADDS, RSAT-AD-PowerShell | |
# | |
# Install New Domain Controller | |
# | |
Import-Module ADDSDeployment | |
$DomainName = "contoso.local" |
Import-Module ADDSDeployment | |
# Demote domain controller | |
$DomainName = "contoso.local" | |
$Cred = New-Object PSCredential "administrator@$DomainName",(ConvertTo-SecureString "P@ssw0rd" -AsPlainText -Force) | |
$Params = @{ | |
LocalAdministratorPassword = (ConvertTo-SecureString "P@ssw0rd" -AsPlainText -Force); | |
DemoteOperationMasterRole = $true; | |
RemoveDnsDelegation = $true; | |
DnsDelegationRemovalCredential = $Cred; | |
Confirm = $false; |
#################################################################### | |
## Copyright(c) Oracle Corporation 1998,2015. All rights reserved.## | |
## ## | |
## Specify values for the variables listed below to customize ## | |
## your installation. ## | |
## ## | |
## Each variable is associated with a comment. The comment ## | |
## can help to populate the variables with the appropriate ## | |
## values. ## | |
## ## |
#Requires -Version 4.0 | |
<# | |
.SYNOPSIS | |
指定したファイルのハッシュ値を検証します。 | |
.DESCRIPTION | |
指定したファイルのハッシュ値を-Hashパラメーターで指定された値と比較し、同一であれば$Trueを返します。 | |
.PARAMETER Path | |
ハッシュ値を検証するファイル名を指定します。 | |
.PARAMETER Hash |
# 文字列置換時にコールバックを使う | |
$RegEx = [Regex]"\p{IsHiragana}" | |
$RegEx.Replace("ざっくりひらがなをカタカナに変換する。", { [char]([int]($args[0].value[0])+0x60) } ) | |
# | |
# 変換結果 → ザックリヒラガナヲカタカナニ変換スル。 | |
# | |
# -Replace演算子ではスクリプトブロックを指定できたもののコールバックは使えなかった | |
# 単純にToStringした結果を渡してるだけっぽい。 | |
"ざっくりひらがなをカタカナに変換する。" -replace "(?<kana>\p{IsHiragana})", { [char]([int](${kana})+0x60) } |
<# | |
.Synopsis | |
昇格したPowerShellコンソールおよびISEを起動します。 | |
.DESCRIPTION | |
昇格したPowerShellコンソールおよびISEを起動します。 | |
コンソールの場合、元のコンソールからカレントパスを引き継ぎます。 | |
ISEの場合、現在開いているファイルを引き継ぎます。 | |
.PARAMETER ExitCurrentProcess | |
昇格したPowerShellコンソールおよびISE起動後に元のプロセスを終了するか否かを指定します。 | |
.PARAMETER Wait |
# BASE64 Encode | |
$FilePath = "C:\Windows\Web\Screen\img100.jpg" | |
$EncodedString = [Convert]::ToBase64String([IO.File]::ReadAllBytes($FilePath)) | |
# output | |
Write-Host """$FilePath"" was encoded in $($EncodedString.Length) words." | |
Write-Output $EncodedString | |
# BASE64 Decode | |
$FilePath = "C:\decode_img100.jpg" |
実行すると以下の様になり、暗黙的にOut-Defaultが呼び出されているのがわかる。
PS C:\> Write-Output "Hello World."
Called Out-Default | Value Type = string
Called Out-Default | Input value = Hello World.
Hello World.
このファンクションTest-BreakForEachObject
を実行すると、
PS C:\> Test-BreakForEachObject
Start function...
Start block...
1
2
3
End function.
function Aggregate-Object | |
{ | |
Param | |
( | |
[Parameter(Mandatory=$true, ValueFromPipeline=$true)] | |
[PSObject[]]$InputObject | |
) | |
Begin | |
{ | |
[PSObject[]]$ReturnObject = @() |