Link to home
Start Free TrialLog in
Avatar of jloomans
jloomansFlag for United States of America

asked on

Powershell move-item cmdlet not working in loop

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

Avatar of BSonPosh
BSonPosh
Flag of United States of America image

Does it just not move? Does it error? Have you tried adding the -verbose flag to move-item?
Avatar of jloomans

ASKER

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.
ASKER CERTIFIED SOLUTION
Avatar of BSonPosh
BSonPosh
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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.