how to get the correct path

Welcome Forums General PowerShell Q&A how to get the correct path

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

 
Participant
2 years ago.

  • Author
    Posts
  • #64332

    Participant
    Points: 0
    Rank: Member

    this is my script:

    cmdkey /add:182.158.8.10\zonghang_data /user:xxxxxxx /pass:xxxxx

    $b = '\\182.158.8.10\zonghang_data'

    $fin = Get-Childitem $b -Directory | Sort-Object LastAccessTime -Descending | select -First 1

    Copy-Item $fin $dis -Recurse

    but when i run

    COPY-ITEM..i cant get the correct path about of the $fin!!

    the $fin show the path is " c:\ " not the server directory!

    help!

  • #64333

    Participant
    Points: 0
    Rank: Member

    Your code is fine but if $fin doesn't show the correct path then it's fairly easy to troubleshoot. Does the below line produces the correct folder?

    Get-Childitem $b -Directory | Sort-Object LastAccessTime -Descending | select -First 1
    • #64338

      Participant
      Points: 0
      Rank: Member

      yes..when i run the commend can get the correct folder!

      then i put the object to the variable and use the Copy-ITEM commend , it cant get the correct folder!

      the error msg: Copy-Item (Get-Childitem $b -Directory | Sort-Object LastAccessTime -Descending ...
      + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      + CategoryInfo : ObjectNotFound: (C:\Windows\system32\20171210:String) [Copy-Item], ItemNotFoundEx

      Actually the $fin path is "\\182.158.10.8\zonghang_data" not "c:\windows\system32" !

      i dont know why !

  • #64347

    Participant
    Points: 1
    Rank: Member

    Not entirely sure why, but this seems to work:

    Copy-Item -Path $fin.PSPath -Destination $dis -Recurse
    • #64497

      Participant
      Points: 0
      Rank: Member

      the command no problem..just didnt know why cant get the correct path.

The topic ‘how to get the correct path’ is closed to new replies.

denizli escort samsun escort muğla escort ataşehir escort kuşadası escort