Tuesday 15 June 2010

windows - Scheduled Powershell Task, stuck Running -



windows - Scheduled Powershell Task, stuck Running -

i have problems when running powershell script in scheduled tasks. gets stuck in running, though transcript has logged out lastly row "done!" , looks has done want to. missing?

when running run in windows seems fine: powershell -file "d:\_temp\copy_bat\copy_one_reprint_folder.ps1"

seetings in task scheduler is:

run total priviliges run weither user logged on or not action, start programme powershell.exe -file "d:\_temp\copy_bat\copy_one_reprint_folder.ps1"

please see code below if needed.

# powershell reprint re-create first folder, sorted on lastmodified function timestamp { $ts = get-date -format s homecoming $ts } $fromdirectory = "d:\_temp\copy_bat" $todirectory = "d:\_temp\in_dummy" $extractguiddir = "" $doctypedir = "" # logging ######### $erroractionpreference="silentlycontinue" stop-transcript | out-null $erroractionpreference = "continue" start-transcript -path $fromdirectory\copy_one_reprint_folder.log.txt -append ########### write-host "" write-host (timestamp) "copy reprint extract started" write-host (timestamp) "============================" get-childitem -path $fromdirectory | ?{ $_.psiscontainer } | sort-object creationtime | ` where-object {$_.name -ne "_copied"} | ` select-object -first 1 | ` foreach-object{ write-host (timestamp) $_.name $extractguiddir = $_.fullname get-childitem -path $extractguiddir | ?{ $_.psiscontainer } | where-object {$_.name -match "purchase order \(-999999997\)" -or $_.name -match "logistics documents \(-1000000000\)" -or $_.name -match "specifications \(-999999998\)"} | ` foreach-object{ write-host (timestamp) " " $_.name } write-host "" write-host "these folders (document types), found not included" get-childitem -path $extractguiddir -exclude "logistics documents (-1000000000)", "purchase order (-999999997)", "specifications (-999999998)" | ?{ $_.psiscontainer } | ` foreach-object{ write-host (timestamp) " - " $_.name } write-host "" get-childitem -path $extractguiddir | ?{ $_.psiscontainer } | where-object {$_.name -match "purchase order \(-999999997\)" -or $_.name -match "logistics documents \(-1000000000\)" -or $_.name -match "specifications \(-999999998\)"} | ` foreach-object{ $temp_name = $_.fullname write-host (timestamp) "copying files " $_.fullname write-host (timestamp) " " $todirectory #copy-item ($_.fullname)\*.* $todirectory write-host (timestamp) " copying meta-files..." copy-item $temp_name\*.meta $todirectory -filter *.meta write-host (timestamp) " copying pdf-files..." copy-item $temp_name\*.pdf $todirectory -filter *.pdf if(test-path $temp_name\*.* -exclude *.meta, *.pdf) { write-host (timestamp) " warning/error not documents have been moved. pdfs moved!" write-host (timestamp) " check folder other document-types." } } move-item $extractguiddir $fromdirectory\_copied } write-host (timestamp) " done!" # stop logging stop-transcript

it solved.

it works, stupid me did not press f5(update) in task scheduler update status of task in gui.

actually quite did this, apparently not.

windows powershell scheduled-tasks

No comments:

Post a Comment