Product: PowerShell Studio 2021 (64 Bit)
Build: v5.8.193
OS: Windows 10 Education (64 Bit)
Build: v10.0.22000.0
So I have a Windows forms application that takes information from use and queries a MS SQL database for information.
The application uses the Button Job Start Control Set. The job works fine and Exports returned data to an Excel workbook in a remote share.
The completed job returns at text string with the file path for the Excel book:
$OutFile = "\\servername.sub.domain.com\Shared\F1\F2\F3\etc\csg266-MAT100-07_2021-08-26_09-12AM.xlsx"
There are no spaces in paths, but some underscores as in the above example. The server name is a FQDN.
If I run Start-Process "$OutFile" the Excel workbook opens in Excel correctly.
If I do the following it does not work:
If (Test-Path $OutFile) {Start-Process "$OutFile"} or (Test-Path "$OutFile")
As the If returns False.
However, the following does work:
If ([System.IO.File]::Exists($OutFile)){Start-Process "$OutFile"}
Test-Path with $OutFile = "\\servername.sub.domain.com\Shared\F1\F2\F3\etc\csg266-MAT100-07_2021-08-26_09-12AM.xlsx" works fine in Console 5.1, ISE and PS7.1.4 just not in this PSS application.
I have a work around using System.IO.File but wanted to know if this is a PSS issue and may be specifically related to the type of file?
Regards,
Pete
Possible issue with Test-Path in Windows forms application
Forum rules
DO NOT POST LICENSE NUMBERS, ACTIVATION KEYS OR ANY OTHER LICENSING INFORMATION IN THIS FORUM.
Only the original author and our tech personnel can reply to a topic that is created in this forum. If you find a topic that relates to an issue you are having, please create a new topic and reference the other in your post.
Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
DO NOT POST LICENSE NUMBERS, ACTIVATION KEYS OR ANY OTHER LICENSING INFORMATION IN THIS FORUM.
Only the original author and our tech personnel can reply to a topic that is created in this forum. If you find a topic that relates to an issue you are having, please create a new topic and reference the other in your post.
Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
- PGomersall
- Posts: 131
- Last visit: Thu Feb 15, 2024 12:14 pm
- Alexander Riedel
- Posts: 8479
- Last visit: Thu Mar 28, 2024 9:29 am
- Been upvoted: 37 times
Re: Possible issue with Test-Path in Windows forms application
AFAIK, Test-Path takes a file object as a parameter. If you want to specify a string you need to use the -path parameter.
PowerShell Studio does not run any different type of PowerShell. It is the same PowerShell. In a console you may have a case of runspace contamination that you do not see in a script though.
PowerShell Studio does not run any different type of PowerShell. It is the same PowerShell. In a console you may have a case of runspace contamination that you do not see in a script though.
Alexander Riedel
SAPIEN Technologies, Inc.
SAPIEN Technologies, Inc.
- PGomersall
- Posts: 131
- Last visit: Thu Feb 15, 2024 12:14 pm
Re: Possible issue with Test-Path in Windows forms application
Yes I understand that David, but explicitly adding -Path doesn't make any difference either and therefore doesn't explain why Test-Path -Path $OutFile fails and [System.IO.File]::Exists($OutFile) works, when all I change is the statements in the If evaluation in PSS.
- Alexander Riedel
- Posts: 8479
- Last visit: Thu Mar 28, 2024 9:29 am
- Been upvoted: 37 times
Re: Possible issue with Test-Path in Windows forms application
I will try to track David down and let him know.
I did some searching on this and it seems Test-Path has issues with UNC paths for a lot of folks. I'd suggest to contact the PowerShell peeps.
I did some searching on this and it seems Test-Path has issues with UNC paths for a lot of folks. I'd suggest to contact the PowerShell peeps.
Alexander Riedel
SAPIEN Technologies, Inc.
SAPIEN Technologies, Inc.
- PGomersall
- Posts: 131
- Last visit: Thu Feb 15, 2024 12:14 pm
Re: Possible issue with Test-Path in Windows forms application
Alex, my bad in last post - I meant you not David.
- Alexander Riedel
- Posts: 8479
- Last visit: Thu Mar 28, 2024 9:29 am
- Been upvoted: 37 times
Re: Possible issue with Test-Path in Windows forms application
I have been called worse things
Alexander Riedel
SAPIEN Technologies, Inc.
SAPIEN Technologies, Inc.
- PGomersall
- Posts: 131
- Last visit: Thu Feb 15, 2024 12:14 pm
Re: Possible issue with Test-Path in Windows forms application
I am sure Alex , but you haven't addressed my point in the post though.
Maybe - you did - UNC path issues? Maybe it is worse with files as opposed to say a folder?
I'll just use the .Net test.
Maybe - you did - UNC path issues? Maybe it is worse with files as opposed to say a folder?
I'll just use the .Net test.
- Alexander Riedel
- Posts: 8479
- Last visit: Thu Mar 28, 2024 9:29 am
- Been upvoted: 37 times
Re: Possible issue with Test-Path in Windows forms application
I, just as anyone else who seems to struggle with Test-Path failing for some unknown reason, have no idea.
Unfortunately I have no insight in the PowerShell implementation. It is open source now, but unfortunately I do not have the time to dive into that.
I found plenty of complaints online about it failing with UNC paths. Or mapped drives. Or both.
Some say it is worse for folders. Some say it is worse for files.
The consensus seems to be to use [System.IO.File]::Exists, which I would imagine is faster anyway.
Unfortunately I have no insight in the PowerShell implementation. It is open source now, but unfortunately I do not have the time to dive into that.
I found plenty of complaints online about it failing with UNC paths. Or mapped drives. Or both.
Some say it is worse for folders. Some say it is worse for files.
The consensus seems to be to use [System.IO.File]::Exists, which I would imagine is faster anyway.
Alexander Riedel
SAPIEN Technologies, Inc.
SAPIEN Technologies, Inc.