Student troubleshooting a script that mostly does as expected RRS feed

  • Question

  • The story - running a command like this in a script with the 2 other domain computers and the workstation where the script is run from, sends output to the file from only the other 2 computers so I am trying to narrow the problem down to what won't work.

    This works from the prompt, sending the output to the file on a remote share:

    PS C:\blah> invoke-command -computer win10 -script {Get-EventLog -LogName "security" -Newest 5} | Out-
    File \\server2\giggedy\mytest.txt

    This doesn't work from the prompt:

    PS C:\blah> Invoke-Command -Computer win10 -Script {Get-EventLog -LogName "security" -Newest 5 | Out-F
    ile \\server2\giggedy\mytest.txt -Append; Get-EventLog -LogName "System" -Newest 5 | Out-File \\server2\giggedy\mytest.t
    xt -Append}

    Access to the path is denied.

    Running the actual script like this:

    $compname = "server1","server2","win10"
    Invoke-Command -ComputerName $compname -Scriptblock {
    Get-EventLog -LogName "security" -Newest 5 | ConvertTo-Html | Out-File \\server2\giggedy\mytest.html -Append;
    Get-EventLog -LogName "System" -Newest 5 | ConvertTo-Html | Out-File \\server2\giggedy\mytest.html -Append

    sends the output to the file only from the servers and returns same "Access to path is denied" as above for the win10 computer.

    The actual error:

    Access to the path '\\server2\giggedy\mytest.html' is denied.
        + CategoryInfo          : OpenError: (:) [Out-File], UnauthorizedAccessException
        + FullyQualifiedErrorId : FileOpenFailure,Microsoft.PowerShell.Commands.OutFileCommand
        + PSComputerName        : win10

    Any insights?


    • Moved by Bill_Stewart Wednesday, February 14, 2018 6:00 PM Abandoned
    Sunday, December 31, 2017 1:29 AM

All replies

  • You should use Get-WinEvent instead of Get-Eventlog but anyway both commands support the parameter ComputerName. So you don't need Invoke-Command. Regardless of that if the access to the target folder or file is denied than you cannot write the output to it. 

    Best regards,


    • Edited by BOfH-666 Sunday, December 31, 2017 5:24 AM
    Sunday, December 31, 2017 1:39 AM
  • Second hop restriction.  You cannot access a third computer in a remote session.

     Out-File\\server2\giggedy\mytest.html -Append

    This is trying to access a third computer.


    Sunday, December 31, 2017 2:09 AM