知道如何解决此powershell错误吗?

知道如何解决此powershell错误吗?,powershell,Powershell,请原谅我这一次 我对power shell非常陌生 我昨天在这里发布了一个问题,要求任何人以编程方式帮助阅读iis日志的内容 目前还没有回应 所以,在苦心的谷歌搜索之后,我发现了一个powershell脚本,它看起来和我正在寻找的非常接近 当我试图执行它时,我得到了以下错误: Get-ChildItem : Cannot find path '\\servername\c$\windows\system32\logfiles\ W3SVC1' because it does not exist.

请原谅我这一次

我对power shell非常陌生

我昨天在这里发布了一个问题,要求任何人以编程方式帮助阅读iis日志的内容

目前还没有回应

所以,在苦心的谷歌搜索之后,我发现了一个powershell脚本,它看起来和我正在寻找的非常接近

当我试图执行它时,我得到了以下错误:

Get-ChildItem : Cannot find path '\\servername\c$\windows\system32\logfiles\
W3SVC1' because it does not exist.
我有理由相信这更像是一个权限问题,因为路径是存在的

有人知道如何在下面的脚本中添加用户名和密码吗

先谢谢你

#
# Script constants
#

$Server = 'myServer'
$Days = 1

Function Read-IISLog {
  [CmdLetBinding()]
  Param(
    [Parameter(ValueFromPipelineByPropertyName = $True)]
      [ValidateScript( { $_ | %{ Test-Path $_ } } )]
    [Alias("FullName")]
    [String[]]$Path
  )

  Process {

    $Path | ForEach-Object {
      $FullPath = (Get-Item $_).FullName
      $FileStream = New-Object IO.FileStream($FullPath, "Open", "Read", "ReadWrite")
      $StreamReader = New-Object IO.StreamReader($FileStream)

      For ($i = 0; $i -lt 4; $i++) {
        $Line = $StreamReader.ReadLine()
        If ($Line -Match '#Fields: ') {
          $Header = ($Line -Replace '#Fields: ').Split(' ', [StringSplitOptions]::RemoveEmptyEntries)
        }
      }
      Do {
        $Line = $StreamReader.ReadLine()
        If ($Line -NotLike "#*") {
          $Line | ConvertFrom-Csv -Delimiter ' ' -Header $Header
        }
      } Until ($StreamReader.EndOfStream)
    }

  }
}

$Output = @{}

$Server | ForEach-Object {
  Get-ChildItem "\\$_\c$\windows\system32\logfiles\W3SVC1" -Filter *.log | 
    Where-Object { $_.LastWriteTime -gt (Get-Date).AddDays(-$Days) } |
    Read-IISLog |
    Where-Object { $_."cs-uri-stem" -Match 'ActiveSync' } 
} | Select-Object `
    @{n='FirstSync';e={ [DateTime]::ParseExact("$($_.date) $($_.time)", "yyyy-MM-dd HH:mm:ss", $Null) }},
    @{n='LastSync';e={ [DateTime]::ParseExact("$($_.date) $($_.time)", "yyyy-MM-dd HH:mm:ss", $Null) }},
    @{n='ClientIP';e={ [Net.IPAddress]($_."c-ip") }},
    @{n='ClientDevice';e={ $_."cs(User-Agent)" }},
    @{n='AuthenticatedUser';e={ $_."cs-username" }},
    @{n='Mailbox';e={ $_."cs-uri-stem".Split("/")[2] }},
    @{n='DeviceId';e={ $_."cs-uri-stem".Split("/")[-1] }},
    @{n='DeviceType';e={ $_."cs-uri-stem".Split("/")[-2] }},
    @{n='SyncCount';e={ 1 }} |
  ForEach-Object {
    If (!$Output.Contains($_.DeviceId)) {
      $Output.Add($_.DeviceId, $_)
    } Else {
      If ($_.FirstSync -lt $Output[$_.DeviceId].FirstSync) { $Output[$_.DeviceId].FirstSync = $_.FirstSync }
      If ($_.LastSync -gt $Output[$_.DeviceId].LastSync)   { $Output[$_.DeviceId].LastSync = $_.LastSync }
      $Output[$_.DeviceId].SyncCount += 1
    }
  }
$Output.Values

这是解决这一问题的一次不顾一切的尝试,因为用户期待明天的演示。

感谢好心人的帮助

我找到了一个更好的解决方案,我可以更好地管理它-LogParser:


尝试以具有给定路径访问权限的其他用户身份运行脚本。请看一下:访问
\c$
共享需要计算机上本地管理员组的成员身份如果当前提供程序不是
文件系统
,则必须使用提供程序名称限定路径:
文件系统::\\\$\uc$\windows\system32\logfiles\W3SVC1
@Harsh,Mathias,PetSerAl,感谢大家的友好回复,但我如何将您的建议纳入该脚本Harsh/Mathias?您需要创建另一个powershell脚本,该脚本将在给定用户帐户下以访问网络驱动器的权限调用您的脚本。请参阅我发布的链接。