How to use powershell transcript?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-01-2015 05:06 PM
Hello,
I am new to ServiceNow but I am trying to automate some AD account provisioning processes which require some advanced logic. So I am creating a workflow which executes a PowerShell script to do all the AD queries, account creation, etc. When I typically write some PowerShell scripts and I want to log the activity, I simply use the Start-Transcript command which works nicely.
However the Start-Transcript doesn't seem to work when the command is executed from within a Service Now workflow. Running the PowerShell script locally works fine. Here is the code in the Run PowerShell activity:
$LogFile = "C:\Data\Scripts\Logs\LogFile.txt"
Start-Transcript -Path $LogFile
Write-Host "host"
Write-Output "output"
"Test" | Out-Default
"Another"
Here is the contents of the logfile after the activity runs:
**********************
Windows PowerShell transcript start
Start time: 20151201170402
Username : TESTMSF\svcSN
Machine : MID01 (Microsoft Windows NT 6.3.9600.0)
**********************
**********************
Windows PowerShell transcript end
End time: 20151201170402
**********************
As you can see, it does start the Transcript but just doesn't log any of the output.
Any ideas?
Thanks,
Michael
- Labels:
-
Service Mapping
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-01-2015 11:02 PM
Hi,
check following it's helpful.
Thanks,
Sanjeev Kumar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-02-2015 02:31 AM
Hi Sanjeev Kumar,
The PowerShell Probe Utility that you're pointing too is out-dated and not working anymore since package calls have been removed. Fortunately I have updated it, even to include MID server script files if needed: PowerShell Utility V2 - execute Powershell scripts directly from your instance
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-02-2015 02:39 AM
Hello Michael,
I tested this with the PowerShell Utility (PowerShell Utility V2 - execute Powershell scripts directly from your instance ) and I got the proper outputs into the log file (see below).
I can only explain this behavior with missing access rights even though the log-file was created... Please confirm that it has well been created by the activity and not been appended?
Check if your user "TESTMSF\svcSN" has proper access rights to "C:\Data\Scripts\Logs" and try to use the parameter "-Force" on Start-Transcript.
**********************
Windows PowerShell transcript start
Start time: 20151202103017
Username: C**\Admin***
RunAs User: C**\Admin***
Machine: **-**-SNOWMID** (Microsoft Windows NT 6.3.9600.0)
Host Application: C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -executionpolicy unrestricted -noninteractive -command & {& 'scripts\PowerShell\PSScript.ps1' -computer '127.0.0.1' -script 'C:\Users\ADMINS~1\AppData\Local\Temp\script.4617265080828112512.PS1' -useCred $false -isDiscovery $true -debug $false; exit $LASTEXITCODE}
Process ID: 11580
**********************
Transcript started, output file is C:\temp\LogFile.txt
output
Test
Another
**********************
Windows PowerShell transcript end
End time: 20151202103017
**********************
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-17-2015 12:55 PM
Thanks for the info however I just couldn't get it to work but I didn't try using the PowerShell Utility... But the bottom line is that it would need to run from a Run PowerShell activity in a workflow and it just won;t work properly.
Not a big deal as I am using another method to just write to a log file for key events...