Avatar of stressedout2004
stressedout2004 asked on

Powershell Tasks Executes and Nothing Happens

When I manually run the following code in power-shell ISE, this code  works fine.
Remove-PSDrive -Name Z
New-PSDrive –Name “Z” –PSProvider FileSystem –Root “\\1.1.1.1\csv” –Persist
get-childitem -path E:\CSV *.csv -recurse | move-item -destination Z:

Open in new window


I now add this code to a PS1 file  and create as a scheduled task referencing the powershell file (movefile.ps1).    The scheduled task completes successfully and no errors.    The CSV file is not moved from E to Z
Powershell

Avatar of undefined
Last Comment
stressedout2004

8/22/2022 - Mon
Jose Gabriel Ortega Castro

I think that the problem would be the " chars on the script they're different on ps. Try this one, if you copy code from the web make sure to use the correct chars.

Remove-PSDrive -Name Z
New-PSDrive –Name "Z" –PSProvider FileSystem –Root "\\1.1.1.1\csv" –Persist
Get-childitem -path "E:\CSV" -filter "*.csv" -recurse | Move-Item -destination "Z:"

Open in new window

ASKER
stressedout2004

Hello,  I tried your code and it worked in powershell ISE no problem.   The CSV file moved.
I saved the code as a powershell file and created scheduled task.     I run the scheduled tasks and it comeplted and the CSV file does not move.
ivan rosa

what is the error code for the task manager? furthermore what is the policy to run PS scripts looks like in your PC, are you "bypass"?
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck
Jose Gabriel Ortega Castro

There you go:
https://social.technet.microsoft.com/wiki/contents/articles/38580.configure-to-run-a-powershell-script-into-task-scheduler.aspx

I did that article some time ago and I use them for this kind of references, let us know if it worked
Qlemo

Make sure to run the script with a  valid user for the remote location. The script is using the task's credentials.
ASKER
stressedout2004

No Progress here with said advise from Jose Latest Link.     The task runs and nothing happens still.
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
Qlemo

Add a line like
Start-Transcript C:\Temp\PStask.log

Open in new window

at the top of the script to generate a log file, then run the task and review the file.
Jose Gabriel Ortega Castro

Corrected the "," for "." @Qlemo... and yes follow that :)

And check the Last Run state
ASKER
stressedout2004

I don't understand what this means sorry.  Corrected the "," for "."
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck
ASKER
stressedout2004

Host Application: C:\Windows\system32\WindowsPowerShell\v1.0\powershell.exe -file E:\CSV\Move_CSV.ps1
Process ID: 15220
**********************
Transcript started, output file is C:\temp\PStask.log
move-item : Cannot find drive. A drive with the name 'Z' does not exist.
At E:\CSV\Move_CSV.ps1:2 char:62
+  get-childitem -path "E:\CSV" -filter "*.csv" -recurse | move-item
-destinat ...
+
~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (Z:String) [Move-Item], DriveNot
   FoundException
    + FullyQualifiedErrorId : DriveNotFound,Microsoft.PowerShell.Commands.Move
   ItemCommand


PS>$global:?
True
**********************
Windows PowerShell transcript end
End time: 20190212003529
**********************
ASKER
stressedout2004

This seams to be working like this when the scheduled task runs now
Start-Transcript C:\temp\PStask.log
 Remove-PSDrive -Name Z
 New-PSDrive –Name “Z” –PSProvider FileSystem –Root “\\1.1.1.1\csv” –Persist
 get-childitem -path "E:\CSV" -filter "*.csv" -recurse | move-item -destination "\\1.1.1.1\csv"

Open in new window

ASKER CERTIFIED SOLUTION
Qlemo

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
ASKER
stressedout2004

This worked
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.