Deprecated: Creation of dynamic property Timber\Site::$pingback is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Site.php on line 180

Deprecated: Creation of dynamic property Timber\User::$name is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/User.php on line 118

Deprecated: Creation of dynamic property Timber\Post::$old_id is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$_thumbnail_id is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$ext-thumbnail_url is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$_edit_last is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$_yoast_wpseo_metadesc is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$post_date_gmt is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$comment_status is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$ping_status is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$post_password is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$post_name is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$to_ping is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$pinged is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$post_modified is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$post_modified_gmt is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$post_content_filtered is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$guid is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$menu_order is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$post_mime_type is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$comment_count is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$filter is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$status is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71
Creare un file eseguibile a partire da uno script PowerShell | IlSoftware.it

Creare un file eseguibile a partire da uno script PowerShell

Windows include uno strumento software molto semplice da usare che permette di creare file .exe a partire anche da script PowerShell.

Anche Windows 10 mette a disposizione uno strumento integrato a livello di sistema che permette di creare file autoestraenti. Si chiama IExpress ed era stato oggetto anni fa di un nostro articolo: Creare file autoestraenti in Windows senza installare alcun software.

La stessa utilità può essere sfruttata per generare un file eseguibile Windows a partire da uno script PowerShell: vedere PowerShell per esempi: cosa si può fare.

File eseguibile a partire da uno script PowerShell con l’utilità IExpress

Per eseguire IExpress è sufficiente premere la combinazione di tasti Windows+R quindi digitare iexpress.

Si supponga di avere già creato un semplice script PowerShell di prova chiamato test.ps1 e contenente le seguenti due righe:

Test-Path -Path "C:\Windows"
Start-Sleep -Seconds 10

La prima riga verifica soltanto l’esistenza del percorso di Windows mentre la seconda sospende l’esecuzione dello script per 10 secondi.

Dopo aver avviato IExpress basterà selezionare l’opzione Create new Self Extraction Directive file e fare clic sul pulsante Avanti. Nella schermata successiva si dovrà selezionare Extract files and run an installation command.

Alla comparsa della finestra Package title si può inserire una descrizione per lo script PowerShell quindi cliccare ancora su Avanti.
La richiesta Confirmation prompt consente di visualizzare un eventuale messaggio di benvenuto prima dell’esecuzione dello script vera e propria. Con un clic su No prompt si può evitare la visualizzazione di qualunque messaggio.

In seguito basta selezionare su Do not display a license quindi fare clic su Add e scegliere lo script PowerShell (nel nostro esempio test.ps1).

In corrispondenza del campo Install program si deve specificare il comando necessario per invocare lo script PowerShell:

PowerShell.exe -noprofile -Sta -executionpolicy bypass -File test.ps1

Al posto di test.ps1 si dovrà ovviamente sostituire il nome dello script PowerShell specificato nella precedente schermata di IExpress.

Se non si dovesse eseguire alcun comando aggiuntivo al termine dello script, basterà lasciare selezionato None in corrispondenza di Post install command.

I passaggi finali consistono nello scegliere Default (recommended), No message quindi indicare il percorso e il nome del file eseguibile (.exe) che si desidera ottenere.

Nella schermata (Configure restart) si può scegliere l’opzione No restart se non fosse necessario richiedere il riavvio del sistema operativo.

Nell’ultima finestra (Save Self Extraction…) si può scegliere Don’t save quindi premere Avanti in corrispondenza di Create package.

Si otterrà così un file eseguibile che con un doppio clic permetterà di avviare istantaneamente lo script PowerShell in esso contenuto.

Ti consigliamo anche

Link copiato negli appunti