# Get active File Explorer window $window = Get-Process | Where-Object { $_.MainWindowTitle -match "File Explorer" } if ($window) { # Access selected items in the active window $shell = New-Object -ComObject "Shell.Application" $selectedItems = $shell.Windows() | Where-Object { $_.HWND -eq $window.MainWindowHandle } | ForEach-Object { $_.Document.SelectedItems() } # Specify the destination folder $destinationFolder = "C:\Temp" # Move selected items to the temporary folder foreach ($item in $selectedItems) { $item.InvokeVerb("copy") Move-Item -Path $item.Path -Destination $destinationFolder } } else { Write-Host "No active File Explorer window found." }