Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Using WMI for file information

by ElderScripts (Novice)
on Mar 07, 2016 at 09:24 UTC ( [id://1156981]=perlquestion: print w/replies, xml ) Need Help??

ElderScripts has asked for the wisdom of the Perl Monks concerning the following question:

I need to write a Perl script that connects via WMI to a remote windows machine (its a prerequisite, cant change the protocol) and retrieve all file information from a specific directory path (file size,creation date, file name). I thought about the possibility of somehow access the to the machine's cmd and run dir command but could not find relevant information. Someone have an idea of how to implement this? Thank you for your support.

Replies are listed 'Best First'.
Re: Using WMI for file information
by VinsWorldcom (Prior) on Mar 07, 2016 at 16:04 UTC

    Are we confusing the terms "WMI" and "protocol" here? If you need to use WMI, why create a Perl script?

    wmic /node:remote_ip /user:username /pass:password datafile where "dri +ve='c:' and path='\\specific\\directory\\'" get name ...

    where "..." is the other attributes you want (e.g., file size, creation date, ...). If you're thinking about connecting to a cmd.exe window on the remote machine, then the suggestion about 'psexec' can get you there and then you can just do a "dir". Of course, none of that is using WMI as the "protocol" ... and none of this requires Perl.

Re: Using WMI for file information
by Corion (Patriarch) on Mar 07, 2016 at 15:22 UTC

    If the psexec approach doesn't work, you can also try to use DBD::WMI to connect to the remote machine and then do a filesystem query there. Note that you will need Administrator privileges on your current domain to connect to the remote machine, as passing credentials has never been implemented.

Re: Using WMI for file information
by Anonymous Monk on Mar 07, 2016 at 09:41 UTC
    psexec?

      To expand on the psexec suggestion, it's a part of the Sysinternals suite of tools that are now owned by Microsoft. It basically will let you execute a command on a remote Windows system - including copying a "program" to the remote system to be run remotely.

      Since you're also interested in capturing the output of the command being run on the remote system, you may want to consider pairing psexec with Capture::Tiny.

      If you have a log in for the remote system that has the required permissions to do what you want, I believe that psexec might be the easiest route to go.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://1156981]
Approved by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (1)
As of 2024-04-16 19:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found