Author Posts

October 28, 2017 at 7:10 pm

I am trying to create a user input script whereby the user inputs the filename and the script will retrieve it on a remote server. The problem I am having is that the script keeps recursing through all files even though the specific file name is given. Here is the script:

$clm = Read-Host -prompt "Please input claim number (i.e. CLM123...)"
Write-Host "Contacting Server to find file"
invoke-command -computername 'server' -authentication negotiatewithimplicitcredential -scriptblock {Get-Childitem D:\CLM_MDB\ -filter $clm -Recurse -force}

Any help appreciated. The goal is to eventually just get the one file and move it to another server.

October 28, 2017 at 7:12 pm

you're not passing the variable containing the file name to invoke-command

invoke-command -computername 'server' -authentication negotiatewithimplicitcredential -scriptblock {Get-Childitem D:\CLM_MDB\ -filter $clm -Recurse -force} -argumentlist $cim

October 28, 2017 at 7:16 pm

Thanks for the reply! I tried to add the argument but it still sends over all recursed files.

October 28, 2017 at 9:09 pm

Turns out I needed to put the read-host INTO the scriptblock. THX!