如何使用带数组的foreach循环加载脚本?

时间:2016-03-07 20:56:29

标签: powershell

我目前正在尝试使用for循环,路径和文件名数组通过PowerShell配置文件加载脚本。即使变量中的完整文件路径正确,并且可用命令显示在PowerShell窗口中,脚本也不会加载它们的功能。

注意:脚本在以这种方式. C:\scripts\script.ps1运行时会起作用。

$PublicScripts   = "\\fileserver\scripts"
$PersonalScripts = "C:\scripts"

$commandArrayPersonal = @("adremove-pc.ps1", "template.ps1")
$commandArrayPublic   = @("get-pc.ps1",
    "port-commands.ps1",
    "LaptopNameChangeScript\adrenamepc-csv.ps1",
    "LaptopNameChangeScript\PingPC-csv.ps1",
    "remove-pc.ps1")

. C:\scripts\adremove-pc.ps1

function loopsForCommand([string]$path, [array]$commands) {
    foreach ($command in $commands) {
        $pathCommand = "$path\$command"

        if ((Test-Path $pathCommand)) {
            . "$pathCommand"
            Write-Host $command
        } else {
            Write-Host "Unavaliable: " $command
        }
    }
}

"`r`n** *  *  * **`r`nScripts Available for use:`r`n"
loopsForCommand -path $PublicScripts -commands $commandArrayPublic
loopsForCommand -path $PersonalScripts -commands $commandArrayPersonal
"`r`n** *  *  * **`r`n"

编辑:在翻译中丢失了一些代码,删除了if($command.Contains("LaptopNameChangeScript")){以缩小问题范围。

1 个答案:

答案 0 :(得分:0)

函数调用需要以boost::uuids::uuid u = boost::uuids::random_generator()();

作为前缀
.