web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / PowerShell Move-Item i...
Power Apps
Unanswered

PowerShell Move-Item in PAD reports success but file remains in source folde

(0) ShareShare
ReportReport
Posted on by 4

¡Perfecto, Francisco! Acá tenés el mensaje listo para publicar en el foro de Power Automate Community o Microsoft Q&A. Solo tenés que copiar y pegar.

 
 

🧵 Título sugerido

 

PowerShell Move-Item in PAD reports success but file remains in source folder

 
 

💬 Mensaje completo para publicar

 

Hi everyone,

 

I'm encountering an issue with Power Automate Desktop (PAD) when executing a PowerShell script that should move a .xlsx file from the Downloads folder to a destination folder. The script runs without errors and logs a successful move, but the file remains in the source folder and does not appear in the destination.

 

✅ Context:

 

  • Platform: Power Automate Desktop (PAD)

  • OS: Windows 11

  • Script type: PowerShell via "Run PowerShell Script" action

  • Goal: Move a .xlsx file downloaded by the flow

  • Note: A separate .xlsm file is used for iteration logic and variable ranges, but is not involved in the move operation


  •  
 

🧪 Script used:

 
$origen = "%ArchivoOrigen%"      # .xlsx file downloaded by the flow
$destino = "%RutaDestino%"
$logPath = "%LogPath%"

$log = @()
$inicio = Get-Date

if (Test-Path $origen) {
    $log += "$($inicio.ToString('yyyy-MM-dd HH:mm:ss')) - Source file found: $origen"

    if (Test-Path $destino) {
        Remove-Item $destino
        $log += "$(Get-Date -Format 'yyyy-MM-dd HH:mm:ss') - Destination file already existed and was deleted: $destino"
    }

    Move-Item -Path $origen -Destination $destino
    $log += "$(Get-Date -Format 'yyyy-MM-dd HH:mm:ss') - File successfully moved to: $destino"
} else {
    $log += "$(Get-Date -Format 'yyyy-MM-dd HH:mm:ss') - ERROR: Source file does not exist: $origen"
}

$fin = Get-Date
$duracion = ($fin - $inicio).TotalSeconds
$log += "$($fin.ToString('yyyy-MM-dd HH:mm:ss')) - Total duration: $duracion seconds"

$log | Out-File -FilePath $logPath -Append
$log -join "`n"
 

🔍 Observations:

 

  • The .xlsx file exists before and after execution

  • Excel is not running (checked via Task Manager)

  • No errors are thrown in PAD

  • The script works correctly when run manually in PowerShell outside PAD

  • Logging and path validation are implemented


  •  
 

❓ Question:

 

Are there any known limitations or issues with Move-Item when executed from PAD that could prevent the file from being moved despite no error being thrown? Could this be related to execution context, virtualization, permissions, or caching?

 

Any insights or suggestions would be greatly appreciated.

 

Thanks in advance!

Francisco

 
 

 


Categories:
I have the same question (1)
  • stampcoin Profile Picture
    5,146 Super User 2026 Season 1 on at
    I think it's your script problem.
    You have below code, I guess you want to check if the file exist or not. 
    That is not correct to use it.... 
    if (Test-Path $destino) {
            Remove-Item $destino
            $log += "$(Get-Date -Format 'yyyy-MM-dd HH:mm:ss') - Destination file already existed and was deleted: $destino"
        }
    then you use below code for moving file, since above code deleted $destino, you will get a file created rather than a folder, which means it won't work ( move files to a file).
    Move-Item -Path $origen -Destination $destino
        $log += "$(Get-Date -Format 'yyyy-MM-dd HH:mm:ss') - File successfully moved to: $destino"
     
    So, I suggest that delete the if statement for Test-Path $destino, use 
    Move-Item -Path $origen -Destination $destino -Force
    it will overwrite the file if you have it in folder $destino.
     
    You can try this in PAD without create any variable, or run it in powershell ISE directly
    $origen = "C:\test\FromDownload\*.xlsx"      # .xlsx file in this folder (exclude subfolder)
    $destino = "C:\test\MoveTest"  #target folder
    $logPath = "C:\test\MoveLog\log.txt" # log file
    
    $log = @()
    $inicio = Get-Date
    
    if (Test-Path $origen) {
        $log += "$($inicio.ToString('yyyy-MM-dd HH:mm:ss')) - Source file found: $origen"
    
        
    
        Move-Item -Path $origen -Destination $destino -Force
        $log += "$(Get-Date -Format 'yyyy-MM-dd HH:mm:ss') - File successfully moved to: $destino"
    } else {
        $log += "$(Get-Date -Format 'yyyy-MM-dd HH:mm:ss') - ERROR: Source file does not exist: $origen"
    }
    
    $fin = Get-Date
    $duracion = ($fin - $inicio).TotalSeconds
    $log += "$($fin.ToString('yyyy-MM-dd HH:mm:ss')) - Total duration: $duracion seconds"
    
    $log | Out-File -FilePath $logPath -Append
    $log -join "`n"
     
    If you want log each file, use for each for example, but that is out of this community's topic.
     
  • CU11082013-1 Profile Picture
    4 on at
    Thanks for your input — I appreciate the suggestion.
    In my case, `$destino` is a folder path, and the `Test-Path` check is used to validate if a file with the same name already exists in that folder. If it does, I remove it to avoid conflicts before moving the new file.
    The issue I'm facing is specific to Power Automate Desktop (PAD): even when `Move-Item` reports success, the file remains in the source folder. I've validated this with detailed logging (timestamp, duration, and file existence checks before and after the move).
    ✅ The same script works perfectly in PowerShell ISE, but fails silently in PAD — which suggests a bug or context issue within PAD itself.
    🛠️ As a temporary workaround, I added a post-move validation. If the file wasn't moved, I fallback to `Copy-Item` + `Remove-Item`.
    Bug has been reported to Microsoft. If anyone else is facing this, feel free to share your PAD version and environment details.
    Thanks again for contributing!
  • stampcoin Profile Picture
    5,146 Super User 2026 Season 1 on at
     
    Your code doesn't work for me, that's why I doubted your code and made some changes.
    like I said your code deleted the destino folder, then when you uses move-item , it created a file instead a folder.
     
    My env:
    PAD:Version: 11.2507.134.0
    Powershell 7.4.11
    Window 11, Enterprise 23H2
     
     
  • CU11082013-1 Profile Picture
    4 on at
    Quiero agradecer profundamente al foro por el acompañamiento técnico y humano que he recibido durante el desarrollo de este proyecto de automatización multiempresa. 
    Gracias a los aportes, sugerencias y debates compartidos aquí, pude evolucionar desde flujos monolíticos hacia una arquitectura modular, con subs independientes, validaciones dinámicas y logging técnico en cada etapa. 
    Cada bug resuelto, cada función reconstruida y cada ajuste de lógica fue posible gracias al intercambio colaborativo que este espacio promueve. 
    Hoy el proceso cuenta con trazabilidad contable, control de auditoría y una estructura escalable que sigue creciendo. 
    A quienes respondieron con paciencia, con código, con ideas o simplemente con aliento: gracias. Este trabajo lleva su huella.
    Seguimos aprendiendo, compartiendo y mejorando. ¡Un abrazo a toda la comunidad! 
    Francisco

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Users!

Kudos to our 2025 Community Spotlight Honorees

Congratulations to our 2025 community superstars!

Congratulations to the March Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 519 Most Valuable Professional

#2
11manish Profile Picture

11manish 489

#3
Haque Profile Picture

Haque 327

Last 30 days Overall leaderboard