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
Avatar of Jose Gabriel Ortega Castro
Jose Gabriel Ortega Castro
Flag of Venezuela, Bolivarian Republic of image

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

Avatar of stressedout2004
stressedout2004

ASKER

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.
Avatar of ivan rosa
ivan rosa
Flag of United States of America image

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"?
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
Avatar of Qlemo
Qlemo
Flag of Germany image

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

ASKER

No Progress here with said advise from Jose Latest Link.     The task runs and nothing happens still.
Avatar of Qlemo
Qlemo
Flag of Germany image

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.
Corrected the "," for "." @Qlemo... and yes follow that :)

And check the Last Run state
Avatar of stressedout2004

ASKER

I don't understand what this means sorry.  Corrected the "," for "."
Avatar of stressedout2004

ASKER

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
**********************
Avatar of stressedout2004

ASKER

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
Avatar of Qlemo
Qlemo
Flag of Germany image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of stressedout2004

ASKER

This worked
Powershell
Powershell

Windows PowerShell is a task automation and configuration management framework from Microsoft, consisting of a command-line shell and associated scripting language built on the .NET Framework. PowerShell provides full access to the Component Object Model (COM) and Windows Management Instrumentation (WMI), enabling administrators to perform administrative tasks on both local and remote Windows systems as well as WS-Management and Common Information Model (CIM) enabling management of remote Linux systems and network devices.

27K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo