mirror of
https://github.com/fleschutz/PowerShell.git
synced 2025-05-11 11:04:46 +02:00
Added convert-history2ps1.ps1
This commit is contained in:
parent
c8bc801efa
commit
cead884c64
35
scripts/convert-history2ps1.ps1
Normal file
35
scripts/convert-history2ps1.ps1
Normal file
@ -0,0 +1,35 @@
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Converts history to PowerShell script
|
||||
.DESCRIPTION
|
||||
This PowerShell script converts your command history into a PowerShell script.
|
||||
It saves all your commands into a script for automation (executed by e.g Jenkins or AutoHotkey).
|
||||
.PARAMETER path
|
||||
Specifies the file path of the new script ('script-from-history.ps1' by default)
|
||||
.EXAMPLE
|
||||
PS> ./convert-history2ps1.ps1
|
||||
✅ Converted your command history into the PowerShell script: script-from-history.ps1
|
||||
.LINK
|
||||
https://github.com/fleschutz/PowerShell
|
||||
.NOTES
|
||||
Author: Markus Fleschutz | License: CC0
|
||||
#>
|
||||
|
||||
param([string]$path = "script-from-history.ps1")
|
||||
|
||||
try {
|
||||
$history = Get-History
|
||||
|
||||
foreach ($item in $history) {
|
||||
Write-Output "`"⏳ Step #$($item.Id): Executing $($item.CommandLine) ...`"" >> $path
|
||||
Write-Output "& $($item.CommandLine)" >> $path
|
||||
Write-Output "" >> $path
|
||||
}
|
||||
Write-Output "`"✅ PowerShell script finished (source: command history of $($env:USERNAME) on $($env:COMPUTERNAME)).`"" >> $path
|
||||
Write-Output "exit 0 # success" >> $path
|
||||
"✅ Converted your command history into PowerShell script: $path"
|
||||
exit 0 # success
|
||||
} catch {
|
||||
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
|
||||
exit 1
|
||||
}
|
Loading…
Reference in New Issue
Block a user