我遇到了以下问题:在工作中,我必须编写一个脚本,使用远程PSSessions将文件从网络连接存储复制到几个客户端。该脚本正在域控制器上执行。
我认为远程会话和“复制文件”部分有问题。但我不知道是什么。
#SRC=Source Data to copy
$src1 = "\\NAS01\adm\sw\CAD\Dateien_fuer_SUPPORT_Verz\def_KOPA_Linie.lin"
$src2 = "\\NAS01\adm\sw\CAD\Dateien_fuer_SUPPORT_VerzSchlinie2.shx"
$src3 = "\\NAS01\adm\sw\CAD\Dateien_fuer_SUPPORT_Verz\Schlinie2.shp"
#PowerShell Check for AD-Service
Get-Service ad*
Get-Module
#Searching through AD for PC's called "WS"
$pc = Get-ADComputer -Filter 'name -like "WS" '
#New Powershell-Remotesession with the $pc
$session = New-PSSession -ComputerName $pc
#Check if the Directory exists, if it exists, copy the files inside
$Dir = "C:\Program Files\Autodesk\AutoCAD 2015\Support\"
if (Test-Path $Dir)
{
Copy-Items -FromSession $session -Path $src1 + src2 + src3 -Destination "C:\Program Files\Autodesk\AutoCAD 2015\Support\"
}
else
{
echo "tohuwabohu"
}发布于 2017-07-06 17:57:37
这将仅带回名称为WS的计算机:
$pc = Get-ADComputer -Filter 'name -like "WS" '您需要使用通配符与-like示例:如果您的计算机名是"WS-1234-abc",WS-2345-afgt。使用:
$pc = Get-ADComputer -Filter 'name -like "WS*"'您当前正试图打开一个没有计算机名的远程会话
您需要运行脚本的每一行,以查看是否获得了预期的输出。
Copy-item (no % s)不要求您首先打开远程会话。path参数将采用逗号分隔值。请参阅帮助复制-项目
[-path] <string[]> []告诉use我们可以使用逗号分隔值示例:
Copy-Item -Path $src1,$src2,$crs3 -Destination "C:\Program Files\Autodesk\AutoCAD 2015\Support\"https://stackoverflow.com/questions/44900883
复制相似问题