Le blog technique

Toutes les astuces #tech des collaborateurs de PI Services.

#openblogPI

Retrouvez les articles à la une

Utilisation des Windows forms .Net via Powershell sous WinPE 4

Depuis WinPe 4, il est possible d’utiliser des forms issues du .net via Powershell.

Pour cela, il faut rajouter à votre image wim des packages issues de l’adk.

Monter tout d’abord votre image wim

imagex64.exe /mountrw c:\winpe4_x86\media\sources\boot.wim 1 c:\winpe4_x86\mount

clip_image002

clip_image003

Installation du 1er Package: Netfx4

dism /image:c:\winpe4_x86\mount /add-package /packagepath:"C:\Program Files (x86)\Windows Kits\8.0\Assessment and Deployment Kit\Windows Preinstallation Environment\x86\WinPE_OCs\winpe-netfx4.cab"

clip_image005

Installation du 2nd Package: Powershell3

dism /image:c:\winpe4_x86\mount /add-package /packagepath:"C:\Program Files (x86)\Windows Kits\8.0\Assessment and Deployment Kit\Windows Preinstallation Environment\x86\WinPE_OCs\winpe-powershell3.cab"

clip_image007

Une fois ceux ci installé, démonté votre image wim.

imagex64.exe /unmount c:\winpe4_x86\mount /commit

Démarrer maintenant sur votre PE.

clip_image009

Et là, nous allons lancer un exemple de script ps1 faisant appel à une interface graphique apporté par le Framework .NET.

clip_image011

Nous pouvons donc imaginer en remplacement du HTA, une interface faisant appel aux Forms pour l’élaboration d’un Master par exemple.

Client http sous Powershell

A l’image de Wget qui est un client http, nous pouvons faire appel en powershell à un objet qui permettra donc d’effectuer des requêtes depuis des Urls. Pour cela, il faut utiliser un objet particulier : system.net.webclient

Regardons maintenant certaines propriétés qu’il propose :

(new-object system.net.webclient) | gm

clip_image001

Maintenant, imaginons que nous disposons d’une Url nous retournant un résultat formaté en fichier type csv (séparateur : virgule) nous renvoyant des informations que nous désirons récupérés dans nos scripts, il suffit pour cela de télécharger via la méthode DownloadFile les informations dans un fichier. Et ensuite d’importer ce fichier dans une variable.

Exemple:

$client=new-object system.net.webclient

$url="http://AppelUrl.local"

$path="c:\test\DataUrl.txt"

$client.DownloadFile ($url, $path)

$csv=Import-Csv $path -header intitulé,Process

clip_image002

A partir de là, nous pouvons facilement exploiter les données reçues par l’url.

Récupérer les paramètres Firefox quel que soit la version par USMT

Vous souhaitez récupérer via l’outil USMT les favoris Firefox.

Cependant depuis quelques temps, le nombre de versions de Firefox a augmenté de façon importante.

Pour supporter l’ensemble des versions de Firefox, ouvrez donc le fichier xml MigApp de USMT.

Identifiez la partie consacrée à Firefox

<!– Mozilla Firefox 3 –>

<component context="UserAndSystem" type="Application">

<displayName _locID="migapp.firefox3">Mozilla Firefox</displayName>

<environment name="GlobalEnv"/>

<environment name="GlobalEnvX64"/>

<role role="Settings">

<detection>

<conditions>

<condition>MigXmlHelper.DoesObjectExist("Registry","%HklmWowSoftware%\Mozilla\Mozilla Firefox 3.*\bin [PathToExe]")</condition>

</conditions>

</detection>

<rules context="User">

<destinationCleanup>

<objectSet>

<pattern type="File">%CSIDL_LOCAL_APPDATA%\Mozilla\Firefox\Profiles\*\Cache\* [*]</pattern>

</objectSet>

</destinationCleanup>

<include>

<objectSet>

<pattern type="File">%CSIDL_APPDATA%\Mozilla\Firefox\* [*]</pattern>

<pattern type="File">%CSIDL_LOCAL_APPDATA%\Mozilla\Firefox\Profiles\* [*]</pattern>

</objectSet>

</include>

<exclude>

<objectSet>

<pattern type="File">%CSIDL_APPDATA%\Mozilla\Firefox\Crash Reports\* [*]</pattern>

<pattern type="File">%CSIDL_APPDATA%\Mozilla\Firefox\Profiles\*\ [pluginreg.dat]</pattern>

<pattern type="File">%CSIDL_LOCAL_APPDATA%\Mozilla\Firefox\Profiles\*\Cache\* [*]</pattern>

</objectSet>

</exclude>

<merge script="MigXmlHelper.SourcePriority()">

<objectSet>

<pattern type="File">%CSIDL_APPDATA%\Mozilla\Firefox\* [*]</pattern>

<pattern type="File">%CSIDL_LOCAL_APPDATA%\Mozilla\Firefox\Profiles\* [*]</pattern>

</objectSet>

</merge>

</rules>

</role>

</component>

Pour supporter l’ensemble des versions de Firefox, il suffit de modifier un seul caractère correspondant à la version par le caractere « * » à la ligne correspondant à :

<condition>MigXmlHelper.DoesObjectExist("Registry","%HklmWowSoftware%\Mozilla\Mozilla Firefox 3.*\bin [PathToExe]")</condition>

Exemple :

<!– Mozilla Firefox –>

<component context="UserAndSystem" type="Application">

<displayName _locID="migapp.firefox3">Mozilla Firefox</displayName>

<environment name="GlobalEnv"/>

<environment name="GlobalEnvX64"/>

<role role="Settings">

<detection>

<conditions>

<condition>MigXmlHelper.DoesObjectExist("Registry","%HklmWowSoftware%\Mozilla\Mozilla Firefox *.*\bin [PathToExe]")</condition>

</conditions>

</detection>

<rules context="User">

<destinationCleanup>

<objectSet>

<pattern type="File">%CSIDL_LOCAL_APPDATA%\Mozilla\Firefox\Profiles\*\Cache\* [*]</pattern>

</objectSet>

</destinationCleanup>

<include>

<objectSet>

<pattern type="File">%CSIDL_APPDATA%\Mozilla\Firefox\* [*]</pattern>

<pattern type="File">%CSIDL_LOCAL_APPDATA%\Mozilla\Firefox\Profiles\* [*]</pattern>

</objectSet>

</include>

<exclude>

<objectSet>

<pattern type="File">%CSIDL_APPDATA%\Mozilla\Firefox\Crash Reports\* [*]</pattern>

<pattern type="File">%CSIDL_APPDATA%\Mozilla\Firefox\Profiles\*\ [pluginreg.dat]</pattern>

<pattern type="File">%CSIDL_LOCAL_APPDATA%\Mozilla\Firefox\Profiles\*\Cache\* [*]</pattern>

</objectSet>

</exclude>

<merge script="MigXmlHelper.SourcePriority()">

<objectSet>

<pattern type="File">%CSIDL_APPDATA%\Mozilla\Firefox\* [*]</pattern>

<pattern type="File">%CSIDL_LOCAL_APPDATA%\Mozilla\Firefox\Profiles\* [*]</pattern>

</objectSet>

</merge>

</rules>

</role>

</component>