Skip to content
Menu
The Lonely Administrator
  • PowerShell Tips & Tricks
  • Books & Training
  • Essential PowerShell Learning Resources
  • Privacy Policy
  • About Me
The Lonely Administrator

PModem and Folder Listings

Posted on November 4, 2009November 4, 2009

PowerShell MVP Oisin Grehan posted a very promising PowerShell module the other day. He calls it the PModem File Transfer Protocol. It is based on the old bulletin board file transfer protocols of the late 20th century, which I have to admit I fondly remember using. Of course Oisin’s work intrigued me and after playing with it for a while I realized I needed something else.

Manage and Report Active Directory, Exchange and Microsoft 365 with
ManageEngine ADManager Plus - Download Free Trial

Exclusive offer on ADManager Plus for US and UK regions. Claim now!

Oisin’s approach is to transfer files in PowerShell using the WinRM connection which is ubiquitous with PowerShell v2.0. I won’t go into the technical nitty gritty, but basically files can be transferred without using any of the traditional file transfer protocols. What I realized I needed was a way to see what files are on the remote computer. I could do a simple listing

PS C:\> dir \\remotepc\c$\mydata\test

But then I’m back to using the old-fashioned file protocols. It took me a few minutes to realize how to get a remote listing using WinRM: The Invoke-Command cmdlet. With this cmdlet I can run the DIR command on the remote computer through a WinRM session. First I need to define a session.

PS C:\> $rdc=new-pssession -ComputerName ResearchDC -credential $research

Then I can use Invoke-Command to run my remote directory listing.

PS C:\> invoke-command $rdc -ScriptBlock {dir $env:temp} -hide

Directory: C:\Users\Administrator\AppData\Local\Temp

Mode                LastWriteTime     Length Name
----                -------------     ------ ----
d----         8/25/2009   2:40 PM            bin
d----         8/18/2009   8:18 PM            Low
d----         8/18/2009   2:20 PM            VMwareDnD
-a---        10/23/2009   1:19 PM        123 CFG5F0C.tmp
-a---        10/23/2009   1:23 PM        123 CFG839D.tmp
-a---         8/25/2009   2:41 PM    2241856 msi.log
-a---         9/16/2009  10:05 AM       1648 Silverlight0.log
-a---         9/16/2009  10:05 AM     604370 SilverlightMSI.log
-a---        10/13/2009   4:21 PM      54558 vminst.log

I’m hiding the remote computername because I already know what it is. Now that I know the file name I want I can use the Get-RemoteFile function.

PS C:\> get-remotefile -session $rdc -remotefile C:\Users\Administrator\AppData\Local\Temp\msi.log -local c:\test

This is very early code so there’s alot of kinks to work out but this works! Even better, I can take my expression and pipe it to Get-Remotefile and retrieve all the log files.

invoke-command $rdc -ScriptBlock {dir $env:temp\*.log} -hide |

 foreach {

   get-remotefile -session $rdc -remotefile $_.fullname -local c:\test

 }

I know Oisin wants to improve multiple file transfers but for now this works for me and I know it will only get better. Thanks Oisin.


Behind the PowerShell Pipeline

Share this:

  • Click to share on X (Opens in new window) X
  • Click to share on Facebook (Opens in new window) Facebook
  • Click to share on Mastodon (Opens in new window) Mastodon
  • Click to share on LinkedIn (Opens in new window) LinkedIn
  • Click to share on Pocket (Opens in new window) Pocket
  • Click to share on Reddit (Opens in new window) Reddit
  • Click to print (Opens in new window) Print
  • Click to email a link to a friend (Opens in new window) Email

Like this:

Like Loading...

Related

reports

Powered by Buttondown.

Join me on Mastodon

The PowerShell Practice Primer
Learn PowerShell in a Month of Lunches Fourth edition


Get More PowerShell Books

Other Online Content

github



PluralSightAuthor

Active Directory ADSI Automation Backup Books CIM CLI conferences console Friday Fun FridayFun Function functions Get-WMIObject GitHub hashtable HTML Hyper-V Iron Scripter ISE Measure-Object module modules MrRoboto new-object objects Out-Gridview Pipeline PowerShell PowerShell ISE Profile prompt Registry Regular Expressions remoting SAPIEN ScriptBlock Scripting Techmentor Training VBScript WMI WPF Write-Host xml

©2025 The Lonely Administrator | Powered by SuperbThemes!
%d