Powershell move-item cmdlet not working in loop

Posted on 2008-11-03
Medium Priority
Last Modified: 2013-11-10
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

Question by:jloomans
  • 2
  • 2
LVL 18

Expert Comment

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

Author Comment

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.
LVL 18

Accepted Solution

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

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

Author Comment

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.

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
AngularJS web development a very simple procedure. So, to put it, in short, AngularJSā€™ stand out features are ā€“ Two-way data binding, MVC structure, directives, templates, dependency injections and testing.
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in aā€¦
Screencast - Getting to Know the Pipeline

624 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