我一直在尝试为 powershell 编写一个 cmd-let,它允许我运行它并将多个模块一次导入到我正在运行的任何脚本中。我以为我让它工作了,但现在它似乎停止了。我只是想知道这是否可能,似乎是这样。
为导入运行的命令:
Import-Module .\Tools\Import-Tools.ps1
$Tools = Import-Tools -ToolsDirectory \$PathToToolsDirectory
$Tools
导入功能:
Function Import-Tools
{
param
(
[Parameter(Mandatory=$true)]
[string]$ToolsDirectory
)
# Make sure the path is absolute (Borrowed from Michael Wanke)
if (!(Split-Path $ToolsDirectory -IsAbsolute))
{
$ToolsDirectory = Join-Path $pwd $ToolsDirectory
}
#Verifies that the tools directory exists.
while ((Test-Path -Path $ToolsDirectory) -eq $False)
{
$ToolsDirectory = Read-Host "Incorrect tool path entered. Please enter one now or exit"
}
#Create $Tools variable containing multiple lines for import.
foreach ($Tool in Get-Childitem $ToolsDirectory -Name -Filter "*.ps1")
{
[string] $Tools= $Tools + "`r`nImport-Module $ToolsDirectory\$Tool"
}
Write-Output $Tools
return $Tools
}
任何帮助或建议将不胜感激。