2009-11-13

Autogenerated scriptheader

In my daily tasks I often use scripts generated by other scripts. Often T-SQL scripts generated by PowerShell scripts.
The descriptive header of such autogenerated scripts I like to contain some general informations like which scripts generated it, who did it, when was it done and on which computer was it done.

In short these line give some of the wanted data.
"Filename  : $($MyInvocation.InvocationName)"
"Date      : $($(Get-Date).ToUniversalTime().ToString('s')) UTC"
"User      : $([Security.Principal.WindowsIdentity]::GetCurrent().Name)"
"Computer  : $($env:COMPUTERNAME)`(.$($env:USERDNSDOMAIN)`)"

No comments: