Azure AD & BitLocker

La clé BitLocker est sauvegardée automatiquement dans Azure AD quand un usager s’identifie la première fois avec son compte Microsoft 365, mais sous le nom original de l’ordinateur, DESKTOP-* (généré automatiquement).

Si plus tard l’ordinateur est renommé, il est difficile de retrouver l’entrée sous les appareils enregistrés, car celui-ci ne correspond plus au HOSTNAME de l’appareil.

Ainsi, quand on change le nom d’un appareil, mieux vaut aussi le changer dans Azure AD. Malheureusement, ceci ne se fait pas via l’interface web « Azure Active Directory admin center », mais il est possible de le faire via PowerShell:

Install-Module AzureAD
Import-Module AzureAD
$credential = Get-Credential
Connect-AzureAD -Credential $credential
Get-AzureADDevice -objectid "GUID"
Set-AzureADDevice -objectid "GUID" -DisplayName "NAME"

Testé sous Windows PoweShell v.5.1.19041.1682.

Macro pour effacer tous les abonnements RSS dans Outlook

Pour éviter de créer des duplicats d’abonnements RSS dans Outlook, sous File > Options > Advanced décocher:
« Any RSS Feed item that is updated appears as new »; et
« Synchronize RSS Feeds to the Common Feed List (CFL) in Windows. »

Et, pour effacer d’un coup tous les duplicats d’abonement RSS, exécuter cette macro:

Sub DeleteAllRSSFeeds()
    Dim objRSSFeedsFolder As Outlook.Folder
    Dim i As Long
    Dim objRSSFolder As Outlook.Folder
    Dim strRSSName As String
    Dim objDeletedItemsFolder As Outlook.Folder
    Dim objDeletedFolder As Outlook.Folder
 
    Set objRSSFeedsFolder = Application.Session.GetDefaultFolder(olFolderRssFeeds)
 
    'Delete All RSS Folders
    For i = objRSSFeedsFolder.Folders.Count To 1 Step -1
        Set objRSSFolder = objRSSFeedsFolder.Folders(i)
        strRSSName = objRSSFolder.Name
        objRSSFolder.Delete
 
        'Permanently Delete from "Deleted Items" Folder
        Set objDeletedItemsFolder = Application.Session.GetDefaultFolder(olFolderDeletedItems)
        For Each objDeletedFolder In objDeletedItemsFolder.Folders
            If objDeletedFolder.Name = strRSSName Then
               objDeletedFolder.Delete
            End If
        Next
    Next
End Sub

Références

https://www.outlook-tips.net/tips/outlook-duplicates-rss-items/#:~:text=You%20can%20change%20this%20setting,occur%20when%20feeds%20are%20updated
https://www.datanumen.com/blogs/2-easy-methods-batch-delete-rss-feeds-outlook/

Macro Excel pour calculer la distance entre deux lieux via API Google Maps

Function G_DISTANCE(Origin As String, Destination As String) As Double
' Requires a reference to Microsoft XML, v6.0
' Draws on the stackoverflow answer at bit.ly/parseXML
Dim myRequest As XMLHTTP60
Dim myDomDoc As DOMDocument60
Dim distanceNode As IXMLDOMNode
    G_DISTANCE = 0
    ' Check and clean inputs
    On Error GoTo exitRoute
    Origin = WorksheetFunction.EncodeURL(Origin)
    Destination = WorksheetFunction.EncodeURL(Destination)
    ' Read the XML data from the Google Maps API
    Set myRequest = New XMLHTTP60
    myRequest.Open "GET", "http://maps.googleapis.com/maps/api/directions/xml?origin=" _
        & Origin & "&destination=" & Destination & "&sensor=false", False
    myRequest.send
    ' Make the XML readable usign XPath
    Set myDomDoc = New DOMDocument60
    myDomDoc.LoadXML myRequest.responseText
    ' Get the distance node value
    Set distanceNode = myDomDoc.SelectSingleNode("//leg/distance/value")
    If Not distanceNode Is Nothing Then G_DISTANCE = distanceNode.Text / 1000
exitRoute:
    ' Tidy up
    Set distanceNode = Nothing
    Set myDomDoc = Nothing
    Set myRequest = Nothing
End Function

Changer la langue de tout le contenu d’un PowerPoint

Option Explicit   
Public Sub ChangeSpellCheckingLanguage()   
    Dim j As Integer, k As Integer, scount As Integer, fcount As Integer 
    scount = ActivePresentation.Slides.Count 
    For j = 1 To scount 
        fcount = ActivePresentation.Slides(j).Shapes.Count 
        For k = 1 To fcount 
            If ActivePresentation.Slides(j).Shapes(k).HasTextFrame Then 
                ActivePresentation.Slides(j).Shapes(k) _ 
                .TextFrame.TextRange.LanguageID = msoLanguageIDFrenchCanadian 
            End If 
        Next k 
    Next j 
End Sub

Codes de langues

msoLanguageIDFrenchCanadian
msoLanguageIDEnglishUS
msoLanguageIDEnglishCanadian

Exporter historique TFS en CSV

using System;
using System.IO;
using System.Text;
using System.Windows.Forms;
 
using Microsoft.TeamFoundation.Client; // NuGet
using Microsoft.TeamFoundation.VersionControl.Client; // GAC
 
namespace TFSHistory
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
 
        private void button1_Click(object sender, EventArgs e)
        {
            var tpp = new TeamProjectPicker(TeamProjectPickerMode.SingleProject, true);
            var result = tpp.ShowDialog();
            if (result != DialogResult.OK) return;
 
            var tpc = tpp.SelectedTeamProjectCollection;
            var versionControl = tpc.GetService<VersionControlServer>();
 
            var tp = versionControl.GetTeamProject(tpp.SelectedProjects[0].Name);
            var path = tp.ServerItem;
 
            var q = versionControl.QueryHistory(path, VersionSpec.Latest, 0, RecursionType.Full, null, new ChangesetVersionSpec(1), VersionSpec.Latest, Int32.MaxValue, false, true, false, false);
           
            using (var file = new StreamWriter(@"fichier.csv", true, Encoding.UTF8))
            {
                file.AutoFlush = true;
                file.WriteLine("CS, Date, User, Comment");
 
                foreach (Changeset cs in q)
                {
                    if (cs.Committer.Contains("Elastic")) continue;
                    if (string.IsNullOrWhiteSpace(cs.Comment)) continue;
 
                    var comment = cs.Comment;
                    comment = comment.Replace(',', ' ');
                    comment = comment.Replace(Environment.NewLine, " ");
 
                    file.WriteLine(string.Format("{0},{1},{2},{3}", cs.ChangesetId, cs.CreationDate, cs.Committer, comment));
                }
            }
        }
    }
}

Ajuster le compte des commentaires et des catégories sous WordPress après importation

<?php
// Place this file in your root directory and navigate to it.  Script will correct counts for comments and categories.
include("wp-config.php");

if (!mysql_connect(DB_HOST, DB_USER, DB_PASSWORD)) {  die('Could not connect: ' . mysql_error());  }
if (!mysql_select_db(DB_NAME)) {  die('Could not connect: ' . mysql_error());  }

$result = mysql_query("SELECT term_taxonomy_id FROM ".$table_prefix."term_taxonomy");
while ($row = mysql_fetch_array($result)) {
  $term_taxonomy_id = $row['term_taxonomy_id'];
  echo "term_taxonomy_id: ".$term_taxonomy_id." count = ";
  $countresult = mysql_query("SELECT count(*) FROM ".$table_prefix."term_relationships WHERE term_taxonomy_id = '$term_taxonomy_id'");
  $countarray = mysql_fetch_array($countresult);
  $count = $countarray[0];
  echo $count."<br />";
 mysql_query("UPDATE ".$table_prefix."term_taxonomy SET count = '$count' WHERE term_taxonomy_id = '$term_taxonomy_id'");
		}

$result = mysql_query("SELECT ID FROM ".$table_prefix."posts");
while ($row = mysql_fetch_array($result)) {
  $post_id = $row['ID'];
  echo "post_id: ".$post_id." count = ";
  $countresult = mysql_query("SELECT count(*) FROM ".$table_prefix."comments WHERE comment_post_ID = '$post_id' AND comment_approved = 1");
  $countarray = mysql_fetch_array($countresult);
  $count = $countarray[0];
  echo $count."<br />";
  mysql_query("UPDATE ".$table_prefix."posts SET comment_count = '$count' WHERE ID = '$post_id'");
		}
?>

Certificats Windows sous Java

Sous Java, la procédure normale pour utiliser des certificats PKI SSL est de les importer dans le Trust Store et Key Store en utilisant l’outil keytool disponible dans le JDK. Un autre bon outil pour manipuler les keystore est Key Store Explorer (KSE)

Par contre, sous Windows, les certificats sont installés dans Windows Certificate Store. Est-il réellement nécessaire de les exporter (ce qui implique avoir accès à la clé privé), les transformer (avec OpenSSL) et de les importer dans les fichiers JKS de Java?

Bien, il s’avère que non, puisqu’il soit possible de lancer une JVM avec les paramètres suivants pour utiliser les certificats de Windows directement:

java -Djavax.net.ssl.trustStoreType=Windows-ROOT -Djavax.net.ssl.keyStoreType=Windows-MY

Ceci est rendu possible grâce au SunMSCAPI JCE Provider et cela fontionne bien pour des certificats générés à partir d’un crypto basée sur RSA.

Par contre, pour des certificats générés en utilisant la crypto moderne, bien Java 8 supporte les certificats de la nouvelle génération stockés dans les fichiers JKS, SunMSCAPI, qui n’a pas évolué, ne supporte pas CNG (CryptoAPI Next Generation).

Ainsi, avec Java 8 et des certificats moderne, de retour à la case départ…

À quand une nouvelle génération du provider SunMSCAPI (ou une alternative) permettant d’aller lire directement les certificats CNG dans le Microsoft Certificate store? Car, pour l’instant, il semble qu’il existe au moyen outre codé soi-même en JNI / JNA une interface à CNG.

Pheox JCAPI offre bien une alternative à SunMSCAPI, mais ce produit commercial n’a pas évolué avec le temps et ne supporte pas CNG.

Changer la clé de produit Microsoft Office 2013 sur VM Azure

Après un certain temps, à force de changer d’adresse IP, la licence d’Office 2013 sur une VM Azure finit par détecter un changement de matériel et se désactive. Si on a une licence MSDN ou BizSpark sous main, on peut contourner ce problème en changeant sa clé de produit en ouvrant une ligne de commande: (Windows-R, CMD) en lancer la commande:

cscript « C:Program FilesMicrosoft OfficeOffice15OSPP.VBS » /inpkey:NOUVELLE-CLÉ

ou

cscript « C:Program Files (x86)Microsoft OfficeOffice15OSPP.VBS » /inpkey::NOUVELLE-CLÉ

Selon sa combinaison de Windows et Office 32 ou 64 bits.

 

Macro pour dévérouiller un fichier Excel par la méthode « Brute Force »

Sub PasswordBreaker()
Dim i As Integer, j As Integer, k As Integer
Dim l As Integer, m As Integer, n As Integer
Dim i1 As Integer, i2 As Integer, i3 As Integer
Dim i4 As Integer, i5 As Integer, i6 As Integer
On Error Resume Next
For i = 65 To 66: For j = 65 To 66: For k = 65 To 66
For l = 65 To 66: For m = 65 To 66: For i1 = 65 To 66
For i2 = 65 To 66: For i3 = 65 To 66: For i4 = 65 To 66
For i5 = 65 To 66: For i6 = 65 To 66: For n = 32 To 126
ActiveSheet.Unprotect Chr(i) & Chr(j) & Chr(k) & _
Chr(l) & Chr(m) & Chr(i1) & Chr(i2) & Chr(i3) & _
Chr(i4) & Chr(i5) & Chr(i6) & Chr(n)
If ActiveSheet.ProtectContents = False Then
MsgBox « One usable password is  » & Chr(i) & Chr(j) & _
Chr(k) & Chr(l) & Chr(m) & Chr(i1) & Chr(i2) & _
Chr(i3) & Chr(i4) & Chr(i5) & Chr(i6) & Chr(n)
Exit Sub
End If
Next: Next: Next: Next: Next: Next
Next: Next: Next: Next: Next: Next
End Sub

Kasparov vs. Deep Blue – Un bug permet la victoire !

En 1997, le super ordinateur Deep Blue d’IBM bat le champion mondial d’échecs  Garry Kasparov, alors que celui-ci s’était vanté de ne jamais pouvoir se faire battre pour une machine. Un mouvement en particulier que la machine a fait, le sacrifice d’une pièce, aurait déstabilisé Kasparov, croyant que ça laissait présager à une stratégie de longue haleine. On avait à l’époque pensé qu’une telle stratégie était trop sophistiquée pour une machine, et qu’un  humain avait sûrement intervenu pendant la partie. En fait, 15 ans plus tard, la vérité éclate au grand jour. Le mouvement en question était en fait le résultat d’un bug informatique! La machine n’aurait pas su quoi jouer et en aurait donc choisit un au hasard…