Solved

Powershell move-item cmdlet not working in loop

Posted on 2008-11-03
4
1,515 Views
Last Modified: 2013-11-10
Hi,
I'm developing a Powershell script which will copy data files and run them threw a Powershell script.  The last line in the loop of the script is to move the particular CSV file to a different folder.  This is not working in the script.  Can someone take a look and see if there is a coding error?

Please note that this script is using cmdlets from the Netcmdlets script.  Thanks.

#Powershell Script within Netcmdlets profile:
 

#    $LogDirectory = "$Env:temp"

        $LogDirectory = "C:\EL\RPSCSVParser\FromBanner\logs\"
 

get-ftp -server mylinuxserver -user myuser -password mypassword -ssh -force -path /misc/path/*.csv | foreach-object -process {

get-ftp -server mylinuxserver -user myuser -password mypassword -ssh -force -path "/misc/path/" -remotefile ($_.Filename) -localfile ("C:\misc\path\" + $_.Filename) 

send-ftp -server mylinuxserver -user myuser -password mypassword -ssh -force -path "/misc/path/" -remotefile ($_.Filename) -rename ("/misc/path/Processed" + $_.Filename)

Write-Output ("Processing file: " + $_.Filename)
 

$Username = "mptcmanage@student.morainepark.edu"

$Password = ConvertTo-SecureString 'l0pht2600' -AsPlainText -Force

$cred = New-Object System.Management.Automation.PSCredential $Username, $Password

c:\misc\path\CSV_Parser_wErrorLogging.PS1 -UsersFile ("C:\misc\path\" + $_.Filename) -RemoteURL https://ps.exchangelabs.com/powershell -LiveCredential $cred -LogDirectory "C:\misc\path\logs\"
 

mv ("C:\misc\path\" + $_.Filename) (C:\misc\path\Processed) -force

Write-Output ("Moved file: " + $_.Filename)

}

Open in new window

0
Comment
Question by:jloomans
  • 2
  • 2
4 Comments
 
LVL 18

Expert Comment

by:BSonPosh
ID: 22867299
Does it just not move? Does it error? Have you tried adding the -verbose flag to move-item?
0
 

Author Comment

by:jloomans
ID: 22867738
I have added -verbose behind the command.  It does not move.  There is no output in the Powershell window to indicate the command was carried out.
0
 
LVL 18

Accepted Solution

by:
BSonPosh earned 125 total points
ID: 22867764
That is odd... try this

move-item "C:\misc\path\$($_.Filename)" "C:\misc\path\Processed" -force -verb
0
 

Author Comment

by:jloomans
ID: 22868143
I found a line in the script that is called from this script that broke the loop.  This line was commented and now this script works well include the move-item command.

Personally, I prefer the way you constructed this line of code better than my own.  Thanks.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
java continue statement 10 75
wordcount challenge 11 78
What is Python programming? 3 68
C Programming - If Statement 8 51
Here we come across an interesting topic of coding guidelines while designing automation test scripts. The scope of this article will not be limited to QTP but to an overall extent of using VB Scripting for automation projects. Introduction Now…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now