Tinus EngOps Wiki

Logo

OpsaC - Operating as PowerShell code

Links

Home

IT-Wiki

PowerShell Blog

PowerShell Index

PowerShell Search

Additional Websites

View my GitHub Profile

View my GitHub Gists

View my Codeberg Page

View my Photo Website

FileInfo

published: February 22, 2019 author: Tinu tags: PowerShell categories: PowerShell-Basic


Table of Contents

Create Logfile

To create a logfile frorm the current scriptname, you can do this:

$LogFile = $PSCommandPath -replace '.ps1', '.log'

Generate Outputfile

Generate an output-file with the name of the inputfile, but without an extension.

System.IO.FileInfo

Cast the FullName of the inputfile to an System.IO.FileInfo-Object (Get-Item).

$FileInfo   = [System.IO.FileInfo] $inputfile

Join-Path

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')"

Save the Outputfile

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

← Previous Post ◇ [ Top ] ◇ Copyright © 2024 by tinuwalther ◇ [ Blog ] ◇ Next Post →