Powershell command not work when compiled

This forum can be browsed by the general public. Posting is limited to current SAPIEN license holders with active maintenance and does not offer a response time guarantee.
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.
This topic is 1 year and 1 month old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Eanna_bearn
Posts: 20
Last visit: Thu Mar 09, 2023 4:36 am
Has voted: 1 time

Re: Powershell command not work when compiled

Post by Eanna_bearn »

I found something else

Here is execution policy on client :

Scope ExecutionPolicy
----- ---------------
MachinePolicy Unrestricted
UserPolicy Unrestricted
Process Undefined
CurrentUser Unrestricted
LocalMachine Unrestricted


With that if i launch .exe or .ps1 file it do not work. Same error "nom de répertoire non valide"

On same computer with the same standard user if i launch from powershell_ise my ps1 file with :

powershell.exe -file "T:\blocage internet.Export.ps1"

All working as expected.
Eanna_bearn
Posts: 20
Last visit: Thu Mar 09, 2023 4:36 am
Has voted: 1 time

Re: Powershell command not work when compiled

Post by Eanna_bearn »

I found solution !!!!

Code: Select all

Start-Process -FilePath "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe" -Credential $cred -ArgumentList $args -WorkingDirectory "C:\Windows\System32\WindowsPowerShell\v1.0\"
		
i just have to add -WorkingDirectory to my command ! :mrgreen:
User avatar
Alexander Riedel
Posts: 8478
Last visit: Tue Mar 26, 2024 8:52 am
Answers: 19
Been upvoted: 37 times

Re: Powershell command not work when compiled

Post by Alexander Riedel »

From your description you are launching the executable from a user folder (like 'My Documents') and the elevate to admin. That will make the user folder invalid.
Start-process the tries to use the current folder as current directory but has no rights to access it.
In general you should never place any applications that use elevation or another user during its process into a user specific folder, as files and folders
Alexander Riedel
SAPIEN Technologies, Inc.
Eanna_bearn
Posts: 20
Last visit: Thu Mar 09, 2023 4:36 am
Has voted: 1 time

Re: Powershell command not work when compiled

Post by Eanna_bearn »

Yes ! I dont know the trick before.

Thanks for your time helping me ;)
This topic is 1 year and 1 month old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.