gpt4 book ai didi

powershell - 找不到接受参数 '\*'的位置参数

转载 作者:行者123 更新时间:2023-12-03 00:01:07 31 4
gpt4 key购买 nike

我有许多Web服务,试图使用PowerShell在DEV服务器上安装。我想在脚本中包括一个部分,该部分将所有文件和文件夹从暂存区复制到DEV服务器上的相应文件夹。

为此,我创建了两个并行的字符串数组-一个包含暂存文件夹的直接文件路径,另一个包含DEV服务器上每个文件夹的名称(我使用其他两个变量来存储其余的目录)。

我想创建一个for循环,并简单地遍历两个数组以完成从暂存到开发服务器的文件/文件夹传输。但是,当循环运行时,copy-item命令每次都会给出此错误

Copy-Item : A positional parameter cannot be found that accepts argument '*'.



如果我决定不使用循环,错误就会消失并且文件会正确传输。 PowerShell刚开始只有几天,所以我不确定正在发生什么/无法在网络上找到特定于此的任何东西。

变量
#web services
$periscopeWebServices = "periscopeWebServices"
$periscopeRetrieveComments = "periscopeRetrieveComments"
$periscopeRetrieveGeneral = "periscopeRetrieveGeneral"
$periscopeRetrieveMasterSubs = "periscopeRetrieveMasterSubs"
$periscopeRetrieveProducers = "periscopeRetrieveProducers"
$periscopeRetrieveProfiles = "periscopeRetrieveProfiles"
$periscopeRetrieveRelationships = "periscopeRetrieveRelationships"
$periscopeSearch = "periscopeSearch"
$periscopeServicesArray = @($periscopeRetrieveComments, $periscopeRetrieveGeneral,
$periscopeRetrieveMasterSubs, $periscopeRetrieveProducers,
$periscopeRetrieveProfiles, $periscopeRetrieveRelationships,
$periscopeSearch)


#staging areas
$stagingComments = "\\install\PeriscopeServices\periscopeWebServices\periscopeRetrieveComments"
$stagingGeneral = "\\install\PeriscopeServices\periscopeWebServices\periscopeRetrieveGeneral"
$stagingMasterSubs = "\\install\PeriscopeServices\periscopeWebServices\periscopeRetrieveMasterSubs"
$stagingProducers = "\\install\PeriscopeServices\periscopeWebServices\periscopeRetrieveProducers"
$stagingProfiles = "\\install\PeriscopeServices\periscopeWebServices\periscopeRetrieveProfiles"
$stagingRelationships = "\\install\PeriscopeServices\periscopeWebServices\periscopeRetrieveRelationships"
$stagingSearch = "\\install\PeriscopeServices\periscopeWebServices\periscopeSearch"
$stagingArray = @($stagingComments, $stagingGeneral, $stagingMasterSubs, $stagingProducers
$stagingProfiles, $stagingRelationships, $stagingSearch)

#server variables
$domain = "InsideServices.dev.com"
$directory = "E:\webcontent"
$domainpath = "$directory\$domain"

循环-对“复制项” 引发错误
#copy files
Write-Host "Copying Files" -ForegroundColor Yellow
For ($i=0; $i -lt $periscopeServicesArray.Length; $i++)
{
Write-Host "Copying $($periscopeServicesArray[$i])" -ForegroundColor Yellow
if(Test-Path -path "$domainpath\$periscopeWebServices\$($periscopeServicesArray[$i])")
{
copy-item -Path $($stagingArray[$i])\* -Destination $domainpath\$periscopeWebServices\$($periscopeServicesArray[$i]) -recurse -Force
}
}

成功的复制项目命令
copy-item -Path $stagingComments\* -Destination $domainpath\$periscopeWebServices\$periscopeRetrieveComments -recurse -Force

最佳答案

我认为这是因为您在循环内部而不是外部使用了子表达式$()。试试这些:

"$($stagingArray[$i])\*"

将其用引号引起来会使它以字符串的形式评估整个事物。
$($stagingArray[$i]) + '\*'

这将把子表达式的结果和包含 \*的字符串连接起来。

关于powershell - 找不到接受参数 '\*'的位置参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28374419/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com