Somewhat new at this so need some assistance if anyone can offer any pointers.
I have created a Powershell script to export all documents modified in the last x days using Export-PWDocuments. This seems to work fine, however I would like to log or report on what has been exported.
I tried to capture the transactions simply using "Start-Transcript". This captures and logs activity logins, paths set etc. but does not capture and log the actual results of the Export-PWDocuments. For example when you run the script in PowerShell you see results of search and copy on the screen i.e. - Copied out 'C:\Export\17053\4 Drawings\4.3 Models\A30\Structural\Test Doc.txt' (Did not exist on disk)
It is this that I would like to log, but I have not found a way to capture this detail.
Any assistance would be appreciated.
Thanks in advance
The PWPS_DAB module has the Write-PWPSLog cmdlet for generating a log file.
Get-Help Write-PWPSLog -Full
Also, you can redirect all activity to a file by using *>> followed by the file to write to.
CheckOut-PWDocuments -InputDocument $pwDocuments -Export -ExportFolder "d:\TEMP\export" *>> 'd:\TEMP\ExportTest.log'
Thanks very much for taking the time to reply. Not to be picky but I had actually looked at these two options previously. Maybe I haven't got it right but from what I see -
Write-PWPSLog You seem to be only able to "specify" what to write in the log using the -Message ' ' parameter. Am I seeing this correctly, as that is all I could achieve with this one?
As for the redirect, this does work, however the output I get is "every" attribute of the file, making a very long (46 lines one file) list or log and not really telling me what I want to know. The only operator that logged anything was *.
The output in the Powershell console is perfect it tells me exactly what I want to know, if I could just capture this as shown in console. A sample of this below.
Returned 1 matchesCopied out 'C:\Export\17053\4 Drawings\4.3 Models\A30\Structural\Test Doc.txt' (Did not exist on disk)Wrote 'C:\Export\17053\4 Drawings\4.3 Models\A30\Structural\Test Doc.txt_2020-04-22 082356.xlsx' OKSearching 'C:\Export'...Found 8 files in folder 'C:\Export'Returned 1 matchesCopied out 'C:\Export\17053\4 Drawings\4.3 Models\A30\Structural\30-LCH-01-S-001.dgn' (File on disk has been changed)
It simply tells me the file didn't exist outside PW so copied out. Where it did exist and had changed it identifies this and copied it out etc. Alas, but can I capture and write this?
Using redirect if the file exists outside PW and is different modified date, the export script will copy it out and overwrite the local file, however redirect does not log anything at all for a file that exists and copied out/overwritten.
On the other hand from the console it will show
Returned 1 matchesCopied out 'C:\Export\17053\4 Drawings\4.3 Models\A30\Structural\Test Doc.txt' (File on disk has been changed)
Which is exactly what I want to know.
Am I missing something? Is there a way?
Have you tried the redirecting the Information stream? 6>>
I would think this will be the only option to get what you'd like. As opposed to everything.
Actually I have tried 1-6 and it does not write anything to the log? Seemingly only * writes anything and that's as previously mentioned writes "all" attributes.
Try the Start-Transcript command.
Creates a record of all or part of a Windows PowerShell session to a text file.
The Start-Transcript cmdlet creates a record of all or part of a Windows PowerShell session to a text file. The transcript includes all command that the
user types and all output that appears on the console.
Starting in Windows PowerShell 5.0, Start-Transcript includes the host name in the generated file name of all transcripts. This is especially useful when
your enterprise's logging is centralized. Files that are created by the Start-Transcript cmdlet include random characters in names to prevent potential
overwrites or duplication when two or more transcripts are started simultaneously. This also prevents unauthorized discovery of transcripts that are
stored in a centralized file share. Additionally in Windows PowerShell 5.0, the Start-Transcript cmdlet works in Windows PowerShell ISE.
-------------------------- EXAMPLExample 1: Start a transcript file with default settings --------------------------xample: Start a transcript file with
This command starts a transcript in the default file location.
Example 2: Start a transcript file at a specific location
PS C:\>Start-Transcript -Path "C:\transcripts\transcript0.txt" -NoClobber
This command starts a transcript in the Transcript0.txt file in C:\transcripts. Since the NoClobber parameter is used, the command prevents any existing
files from being overwritten. If the Transcript0.txt file already exists, the command fails.