Pergunta

Basically from a input provided network path (e.g "\SERVER\SHARE\") i want to copy a specific Excel file to my desktop and run it automatically. Problem is that on my desktop there are other Excel files containing the letters ZZZ. Any ideas? Thank you!

$title = "Copy ZZZ to Desktop"
$zzzpath = read-host Paste ZZZ path here
copy-item "$zzzpath\*ZZZ*.xlsx" "C:\Users\%username%\Desktop\"
Invoke-Item C:\Users\%username%\Desktop\*ZZZ*.xlsx
Foi útil?

Solução

You can pipe the output of Copy-Item to your Invoke-Item, forcing the former to pass its output to the latter (via -PassThru):

$title = "Copy ZZZ to Desktop"
$zzzpath = Read-Host Paste ZZZ path here

Copy-Item "$zzzpath\*ZZZ*.xlsx" "C:\Users\%username%\Desktop\" -PassThru |
    Invoke-Item

Outras dicas

I think I would have done something like this:

$path = read-host "Enter/paste path"
$localdesktop = $env:userprofile, "\desktop" -join ("")

$xlsdoc = Get-ChildItem -path $path | where {$_.Name -match ".xlsx$" -and $_.Name -match "ZZZ"}

Copy-Item -path ($xlsdoc.FullName) -destination $localdesktop

$copiedxls = Get-ChildItem -path $localdesktop | where {$_.Name -match ".xlsx$" -and $_.Length -match $xlsdoc.Length}

Sleep -s 5

start $copiedxls.FullName

start $copiedxls

Edit: I use the '.lenght' property to compare filesize. This is how I determine wich "zzz.xlsx" to start.

Erlend.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top