none
How do I remotely get-childitem? RRS feed

  • Question

  • Suppose i have a dev environment and prod environment

    both of these environments have a shared drive: N:\ however the FQDN of the shared drives differ between the environments

    i.e.

    • dev: sharedserverdev.domain.com\data
    • prod: sharedserverprod.domain.com\data

    now suppose i have the following servers on dev and prod

    • dev: server1.dev.domain.com
      prod: server2.prod.domain.com

    the N:drive shows up like this on server1 and server2

    sharedd

    i want to retrieve a file from the prod server2 N: drive to the dev server1 N: drive.

    particularly, im interested in executing this command from dev server1.dev.domain.com:

    $backupfile = Get-ChildItem "N:\" -Filter "*Cube2*.abf" | Sort-Object LastAccessTime -Descending | Select-Object -First 1
    
    Restore-ASDatabase -Server "server3.dev.domain.com" -RestoreFile $backupfile -Name Cube1 -AllowOverwrite

    the $backupfile is currently retrieved from the dev N: drive

    which works and restores successfuly on target server (in this case server3.dev.domain.com)

    however, i'd like to get a backup file from the prod N: drive. in thsi example, Cube2.abf file. i clearly can see the file exists there on prod N:\ drive

    I am trying this answer here

    $b = New-PSSession server2.prod.domain.com
    
    Copy-Item -FromSession $b N:\Cube2.abf -Destination N:\Cube2.abf

    but i am getting error:

    Copy-Item : Cannot find path 'N:\Cube2.abf' because it does not exist.

    ultimately, i dont even need to copy the file. i would just need to get it:

    $backupfile = Invoke-Command -Cn "server2.prod.domain.com" { Get-ChildItem "N:\" -Filter "*Cube2*.abf" | Sort-Object LastAccessTime -Descending | Select-Object -First 1 }

    but even THAT is not working either with Invoke-Command (whether running it from the prod server itself or dev server i am not getting any output except this error/warning (which from my experience is just a display line that doesnt really make a difference...). also, specifying a local drive thats not mounted, like D:\ or C:\ unlike N:\ still results in that error with Invoke-Command)
    Attempting to perform the InitializeDefaultDrives operation on the 'FileSystem' provider failed.
    if i run this command on the prod server
    Get-ChildItem "N:\" -Filter "*Cube2*.abf" | Sort-Object LastAccessTime -Descending | Select-Object -First 1

    i get output:

        Directory: N:\
    
    
    Mode                LastWriteTime         Length Name
    ----                -------------         ------ ----
    -a----        7/17/2019   3:05 PM       41033728 Cube2.abf
    • Edited by jrvModerator Friday, July 19, 2019 8:23 AM Bad formatting
    • Edited by cataster Friday, July 19, 2019 3:03 PM
    Friday, July 19, 2019 6:25 AM

All replies

  • Wow ... that hurts my eyes. ;-)  ... could you please remove the weird formatting from your post?

    Thanks.

    Don't you check your post after you send it away?


    Live long and prosper!

    (79,108,97,102|%{[char]$_})-join''

    Friday, July 19, 2019 7:59 AM
  • To cppy the file you should be using below:

    Copy-Item -FromSession $b N:\Cube2.abf -Destination N:\

    Also while working with network drives, you should be using the UNC path of the same instead of drive letters.

    • Proposed as answer by Imran_Khan Friday, July 19, 2019 2:49 PM
    Friday, July 19, 2019 8:19 AM
  • I tried to fix your bad formatting but it can't be fixed. Please edit and post your question correctly.

    How to ask   questions in a technical forum

    How   to post code in Technet Forums
     


    \_(ツ)_/

    Friday, July 19, 2019 8:24 AM
    Moderator
  • Wow ... that hurts my eyes. ;-)  ... could you please remove the weird formatting from your post?

    Thanks.

    Don't you check your post after you send it away?


    Live long and prosper!

    (79,108,97,102|%{[char]$_})-join''

    lol my bad. i editted it to technet standard now :)
    Friday, July 19, 2019 3:05 PM
  • I tried to fix your bad formatting but it can't be fixed. Please edit and post your question correctly.

    How to ask   questions in a technical forum

    How   to post code in Technet Forums
     


    \_(ツ)_/

    my bad, i reeditted it and now the code should be conforming to tech forum standard :)
    Friday, July 19, 2019 3:06 PM
  • To cppy the file you should be using below:

    Copy-Item -FromSession $b N:\Cube2.abf -Destination N:\

    Also while working with network drives, you should be using the UNC path of the same instead of drive letters.

    i still cant get files to copy. however, i was able to copy folders!

    Copy-Item -Path \\sharedserverprod.domain.com\data\Cubefolder -Destination \\sharedserverdev.domain.com\data

    why cant i copy files? it keeps saying it doesnt exist...

    Copy-Item : Cannot find path '\\sharedserverprod.domain.com\data\Cube2.abf' because it does not exist.


    • Edited by cataster Friday, July 19, 2019 3:30 PM
    Friday, July 19, 2019 3:29 PM
  • why cant i copy files? it keeps saying it doesnt exist...


    It should be fairly easy to verify that the file exists. 

    Get-ChildItem \\sharedserverprod.domain.com\data
    Get-ChildItem \\sharedserverprod.domain.com\data\Cube2.abf
    Get-ChildItem \\sharedserverprod.domain.com\data\Cubefolder\Cube2.abf
    

    Saturday, July 20, 2019 1:19 PM
  • Hi,

    Was your issue resolved?

    If you resolved it using our solution, please "mark it as answer" to help other community members find the helpful reply quickly.

    If you resolve it using your own solution, please share your experience and solution here. It will be very beneficial for other community members who have similar questions.

    If no, please reply and tell us the current situation in order to provide further help.

    Best Regards,

    Lee



    Just do it.

    Wednesday, July 31, 2019 7:15 AM
    Moderator