daveyc
September 12, 2019, 3:19am
1
Hi all,
I’m trying to run another script from a main script as a different user then redirect the output to a file. I can’t work out what I’m doing wrong, the error is “the directory name is invalid”. Please help!
$logpath = "\\Network\scripts\logs"
$rand = get-random -maximum 50
$filepath = "\\Network\NewUserScript.ps1"
Start-Process powershell -Credential (get-credential) -ArgumentList '-noexit','-file',$filepath,'> $logpath\transcript$rand.txt'
Two issues…
The way how arguments are passed.
Output redirection
How to pass arguments.
Start-Process -FilePath PowerShell.exe -ArgumetnList "-NoExit -File $FilePath"
Redirection of output, you can use RedirectStandardOutput Parameter
Start-Process -FilePath PowerShell.exe -ArgumetnList "-NoExit -File $FilePath" -RedirectStandardOutput "$logpath\transcript$rand.txt"
daveyc
September 12, 2019, 6:47pm
3
Thanks for your reply kvprasoon, I didn’t know about the -redirectoutput switch. Now I have;
Start-Process powershell -Credential (get-credential) -ArgumentList "-noexit -file $filepath" -RedirectStandardOutput "$logpath\transcript$rand.txt"
Unfortunately this still yields the “directory name is invalid” error.
This should work. can you share the exact error you get.
daveyc
September 12, 2019, 10:29pm
5
It’s working now, the second user didn’t have the drive mapped the first user was running it from.
Thanks for the assistance.