Powershell, shell_exec + Get-Printer

Asked

Viewed 72 times

1

I’m trying to get a result from server B through server A, by Powershell in php. Basically I’m giving the command


PowerShell Get-Printer -ComputerName (Servidor-B) -Name (Impressora) | Format-List

If I run this command locally on the A server I get this result.

Name                         : teste_1
ComputerName                 : 10.41.13.95
Type                         : Local
ShareName                    :
PortName                     : 192.168.258.258
DriverName                   : Generic / Text Only
Location                     :
Comment                      :
SeparatorPageFile            :
PrintProcessor               : winprint
Datatype                     : RAW
Shared                       : False
Published                    : False
PermissionSDDL               :
RenderingMode                :
KeepPrintedJobs              : False
Priority                     : 1
DefaultJobPriority           : 0
StartTime                    : 0
UntilTime                    : 0
PrinterStatus                : Error
JobCount                     : 1
DisableBranchOfficeLogging   :
BranchOfficeOfflineLogSizeMB :

Until then perfect, but if I go through PHP with Shell_exec through the command;

shell_exec('PowerShell Get-Printer -ComputerName (Servidor-B) -Name (Impressora) | Format-List');

The result is this:

Get-Printer : An error occurred while performing the specified operation.  See 
the error details for more information.
At line:1 char:1
+ Get-Printer -computername 10.41.13.95 teste_1 | Format-list
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (MSFT_Printer:ROOT/StandardCimv2/M 
   SFT_Printer) [Get-Printer], CimException
    + FullyQualifiedErrorId : HRESULT 0x8007007b,Get-Printer

Some details:

  • I’ve run with -Executionpolicy Bypass
  • I have already checked which user is running this command through IIS ( Administrator)
  • I have tried to execute this command within a . ps1 command within a . bat

Anyway, I’ve run out of ideas, someone can help me ?

1 answer

1


Try installing PHP on the servers and running the powershell from within php q ta on the servers as ADMIN. One can take the result and play in database and redeem by main application.

  • Actually, I did an iis on the other server and just called the local command to generate the report that needed, and it worked. Thanks for the tip !!!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.