View add-function.ps1
function Show-Hoge {
Write-Host 'Hoge'
}
$func = ${function:Show-Hoge}
Invoke-Command -Session $session -ScriptBlock {
New-Item -Path 'Function:\Show-Hoge' -Value $using:func > $null
Show-Hoge
}
View Find-UpdatedModule.ps1
$module = Get-Module -ListAvailable
# $module = Get-InstalledModule
$module |
Select-Object -Property 'Name', 'Version' |
Group-Object -Property 'Name' |
ForEach-Object -PipelineVariable 'm' {
$_.Group |
Sort-Object -Property 'Version' -Descending |
Select-Object -First 1
View Uninstall-OldModule.ps1
function Uninstall-OldModule {
[CmdletBinding(
SupportsShouldProcess,
ConfirmImpact = 'High')]
param(
[string] $Name,
[switch] $Force)
View Ssh.txt
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Ssh
Proxy
@completion-port-threads
@ip4-bind-port
@ip6-bind-port
@listeners
@session-pipe-prefix
@session-app-name
@session-pipe-timeout
@session-timeout
View common-parameters.ps1
function Get-CommonParameter {
[OutputType([Hashtable])]
[CmdletBinding(
SupportsShouldProcess)]
[System.Diagnostics.CodeAnalysis.SuppressMessage('PSShouldProcess', '')]
param(
View query1.ps1
# This query is valid. __InstanceCreationEvent class has TargetInstance property.
$query = @'
SELECT * FROM __InstanceCreationEvent WITHIN 1 WHERE TargetInstance ISA 'Win32_Process' AND TargetInstance.Name = 'cmd.exe'
'@
$evt = Register-CimIndicationEvent -Query $query -SourceIdentifier 'TestEvent' -Action {
$EventArgs | Get-Member -Force | Out-Default
$EventArgs | Format-List * | Out-Default
$e = $EventArgs.NewEvent
View coffee.cs
case (order)
{
case "Small Coffee":
return 5.0;
case "Small Coffee. please.":
return 3.0;
case "Hello, one small coffee please.":
return 1.75;
View New-Date.ps1
<#
.Synopsis
新規にDatetime型のオブジェクトを生成します。
.DESCRIPTION
新規にDatetime型のオブジェクトを生成します。
Get-Dateとは異なり現在時刻を基準とせず、未指定のパラメーターには初期値を割り当ててオブジェクトを生成します。
.OUTPUTS
Format パラメーターまたは UFormat パラメーターを使用した場合、Get-Date は文字列を返します。それ以外の場合は、DateTime オブジェクトが返されます。
.EXAMPLE
New-Date -Year 2016 -Month 3 -Day 7
View TestPSCmdletCommand.cs
// 本物の PSCmdlet 派生クラス
namespace CmdletTest
{
using System;
using System.Management.Automation;
[Cmdlet("Test", "PSCmdlet")]
public class TestPSCmdletCommand : PSCmdlet, IDisposable
{
protected IDatabaseConnection Connection { get; set; }
View Play-SpeechText.ps1
function Play-SpeechText {
[CmdletBinding(
DefaultParameterSetName = 'Default',
ConfirmImpact = [System.Management.Automation.ConfirmIMpact]::Medium)]
param(
[Parameter(Mandatory)]
[string] $ApiKey,