Tambourine作業メモ

主にスキル習得のためにやった作業のメモ。他人には基本的に無用のものです。

mkdirコマンド

PSでmkdirコマンドが使えるのか気になった

PS Function:\> mkdir

コマンド パイプライン位置 1 のコマンドレット mkdir
次のパラメーターに値を指定してください:
Path[0]:

あるっぽ

PS T:\PowerShell> Get-Command mkdir

CommandType     Name                            Definition
-----------     ----                            ----------
Function        mkdir                           ...
Application     mkdir.exe                       C:\cygwin/bin\mkdir.exe

関数らしい

PS T:\PowerShell> cd function:
PS Function:\> dir mkdir

CommandType     Name                            Definition
-----------     ----                            ----------
Function        mkdir                           ...

定義を見てみたい

   TypeName: System.Management.Automation.FunctionInfo

Name                MemberType     Definition
----                ----------     ----------
Equals              Method         bool Equals(System.Object obj)
GetHashCode         Method         int GetHashCode()
GetType             Method         type GetType()
ToString            Method         string ToString()
PSDrive             NoteProperty   System.Management.Automation.PSDriveInfo ...
PSIsContainer       NoteProperty   System.Boolean PSIsContainer=False
PSPath              NoteProperty   System.String PSPath=Microsoft.PowerShell...
PSProvider          NoteProperty   System.Management.Automation.ProviderInfo...
CmdletBinding       Property       System.Boolean CmdletBinding {get;}
CommandType         Property       System.Management.Automation.CommandTypes...
DefaultParameterSet Property       System.String DefaultParameterSet {get;}
Definition          Property       System.String Definition {get;}
Description         Property       System.String Description {get;set;}
Module              Property       System.Management.Automation.PSModuleInfo...
ModuleName          Property       System.String ModuleName {get;}
Name                Property       System.String Name {get;}
Options             Property       System.Management.Automation.ScopedItemOp...
OutputType          Property       System.Collections.ObjectModel.ReadOnlyCo...
Parameters          Property       System.Collections.Generic.Dictionary`2[[...
ParameterSets       Property       System.Collections.ObjectModel.ReadOnlyCo...
ScriptBlock         Property       System.Management.Automation.ScriptBlock ...
Visibility          Property       System.Management.Automation.SessionState...
HelpUri             ScriptProperty System.Object HelpUri {get=try...

このScriptBlockプロパティの中を見てやればいいんだろう

PS Function:\> $a = dir mkdir
PS Function:\> $a.ScriptBlock

<#
.FORWARDHELPTARGETNAME New-Item
.FORWARDHELPCATEGORY Cmdlet
#>
[CmdletBinding(DefaultParameterSetName='pathSet',
    SupportsShouldProcess=$true,
    SupportsTransactions=$true,
    ConfirmImpact='Medium')]
param(
    [Parameter(ParameterSetName='nameSet', Position=0, ValueFromPipelineByPrope
rtyName=$true)]
    [Parameter(ParameterSetName='pathSet', Mandatory=$true, Position=0, ValueFr
omPipelineByPropertyName=$true)]
    [System.String[]]
    ${Path},

    [Parameter(ParameterSetName='nameSet', Mandatory=$true, ValueFromPipelineBy
PropertyName=$true)]
    [AllowNull()]
    [AllowEmptyString()]
    [System.String]
    ${Name},

    [Parameter(ValueFromPipeline=$true, ValueFromPipelineByPropertyName=$true)]
    [System.Object]
    ${Value},

    [Switch]
    ${Force},

    [Parameter(ValueFromPipelineByPropertyName=$true)]
    [System.Management.Automation.PSCredential]
    ${Credential}
)
begin {


    try {
        $wrappedCmd = $ExecutionContext.InvokeCommand.GetCommand('New-Item', [S
ystem.Management.Automation.CommandTypes]::Cmdlet)
        $scriptCmd = {& $wrappedCmd -Type Directory @PSBoundParameters }
        $steppablePipeline = $scriptCmd.GetSteppablePipeline()
        $steppablePipeline.Begin($PSCmdlet)
    } catch {
        throw
    }


}
process {


    try {
        $steppablePipeline.Process($_)
    } catch {
        throw
    }


}
end {


    try {
        $steppablePipeline.End()
    } catch {
        throw
    }


}

無事見られた。中身はゆっくり確認する