Get-Item Problem

This topic contains 3 replies, has 2 voices, and was last updated by  Phil L 3 weeks, 1 day ago.

  • Author
    Posts
  • #83168

    Phil L
    Participant

    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.

  • #83170

    Richard Siddaway
    Moderator

    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
    
    • #83173

      Phil L
      Participant

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

    • #83176

      Phil L
      Participant

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

You must be logged in to reply to this topic.