locked
Script to delete after RRS feed

  • Question

  • I have got a script and it works ok but I want to add more command to empty the folder when all these tasks finished but not sure how as I tried to add Remove-Item -path 'E:\id\Upload\* it doesn't seem to work. Could someone please advise? param ( $localPath = "E:\id\Upload\*.*", $backupPath = "E:\id\Archive", $backupPath2 = "E:\id\Archive2", ) try { # Connect $session.Open($sessionOptions) # Upload files, collect results $transferResult = $session.PutFiles($localPath, $remotePath, $False, $transferOptions) # Iterate over every transfer foreach ($transfer in $transferResult.Transfers) { # Success or error? if ($transfer.Error -eq $Null) { Write-Output "$(Get-Date) Upload of $($transfer.FileName) succeeded, moving to backup" >> $logFile # Upload succeeded, move source file to backup Move-Item $transfer.FileName $backupPath Move-Item $transfer.FileName $backupPath2 } } }
    Friday, November 8, 2019 4:36 PM

Answers

  • Hi,

    Thanks for your question.

    Do you get any error message? It woks for me to empty the folder.

    But it will need to confirm the delete operation.To skip it, you need to add "-confirm:$false" and "-recurse" parameter.

    Remove-Item "'E:\id\Upload\*" -Confirm:$false -Recurse

    Best regards,

    Lee


    Please remember to mark the replies as answers if they help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.

    • Marked as answer by moses004 Wednesday, November 13, 2019 4:39 PM
    Monday, November 11, 2019 8:24 AM

All replies

  • Please post code correctly and ask a clear question in this and other technical forums.

    Start by reading the following:


    \_(ツ)_/

    Friday, November 8, 2019 5:21 PM
  • Hi,

    Thanks for your question.

    Do you get any error message? It woks for me to empty the folder.

    But it will need to confirm the delete operation.To skip it, you need to add "-confirm:$false" and "-recurse" parameter.

    Remove-Item "'E:\id\Upload\*" -Confirm:$false -Recurse

    Best regards,

    Lee


    Please remember to mark the replies as answers if they help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.

    • Marked as answer by moses004 Wednesday, November 13, 2019 4:39 PM
    Monday, November 11, 2019 8:24 AM
  • Hi Lee,

    It seems to delete all the files. Does powershell command start from the top to down or down to up?

    for example

    get-childitem c:\*

    remove-childitem "'C:\" -Recurse

    how will the command execute in the powershell? is it ascending order or descending?

    Thanks,

    Wednesday, November 13, 2019 4:39 PM
  • Hi Moses,

    The default is ascending order. For example the first letter of file name by English alphabet [a-z].

    Also you can use "sort-object " to sorts objects by property values and determine the ascending order and  descending order.

    https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/sort-object?view=powershell-6

    Also, powershell don't have "remove-childitem" cmdlet, only have "remove-item" cmdlet.

    Best regards,

    Lee


    Please remember to mark the replies as answers if they help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.

    Thursday, November 14, 2019 2:53 AM