I found this script on this site and it works well when I run it locally but when I run it in a domain environment I this error. Tried everthing I found on this site and others to no avail... I have full access to the domain and there is a full Trust between my domain and the other. I can connect to the other computer via EventViewer but when I try and access the Application log I get the error of Access denied... if you look down the second block of code works when running from a .bat file using task Scheduler. i'm lost here, why would one code work and the other not? is there a way to use credentials in powershell?
Get-EventLog : The network path was not found.At C:\Scripts\EventLogGrab\ServerLogs.ps1:28 char:25
+ $AppLog = Get-EventLog <<<< -LogName Application -EntryType Error -computer $server -Newest 10
+ CategoryInfo : NotSpecified: (:) [Get-EventLog], IOException
+ FullyQualifiedErrorId : System.IO.IOException,Microsoft.PowerShell.Commands.GetEventLogCommand
$objExcel = New-Object -comobject Excel.Application $objExcel.visible = $False $objWorkbook = $objExcel.Workbooks.Add() $objSheet = $objWorkbook.Worksheets.Item(1) $objSheet.Cells.Item(1,1) = "Server" $objSheet.Cells.Item(1,2) = "LogName" $objSheet.Cells.Item(1,3) = "Time" $objSheet.Cells.Item(1,4) = "Source" $objSheet.Cells.Item(1,5) = "Message" $objSheetFormat = $objSheet.UsedRange $objSheetFormat.Interior.ColorIndex = 19 $objSheetFormat.Font.ColorIndex = 11 $objSheetFormat.Font.Bold = $True $DT2 = get-date -format MMddyyyy $DT = get-date $Dec1 = get-date $Dt.AddDays(-1) $DT $Dec1 $DT2 $row = 1 $servers = gc "C:\Scripts\EventLogGrab\servers.txt" Clear-Host foreach ($server in $servers) { $row = $row + 1 $AppLog = Get-EventLog -LogName Application -EntryType Error -computer $server -Newest 10 #$SecLog = Get-EventLog -LogName Security -EntryType Error -computer $server -Newest 5 -ea Silentlycontinue #$SysLog = Get-EventLog -LogName System -EntryType Error -computer $server -Newest 10 foreach ($Cat in $AppLog,$Syslog,$Seclog) { if ($cat -is [array]) { if ($AppLog -contains $cat[0]) {$Catname = "Application"} #if ($SecLog -contains $cat[0]) {$Catname = "Security"} if ($SysLog -contains $cat[0]) {$Catname = "System"} Foreach ($event in $cat) { $objSheet.Cells.Item($row,1).Font.Bold = $True $objSheet.Cells.Item($row,1) = $server $objSheet.Cells.Item($row,2) = $Catname $objSheet.Cells.Item($row,3) = $Event.TimeGenerated $objSheet.Cells.Item($row,4) = $Event.Source $objSheet.Cells.Item($row,5) = $Event.Message $row = $row + 1 } } } } $objSheetFormat = $objSheet.UsedRange $objSheetFormat.EntireColumn.AutoFit() $objSheetFormat.RowHeight = 15 $objWorkbook.SaveAs("C:\Scripts\EventLogGrab\EvtLogWorking\Workbook1_$DT2.xlsx") $Script = {C:\Scripts\EventLogGrab\CopytoIT_Share.bat} $Job = Invoke-Command $Script
cls
$PCName += @("Server1.domain.local") $DT2 = get-date -format MMddyyyy $DT = get-date $Dec1 = get-date $Dt.AddDays(-1) $DT $Dec1 $DT2 get-eventlog -LogName Application -computername $PCName -newest 20 -EntryType Error ` |Select-Object MachineName, EntryType, Message, TimeGenerated,Source|Where-Object {$_.Timegenerated -gt $Dec1} ` |export-csv "C:\Scripts\EventLogGrab\EvtLogWorking\ServerEvt_ComPlusLog_$DT2.csv" -NoTypeInformation