OpsaC - Operating as PowerShell code
published: February 22, 2019 author: Tinu tags: PowerShell categories: PowerShell-Basic
To create a logfile frorm the current scriptname, you can do this:
$LogFile = $PSCommandPath -replace '.ps1', '.log'
Generate an output-file with the name of the inputfile, but without an extension.
Cast the FullName of the inputfile to an System.IO.FileInfo-Object (Get-Item).
$FileInfo = [System.IO.FileInfo] $inputfile
Join the Directory- and the BaseName with the current time-stamp to the new FullName without an extension.
$Outputfile = Join-Path -Path $FileInfo.DirectoryName -ChildPath "$($FileInfo.BaseName)-$(Get-Date -f 'yyyy-MM-dd_HHmmss')"
Convert the content (Object) to a JSON- and CSV-File.
$content | ConvertTo-Json | Set-Content -Path "$($Outputfile).json"
$content | Export-Csv -Path "$($Outputfile).csv" -Delimiter ';' -NoTypeInformation -Append