From fe0a982699c94bca68237c4922fc892cecad27ed Mon Sep 17 00:00:00 2001 From: andre Date: Mon, 9 Apr 2018 11:07:58 +0200 Subject: [PATCH] fichier pour profil powershell et enregistrer history --- WindowsServer2016/profile.ps1 | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 WindowsServer2016/profile.ps1 diff --git a/WindowsServer2016/profile.ps1 b/WindowsServer2016/profile.ps1 new file mode 100644 index 0000000..54c3f97 --- /dev/null +++ b/WindowsServer2016/profile.ps1 @@ -0,0 +1,18 @@ +function global:Prompt { +## Get the last item from the history +$historyItem = Get-History -Count 1 +## If there were any history items +if() +{ +# Save previous command details + | convert-to-tsv | select -skip 1 >> ".command-history.txt" +} +} + +function global:convert-to-csv { + | +ConvertTo-Csv -delimiter " " -NoTypeInformation | +# First replace: Remove double-quotes 1) at beginning of line 2) at end of line 3) before a tab using regex look-ahead 4) after a tab using regex look-behind +# Second replace: Replace 2 double-quotes with one (added by convert-to-csv) +% { -replace '^"|"$|"(?=\t)|(?<=\t)"', '' -replace '""','"' } +}