none
Could not find a part of the path error in schedulled powershell script RRS feed

  • Question

  • Hello!

    This works:

    'test' | out-file -encoding utf8 -filepath 'c:\scripts\test.txt'

    But this does not work (Error:Could not find a part of the path):

    'test' | out-file -encoding utf8 -filepath 'c:\windows\System32\Winevt\Logs\test.txt'

    task runs under domain admin account on domain controller.

    Thank you for any help!


    Wednesday, May 23, 2018 8:52 PM

Answers

  • The problem was that I have used 32-bit powershell .

    32 powershell does not see c:\windows\System32\Winevt\Logs\test.txt

    I have switched to 64 bit powershell and it has found c:\windows\System32\Winevt\Logs\test.txt.

    Friday, May 25, 2018 12:50 PM

All replies

  • Obviously the folder c:\scripts does not exist. You have to create it before you can write files to it.

    Best regards,

    (79,108,97,102|%{[char]$_})-join''

    Wednesday, May 23, 2018 9:41 PM
  • Problem with c:\windows\System32\Winevt\Logs\

    Thursday, May 24, 2018 8:40 AM
  • Do you have write access to this folder?

    Best regards,

    (79,108,97,102|%{[char]$_})-join''

    Thursday, May 24, 2018 8:56 AM
  • I run under domain admin and it works from IDE but does not work from task scheduler.
    Thursday, May 24, 2018 11:46 AM
  • Have you tried to check the security option "Run with highest privileges" in your task?
    Thursday, May 24, 2018 1:00 PM
  • Yes.
    Thursday, May 24, 2018 1:02 PM
  • This is not a support forum for the Task Scheduler service, unfortunately.

    -- Bill Stewart [Bill_Stewart]

    Thursday, May 24, 2018 2:08 PM
    Moderator
  • This is not question about TS - this is question about work powershell under TS.
    Thursday, May 24, 2018 2:36 PM
  • The problem is with the task scheduler settings since the script runs fine outside of the TS.


    \_(ツ)_/

    Thursday, May 24, 2018 3:00 PM
  • I should also note that you should never write or save files to the system folders.  These are owned by the system and should never be altered without direction from MS.


    \_(ツ)_/

    Thursday, May 24, 2018 3:05 PM
  • jrv is correct. If the script works outside of the Task Scheduler, then you don't have a scripting question but rather a different kind of problem.

    -- Bill Stewart [Bill_Stewart]

    Thursday, May 24, 2018 3:42 PM
    Moderator
  • The problem was that I have used 32-bit powershell .

    32 powershell does not see c:\windows\System32\Winevt\Logs\test.txt

    I have switched to 64 bit powershell and it has found c:\windows\System32\Winevt\Logs\test.txt.

    Friday, May 25, 2018 12:50 PM
  • That is because the folder does not exist in the 32 bit version of PowerShell.

    Look up information explaining how 32 bit on 64 bit works.

    To get to that folder on 32 bits use SysNative.

    c:\windows\Sysnative\Winevt\Logs

    To detect 32 on 64 use:

    [System.Environment]::Is64BitOperatingSystem


    \_(ツ)_/


    • Edited by jrv Friday, May 25, 2018 1:06 PM
    Friday, May 25, 2018 1:05 PM