Share via

Problem with path in a Powershell script

Kaplan, Andrew H 226 Reputation points
2026-02-05T15:41:02.0866667+00:00

Hello.

I am trying to export the contents of a Custom View from the Event Viewer to a csv file. The first part of the process, for now, involves my interactively outputting to an xml file. The file is sent to the C:\Logs folder.

The next part is a Powershell script designed to output the contents of the xml file to csv format. The name of the script is mghroswl3loginsoutput.ps1, and the code is the following:

# Path to your exported Custom View XML

$xmlPath = "C:\Logs\mghroswl3logins.xml"

# Load the XML filter

[xml]$xmlFilter = Get-Content $xmlPath

# Get events matching the filter

$events = Get-WinEvent -FilterXml $xmlFilter

# Output to CSV

$events |

Select-Object TimeCreated, Id, LevelDisplayName, ProviderName, Message |

Export-Csv "C:\Logs\mghroswl3logins.csv" -NoTypeInformation -Encoding UTF8

The script is located in the C:\Logs folder. The command syntaxes that I have tried are the following:

.\mghroswl3loginsoutput.ps1

.\mghroswl3loginsoutput.ps1 mghroswl3logins.xml

The error message that I am getting is shown below:

Get-Content : Cannot find path 'C:\Logs\C\Logs\mghroswl3logins.xml' because it does not exist.

At C:\Logs\mghroswl3loginsoutput.ps1:5 char:19

+ [xml]$xmlFilter = Get-Content $xmlPath

+ ~~~~~~~~~~~~~~~~~~~~

+ CategoryInfo : ObjectNotFound: (C:\Logs\C\Logs\mghroswl3logins.xml:String) [Get-Content], ItemNotFoundE

xception

+ FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.GetContentCommand

Get-WinEvent : Cannot bind argument to parameter 'FilterXml' because it is null.

At C:\Logs\mghroswl3loginsoutput.ps1:8 char:35

+ $events = Get-WinEvent -FilterXml $xmlFilter

+ ~~~~~~~~~~

+ CategoryInfo : InvalidData: (:) [Get-WinEvent], ParameterBindingValidationException

+ FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Commands.GetWinEvent

Command

The path in the error message shows a wrong path. How can I correct it?

Windows for business | Windows Server | Networking | Other
0 comments No comments

6 answers

Sort by: Most helpful
  1. Kaplan, Andrew H 226 Reputation points
    2026-02-11T15:28:26.4533333+00:00

    Hello.

    I made the suggested changes, and the error message continues to appear.

    Was this answer helpful?


Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.