<br />
<b>Warning</b>:  strpos() expects parameter 1 to be string, array given in <b>/home/theserverside/public_html/wp-includes/blocks.php</b> on line <b>20</b><br />
{"id":1678,"date":"2021-10-30T15:02:45","date_gmt":"2021-10-30T15:02:45","guid":{"rendered":"https:\/\/www.theserverside.technology\/?p=1678"},"modified":"2021-10-30T15:18:38","modified_gmt":"2021-10-30T15:18:38","slug":"","status":"publish","type":"post","link":"https:\/\/www.theserverside.technology\/it\/2021\/10\/30\/how-to-clear-powershell-history-done-right\/","title":{"rendered":"Come cancellare la history di Powershell (ma davvero)","raw":"Come cancellare la history di Powershell (ma davvero)"},"content":{"rendered":"\n<p>Capita di avere la necessit\u00e0 di cancellare la history dei comandi Powershell inviati con un account. A noi, per esempio, \u00e8 capitato quando abbiamo dovuto preparare dei template per le virtual machine dei nostri clienti ed era necessario attivare un software prima di completare il template.<\/p>\n\n\n\n<p>Sfortunatamente questa attivazione avveniva per mezzo console e bisogna quindi inserire un comando con il codice di attivazione. Questo faceva si che il codice potesse poi essere visibile per gli utenti che usavano quel template che potevano accedere alla history semplicemente premendo <em>PgUp<\/em>. Se si cerca una soluzione si scopre che Powershell ha un comando per la cancellazione della history:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;powershell&quot;,&quot;mime&quot;:&quot;application\/x-powershell&quot;,&quot;theme&quot;:&quot;lucario&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;PowerShell&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;powershell&quot;}\">Clear-History<\/pre><\/div>\n\n\n\n<p>Tuttavia non tutti i comandi vengono rimossi. Alcuni vengono rimossi, altri no oppure proprio nessuno. Probabilmente non vengono rimosse le invocazioni di eseguibili e comandi esterni. Ad ogni modo, questo lascia la history, o parte di essa, disponibile per gli altri utenti.<\/p>\n\n\n\n<p>C&#8217;\u00e8 per\u00f2 un comando che consente di visualizzare quale sia il file in cui Powershell memorizza la history dell&#8217;utente:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;powershell&quot;,&quot;mime&quot;:&quot;application\/x-powershell&quot;,&quot;theme&quot;:&quot;lucario&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;PowerShell&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;powershell&quot;}\">PS C:\\Users\\Administrator&gt; (Get-PSReadlineOption).HistorySavePath\nC:\\Users\\Administrator\\AppData\\Roaming\\Microsoft\\Windows\\PowerShell\\PSReadLine\\ConsoleHost_history.txt<\/pre><\/div>\n\n\n\n<p>Il file mostrato \u00e8 quello della history. Basta quindi modificarl e rimuovere le righe che non si vogliono rendere disponibili per gli altri utenti.<\/p>\n\n\n\n<p>Un trucco semplice ma rimane il mistero sul perch\u00e9 esista un comando dedicato che non funziona come ci si aspetterebbe.<\/p>\n","protected":false,"raw":"<!-- wp:paragraph -->\n<p>Capita di avere la necessit\u00e0 di cancellare la history dei comandi Powershell inviati con un account. A noi, per esempio, \u00e8 capitato quando abbiamo dovuto preparare dei template per le virtual machine dei nostri clienti ed era necessario attivare un software prima di completare il template.<\/p>\n<!-- \/wp:paragraph -->\n\n<!-- wp:paragraph -->\n<p>Sfortunatamente questa attivazione avveniva per mezzo console e bisogna quindi inserire un comando con il codice di attivazione. Questo faceva si che il codice potesse poi essere visibile per gli utenti che usavano quel template che potevano accedere alla history semplicemente premendo <em>PgUp<\/em>. Se si cerca una soluzione si scopre che Powershell ha un comando per la cancellazione della history:<\/p>\n<!-- \/wp:paragraph -->\n\n<!-- wp:codemirror-blocks\/code-block {\"mode\":\"powershell\",\"mime\":\"application\/x-powershell\",\"theme\":\"lucario\"} -->\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>Clear-History<\/pre><\/div>\n<!-- \/wp:codemirror-blocks\/code-block -->\n\n<!-- wp:paragraph -->\n<p>Tuttavia non tutti i comandi vengono rimossi. Alcuni vengono rimossi, altri no oppure proprio nessuno. Probabilmente non vengono rimosse le invocazioni di eseguibili e comandi esterni. Ad ogni modo, questo lascia la history, o parte di essa, disponibile per gli altri utenti.<\/p>\n<!-- \/wp:paragraph -->\n\n<!-- wp:paragraph -->\n<p>C'\u00e8 per\u00f2 un comando che consente di visualizzare quale sia il file in cui Powershell memorizza la history dell'utente:<\/p>\n<!-- \/wp:paragraph -->\n\n<!-- wp:codemirror-blocks\/code-block {\"mode\":\"powershell\",\"mime\":\"application\/x-powershell\",\"theme\":\"lucario\"} -->\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>PS C:\\Users\\Administrator&gt; (Get-PSReadlineOption).HistorySavePath\nC:\\Users\\Administrator\\AppData\\Roaming\\Microsoft\\Windows\\PowerShell\\PSReadLine\\ConsoleHost_history.txt<\/pre><\/div>\n<!-- \/wp:codemirror-blocks\/code-block -->\n\n<!-- wp:paragraph -->\n<p>Il file mostrato \u00e8 quello della history. Basta quindi modificarl e rimuovere le righe che non si vogliono rendere disponibili per gli altri utenti.<\/p>\n<!-- \/wp:paragraph -->\n\n<!-- wp:paragraph -->\n<p>Un trucco semplice ma rimane il mistero sul perch\u00e9 esista un comando dedicato che non funziona come ci si aspetterebbe.<\/p>\n<!-- \/wp:paragraph -->"},"excerpt":{"rendered":"","protected":false,"raw":""},"author":8,"featured_media":1679,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_en_post_content":"<!-- wp:paragraph -->\n<p>You might find youserlf in a situation where you need to clear Powershell command history. For example, for us it was needed because we needed to prepare templates for virtual machines deployment and we needed to activate a specific software before finalizing the template.<\/p>\n<!-- \/wp:paragraph -->\n\n<!-- wp:paragraph -->\n<p>Unfortunately you need to type a command to enter the code and activate the software and those templates could be used by our customers that might be able to retrieve the correct code by simply striking arrow-up. If you look for a solution you will find that Powershell has a specific command to do that:<\/p>\n<!-- \/wp:paragraph -->\n\n<!-- wp:codemirror-blocks\/code-block {\"mode\":\"powershell\",\"mime\":\"application\/x-powershell\",\"theme\":\"lucario\"} -->\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>Clear-History\n<\/pre><\/div>\n<!-- \/wp:codemirror-blocks\/code-block -->\n\n<!-- wp:paragraph -->\n<p>However, you might find that this won't solve your problem. Some history gets cancelled and some don't or sometimes nothing at all gets removed and all of your history is still available to anyone logging using that account.<\/p>\n<!-- \/wp:paragraph -->\n\n<!-- wp:paragraph -->\n<p>Turned out that there's a way to check <span style=\"text-decoration: underline;\">actually where<\/span> Powershell stores your history. Just issue this command:<\/p>\n<!-- \/wp:paragraph -->\n\n<!-- wp:paragraph -->\n<p><\/p>\n<!-- \/wp:paragraph -->\n\n<!-- wp:codemirror-blocks\/code-block {\"mode\":\"powershell\",\"mime\":\"application\/x-powershell\",\"theme\":\"lucario\"} -->\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>PS C:\\Users\\Administrator&gt; (Get-PSReadlineOption).HistorySavePath\nC:\\Users\\Administrator\\AppData\\Roaming\\Microsoft\\Windows\\PowerShell\\PSReadLine\\ConsoleHost_history.txt\n<\/pre><\/div>\n<!-- \/wp:codemirror-blocks\/code-block -->\n\n<!-- wp:paragraph -->\n<p>The result is the location of the history file. Just edit this file and remove those lines you don't want other users to access.<\/p>\n<!-- \/wp:paragraph -->\n\n<!-- wp:paragraph -->\n<p>Neat trick but actually we're not sure why the dedicated command is not working as expected. <\/p>\n<!-- \/wp:paragraph -->","_en_post_name":"how-to-clear-powershell-history-done-right","_en_post_excerpt":"","_en_post_title":"How to clear Powershell history (done right!)","_it_post_content":"<!-- wp:paragraph -->\n<p>Capita di avere la necessit\u00e0 di cancellare la history dei comandi Powershell inviati con un account. A noi, per esempio, \u00e8 capitato quando abbiamo dovuto preparare dei template per le virtual machine dei nostri clienti ed era necessario attivare un software prima di completare il template.<\/p>\n<!-- \/wp:paragraph -->\n\n<!-- wp:paragraph -->\n<p>Sfortunatamente questa attivazione avveniva per mezzo console e bisogna quindi inserire un comando con il codice di attivazione. Questo faceva si che il codice potesse poi essere visibile per gli utenti che usavano quel template che potevano accedere alla history semplicemente premendo <em>PgUp<\/em>. Se si cerca una soluzione si scopre che Powershell ha un comando per la cancellazione della history:<\/p>\n<!-- \/wp:paragraph -->\n\n<!-- wp:codemirror-blocks\/code-block {\"mode\":\"powershell\",\"mime\":\"application\/x-powershell\",\"theme\":\"lucario\"} -->\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>Clear-History<\/pre><\/div>\n<!-- \/wp:codemirror-blocks\/code-block -->\n\n<!-- wp:paragraph -->\n<p>Tuttavia non tutti i comandi vengono rimossi. Alcuni vengono rimossi, altri no oppure proprio nessuno. Probabilmente non vengono rimosse le invocazioni di eseguibili e comandi esterni. Ad ogni modo, questo lascia la history, o parte di essa, disponibile per gli altri utenti.<\/p>\n<!-- \/wp:paragraph -->\n\n<!-- wp:paragraph -->\n<p>C'\u00e8 per\u00f2 un comando che consente di visualizzare quale sia il file in cui Powershell memorizza la history dell'utente:<\/p>\n<!-- \/wp:paragraph -->\n\n<!-- wp:codemirror-blocks\/code-block {\"mode\":\"powershell\",\"mime\":\"application\/x-powershell\",\"theme\":\"lucario\"} -->\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>PS C:\\Users\\Administrator&gt; (Get-PSReadlineOption).HistorySavePath\nC:\\Users\\Administrator\\AppData\\Roaming\\Microsoft\\Windows\\PowerShell\\PSReadLine\\ConsoleHost_history.txt<\/pre><\/div>\n<!-- \/wp:codemirror-blocks\/code-block -->\n\n<!-- wp:paragraph -->\n<p>Il file mostrato \u00e8 quello della history. Basta quindi modificarl e rimuovere le righe che non si vogliono rendere disponibili per gli altri utenti.<\/p>\n<!-- \/wp:paragraph -->\n\n<!-- wp:paragraph -->\n<p>Un trucco semplice ma rimane il mistero sul perch\u00e9 esista un comando dedicato che non funziona come ci si aspetterebbe.<\/p>\n<!-- \/wp:paragraph -->","_it_post_name":"","_it_post_excerpt":"","_it_post_title":"Come cancellare la history di Powershell (ma davvero)","edit_language":"it"},"categories":[400],"tags":[109,399,115],"_links":{"self":[{"href":"https:\/\/www.theserverside.technology\/it\/wp-json\/wp\/v2\/posts\/1678"}],"collection":[{"href":"https:\/\/www.theserverside.technology\/it\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.theserverside.technology\/it\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.theserverside.technology\/it\/wp-json\/wp\/v2\/users\/8"}],"replies":[{"embeddable":true,"href":"https:\/\/www.theserverside.technology\/it\/wp-json\/wp\/v2\/comments?post=1678"}],"version-history":[{"count":45,"href":"https:\/\/www.theserverside.technology\/it\/wp-json\/wp\/v2\/posts\/1678\/revisions"}],"predecessor-version":[{"id":1724,"href":"https:\/\/www.theserverside.technology\/it\/wp-json\/wp\/v2\/posts\/1678\/revisions\/1724"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.theserverside.technology\/it\/wp-json\/wp\/v2\/media\/1679"}],"wp:attachment":[{"href":"https:\/\/www.theserverside.technology\/it\/wp-json\/wp\/v2\/media?parent=1678"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.theserverside.technology\/it\/wp-json\/wp\/v2\/categories?post=1678"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.theserverside.technology\/it\/wp-json\/wp\/v2\/tags?post=1678"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}