【发布时间】:2021-03-29 13:38:01
【问题描述】:
我需要一些帮助来解决一件事。
我有一个从不同文件夹收集日志的脚本。它运行了几个月,但今天我发现它在读取某些文件夹时在 GCI 上失败了。
这是代码。
Function Process-Logs {
Param (
[Parameter(Mandatory=$True)]
[string] $Area
)
$PathFailed = "P:\IntegrationFileShare\failed\$Area"
$PathLogs = "P:\IntegrationFileShare\logs\$Area"
#$Dest = "C:\tmp\SCRPT\"
$Dest = 'C:\tmp\SCRPT\' +$Area + '\'
$compress_log = @{
Path = $Dest + '*.log'
CompressionLevel = "Fastest"
DestinationPath = ($Dest + "Logs_" + ($Area) + "_" + ($Date) + ".zip")
}
$compress_failed = @{
Path = $Dest + '*.log'
CompressionLevel = "Fastest"
DestinationPath = ($Dest + "Failed_" + ($Area) + "_" + ($Date) + ".zip")
}
gci -path $PathLogs -filter *$Date* | %{cp $_.pspath -destination $Dest}
if(Test-Path $compress_log.Path) {Compress-Archive @compress_log}
Remove-Item -Path $Dest* -Include *.log
gci -path $PathFailed -filter *$Date* |
%{cp $_.pspath -destination $Dest}
if(Test-Path $compress_failed.Path) {Compress-Archive @compress_failed}
Remove-Item -Path $Dest* -Include *.log
} #End Process-Logs
$Date = (get-date).AddDays(-1).ToString("yyyy-MM-dd")
#$Date = "2021-03-28"
Process-Logs -Area "Europe"
Process-Logs -Area "LATAM"
Process-Logs -Area "APAC"
Upload-Files
由于某种原因,我在运行完整脚本时一直收到 LatAm 和欧洲的此错误。
gci : The specified server cannot perform the requested operation.
At C:\tmp\SCRPT\LogDownloader_PROD_Sched.ps1:25 char:3
+ gci -path $PathLogs -filter *$Date* | %{cp $_.pspath -destination $ ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ReadError: (P:\IntegrationFileShare\logs\LATAM:String) [Get-ChildItem], IOException
+ FullyQualifiedErrorId : DirIOError,Microsoft.PowerShell.Commands.GetChildItemCommand
当我从 GCI 中删除 -Recurse 时,它开始在欧洲工作。这让我觉得可能有一个文件或文件夹深入我无法阅读,因为我不是管理员。但是同一行代码适用于每个地区,现在它适用于欧盟和亚太地区,但在拉美一直失败。
当我使用资源管理器转到此文件夹时,我没有任何问题,可以移动复制/移动/删除文件。 另外,我做了 Powershell->CD LatAm 文件夹并用过滤器做了 GCI - 它有效。 当我通过操作 GCI 运行脚本操作时。
仅当我运行完整脚本时它才会失败。 有人能告诉我我在这里缺少什么吗?
提前致谢。
【问题讨论】:
-
这是生产脚本?!?
-
这不是一个完整的脚本。它是负责收集日志的部分。但是,是的。为什么?
-
Ты пробовал запустить сессию PS интерактивно и прошерстить файлы в папках? Ошибка вываливается также?
-
如果你的意思是 PS-Session 所以它被阻止了。我希望我可以使用 PS 可以提供的所有方法)
标签: powershell