将日志复制到网络共享位置不起作用



将日志复制到网络共享位置不起作用

我在网上找到了下面的脚本,并根据自己的需要对其进行了修改。该脚本按预期生成"logs.zip"到"SystemRoot\CCM\logs",但是当我尝试将"logs.zip"复制到网络共享驱动器时,它失败了

我正在使用以下命令将"logs.zip"复制到"\网络共享\软件\日志">

$Computerlogshare = “\networksharesoftwareLogs” + $env:Computername
Copy-Item $env:SystemRootCCMLogslogs.zip -Destination $Computerlogshare -force 

# Script to run SetupDiag to troubleshoot Windows 10 Setup
# Download SetupDiag.exe from https://go.microsoft.com/fwlink/?linkid=870142 and place in same directory as this script
# Get the CCM Logs location from registry
$LogLocation = Get-ItemProperty -Path "HKLM:SOFTWAREMicrosoftCCMLogging@Global" -Name LogDirectory | Select -ExpandProperty LogDirectory
#$LogLocation = "$env:SystemRootCCMLogs"
# Get the location we're running from (or use $PSScriptRoot)
$ScriptPath = Split-Path $MyInvocation.MyCommand.Path -Parent

# Check that .Net 4.6 minimum is installed
If (Get-ChildItem "HKLM:SOFTWAREMicrosoftNET Framework SetupNDPv4Full" | Get-ItemPropertyValue -Name Release | ForEach-Object { $_ -ge 393295 })
{
Try
{
Start-Process -FilePath "$ScriptPathSetupDiag.exe" -ArgumentList "/Output:$LogLocationSetupDiagResults.log" -Wait -ErrorAction Stop
}
Catch
{
"[ERROR] There was an error starting SetupDiag.exe: $_" | Out-file -FilePath "$LogLocationSetupDiagResults.log" -Force 
}
}
Else
{
"[ERROR] .Net Framework 4.6 is required to run SetupDiag.exe" | Out-file -FilePath "$LogLocationSetupDiagResults.log" -Force
}
$Computerlogshare = “\networksharesoftwareLogs” + $env:Computername
Copy-Item $env:SystemRootCCMLogslogs.zip -Destination $Computerlogshare -force 

首先,不要在代码中使用卷曲的"智能引号"并用直引号替换它们。
然后,您使用"\networksharesoftwareLogs" + $env:Computername连接路径,这将导致\networksharesoftwareLogsYourMachineName.

我的猜测是您需要使用连接路径,因此生成的目标路径将变为
\networksharesoftwareLogsYourMachineName。 您需要检查该路径是否存在,如果没有,则需要在执行Copy-Item之前创建它。

像这样:

$Computerlogshare = Join-Path -Path "\networksharesoftwareLogs" -ChildPath $env:Computername
if (!(Test-Path -Path $Computerlogshare -PathType Container)) {
New-Item -Path $Computerlogshare -ItemType Directory -Force | Out-Null
}
Copy-Item "$env:SystemRootCCMLogslogs.zip" -Destination $Computerlogshare -Force 

希望有帮助

您可以尝试将路径更改为:

$Computerlogshare = Join-Path -Path "Microsoft.Powershell.CoreFileSystem::\networksharesoftwareLogs" -ChildPath $env:Computername

最新更新