I have the following code. It connects to a Service Now Instance. Fetches Incident for particular server. The Incident has details for Printer Creation. ip is in record['user_input'],printer name is in record['u_string_full_utf8_1']. What I would like to achieve is pass these as arguments to powershell so that it can run the Printer Create script. The arguments passed in the below code works. But I am not sure how to pass arguments in the middle of it.
import pysnow
import subprocess
import os
# Create client object
s = pysnow.Client(instance='instance', user='admin', password='password')
# Get all incidents
r = s.query('incident', query={'cmdb_ci':'a28cba7a4fb4030028f7fd218110c7f5'})
# order by 'created_on' descending, then iterate over the result and print out number
for record in r.get_multiple(order_by=['-created_on']):
print(record['cmdb_ci'])
psxmlgen = subprocess.Popen([r'C:\WINDOWS\system32\WindowsPowerShell\v1.0\powershell.exe',
"Invoke-Command -ComputerName SERVER01 -FilePath 'C:\Users\testuser\Documents\Scripts\PrinterCreate.ps1' -ArgumentList '10.2.3.2','PS Driver for Universal Print','TESTPRINTER' -Credential $cred"], cwd=os.getcwd())
result = psxmlgen.wait()
I checked the existing resources but was unable to figure out how to pass it in the middle.
Any help would be appreciated.
Using Python2.7