2016-10-26 29 views

答えて

1

以下PowerShellスクリプトは、モジュール(.psm1)を関数(.ps1)に分割します。

$ModuleName = 'Module1' #Specify the module name 
$SplittedFunctionPath = "D:\SplittedFunction\" #Specify Splitted function path 

#Import-Module 
Import-Module $ModuleName 

#Function to split the module and export it as functions 
Function Insert-Content 
{ 
    param ([String]$Path) 
    process 
    { 
    $(,$_; Get-Content $Path -ea SilentlyContinue) | Out-File $Path 
    } 
} 
$FunctionName = Get-Command -Module $ModuleName 
$path ="$SplittedFunctionPath" 
Foreach ($Function in $FunctionName.Name) 
{ 
    (get-command $Function).definition | out-file $Path\$Function.ps1 
    "Function $Function `n {" | Insert-Content $Path\$Function.ps1 
    "}" | Add-Content $Path\$Function.ps1 

} 
関連する問題