Get-Item Problem

Welcome Forums General PowerShell Q&A Get-Item Problem

This topic contains 3 replies, has 2 voices, and was last updated by

 
Participant
1 year ago.

  • Author
    Posts
  • #83168

    Participant
    Points: 0
    Rank: Member

    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

    Participant
    Points: 0
    Rank: Member

    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

      Participant
      Points: 0
      Rank: Member

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

    • #83176

      Participant
      Points: 0
      Rank: Member

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

The topic ‘Get-Item Problem’ is closed to new replies.