0
请原谅我这一个。任何想法如何解决这个PowerShell错误?
我对电源外壳非常陌生。
昨天我在这里发布了一个问题,要求任何帮助以编程方式阅读iis日志的内容。
对此尚无回应。
所以,经过艰苦的搜索后,我发现一个Power Shell脚本,出现接近我在找什么。
当我试图执行它,我得到了以下错误:
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
这是一个绝望的尝试来解决这个问题,因为用户期待明天的演示。
尝试运行脚本谁有权访问给定的路径不同的用户。看看这个:http://stackoverflow.com/questions/17569678/run-powershell-script-using-different-credentials – Harsh
访问'\ c $'共享需要本地管理员组在本机上的成员资格 –
如果当前提供者不是'FileSystem',那么您必须使用提供者名称来限定路径:'FileSystem :: \\ $ _ \ c $ \ windows \ system32 \ logfiles \ W3SVC1'。 – PetSerAl