【发布时间】:2020-10-13 12:14:21
【问题描述】:
所以我一直在家里编写这个脚本
Copy-Item "$env:SystemRoot\System32\Winevt\Logs\Security.evtx" "C:\CommFiles\LogFile_$(get-date -uformat %d-%m-%Y-%H.%M.%S).evtx"
if(-not $?) {
Write-Warning "Copy Failed"
} else {
Remove-Item "$env:SystemRoot\System32\Winevt\Logs\Security.evtx"
}
我知道它可以工作,因为我在家里使用它,它的文件路径与我在办公室使用的相同,但我不断收到此警告
Copy-Item : Could not find a part of the path 'C:\windows\System32\Winevt\Logs\Security.evtx'.
At line:1 char:1
+ Copy-Item "$env:SystemRoot\System32\Winevt\Logs\Security.evtx" "C:\Co ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Copy-Item], DirectoryNotFoundException
+ FullyQualifiedErrorId :
System.IO.DirectoryNotFoundException,Microsoft.PowerShell.Commands.CopyItemCommand
我怀疑我不在正确的目录中,但由于我对 powershell 的了解有限,我不确定适合我的情况的目录是什么。我正在使用此脚本将我的事件查看器日志复制到新的文件路径以进行组织
【问题讨论】:
-
出现问题的机器上运行的 PowerShell 和操作系统版本是什么?
-
@AdminOfThings 据我所知,这台机器正在运行最新版本的 PowerShell,操作系统版本是 windows 10 企业版 10.0.17763 Build 17763
-
如果你手动进入文件夹
C:\windows\System32\Winevt\Logs,你能看到Security.evtx文件。你的权限允许你复制它吗? -
@Theo 我有管理员权限,但这没关系,我使用下面的解决方案来获取正确的文件路径,它仍然做同样的事情。
标签: powershell directory filepath event-viewer