アセンブリをロードするスクリプト

アセンブリをロードするスクリプトを作ってみた。

Import-Assembly.ps1

param([string[]]$assemblyName)

$assemblyName += @($input)

if($args[0] -eq "-?" -or $assemblyName.Length -eq 0) {
    $commandName = [IO.Path]::GetFileNameWithoutExtension($MyInvocation.MyCommand.Name)
	Write-Host @"

Name:
    $commandName

Description:
    Imports Assembly file.

Usage:
    $commandName [[-assemblyName] <string[]>]

    -assemblyName <string[]>
        The Assembly's partial name or file name to import.
        
"@ -foregroundColor Yellow
	exit 1
}
# カレントディレクトリを変更する。
[Environment]::CurrentDirectory = (Get-Location).ProviderPath

$assemblyName | % {
    # 末尾が.dll又は.exeの場合は部分名でないと判断する。
    if($_ -match '.*(\.dll|\.exe)$') {
    	[Reflection.Assembly]::LoadFrom($_)
    } else {
    	[Reflection.Assembly]::LoadWithPartialName($_)
    }
}

使い方
PS > Import-Assembly Hoge.dll

PS > dir *.dll | Import-Assembly