We help IT Professionals succeed at work.

Powershell Tasks Executes and Nothing Happens

stressedout2004
on
169 Views
Last Modified: 2019-07-01
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
Comment
Watch Question

Jose Gabriel Ortega CastroCEO Faru Bonon IT&Agency /Top-Rated Freelancer (Upwork)/Photographer
CERTIFIED EXPERT
Awarded 2018
Distinguished Expert 2018

Commented:
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

Author

Commented:
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.
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"?
Jose Gabriel Ortega CastroCEO Faru Bonon IT&Agency /Top-Rated Freelancer (Upwork)/Photographer
CERTIFIED EXPERT
Awarded 2018
Distinguished Expert 2018

Commented:
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"Batchelor", Developer and EE Topic Advisor
CERTIFIED EXPERT
Top Expert 2015

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

Author

Commented:
No Progress here with said advise from Jose Latest Link.     The task runs and nothing happens still.
Qlemo"Batchelor", Developer and EE Topic Advisor
CERTIFIED EXPERT
Top Expert 2015

Commented:
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 CastroCEO Faru Bonon IT&Agency /Top-Rated Freelancer (Upwork)/Photographer
CERTIFIED EXPERT
Awarded 2018
Distinguished Expert 2018

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

And check the Last Run state

Author

Commented:
I don't understand what this means sorry.  Corrected the "," for "."

Author

Commented:
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
**********************

Author

Commented:
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

"Batchelor", Developer and EE Topic Advisor
CERTIFIED EXPERT
Top Expert 2015
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Author

Commented:
This worked

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.