Le blog technique

Toutes les astuces #tech des collaborateurs de PI Services.

#openblogPI

Retrouvez les articles à la une

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>

SQL Server – Script Table Row Count in a Database

Ce script très utile pour des travaux d’inventaire ou de statistiques, permet de compter le nombre de lignes que disposent les tables d’une base de données :

USE [DB]
GO
SELECT OBJECT_NAME(OBJECT_ID) TableName, st.row_count
FROM sys.dm_db_partition_stats st
WHERE index_id < 2
ORDER BY st.row_count DESC
GO