简体   繁体   中英

Execute Powershell Script on Client Machine?

I am asked to create a simple data collection form that also needs to include some client machine information (the not simple part). Basically the company wants me to pre-populate form values with client machine's list of printers. They graciously provided me with a powershell script to demonstrate what they need.

"Printers" >> c:\Printers.txt
get-WmiObject -class Win32_printer | ft name, systemName, shareName >> c:\printers.txt

I have been toying with some ideas about how to accomplish this in a way that would minimize the clients involvement.

For example I would have a user download a script, click on it to execute and then open a text file so that they can copy and paste the collected information into a web page form field. But this seems to involved for non technical people.

Is there a way I could automate this a bit more. Maybe automatically execute the script. I am working with PHP on the server side and I am free to use any JavaScript I want,,, Since JavaScript doesn't have access to filesystem I can't see that there is much more than the original idea that I could do.

Do you have any suggestions on how to accomplish this while minimizing the number of steps that a client has to take?

You could do something like the below

$computers = Import-Csv C:\ListOfTargetComputers.csv
$cred = (Get-credential)

foreach ($comp in $computers) {

get-WmiObject -class Win32_printer -ComputerName $comp -Credential $cred | ft name, systemName, shareName | Out-File \\share\PublicFolder\project\printers-$comp.txt

}

So, get a list of computers you want to run this against and stick them in a csv, in this case: "ListOfTargetComputers.csv".

The loop then targets each computer in the list, uses the credentials specified (these will need to be a local admin on the machines, so a domain admin account or so?), then will stick the data in a .txt file in a public folder on a file-share.

So that will all need setting up, but should work.

  1. Account that is set as a local admin on all machines
  2. A public share folder that everyone has read-write access to
  3. A list of target computers

NOTE: This will require no end-user input and should be able to be run remotely.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM