Check last exit code with PowerShell

In a script containing a lot of commands, it could be very helpful to be able to check if their execution are successful or not. To check the last exit code returned in a PowerShell script, the variable $lastExitCode can be used. $lastExitCode contains the exit code of the last Win32 executable execution. Here is … Read more

Import Certificate

1. On Windows 10 Since Windows 8 and Windows Server 2012, importing certificates can be done easily using PowerShell, and more precisely with the command Import-Certificate This cmdlet allows to import one or more certificates in to a certificate store. In case of PFX certificate, the command Import-PfxCertificate can be used (Imports certificates and private … Read more

Countdown in a PowerShell GUI

The following script allows to include a countdown in a PowerShell-based GUI. Basically, a “timer” object is used to decrement a variable. In this example: The countdown is initialized to 10 Then, a timer is used to run a function every second This function decrement the countdown When the value of the countdown equal 0, … Read more

Check OS with PowerShell

All information relative to the Operating System installed can be retrieved from the registry and more especially in the following key: HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion . Until Windows 8.1, the entry CurrentVersion could be used to retrieve the Windows OS version: . But, this entry is deprecated since Windows 10, and Microsoft recommends to use the following … Read more

Check if a user is logged-in with PowerShell

Patching machines is usually a constraint for the end user, mainly because of the reboot required at the end of the update… A good workaround to update machines without disrupting the user is to apply the patch and then reboot when no user is logged on the machine. Many possibilities exist to check whether a … Read more

Disable NetBIOS with PowerShell

1. NetBIOS and Direct Hosting With direct hosting, NetBIOS is not used for name resolution. DNS is used for name resolution and the Microsoft networking communication is sent directly over TCP without a NetBIOS header. Direct hosting over TCP/IP uses TCP port 445 instead of the NetBIOS session TCP port 139. By default, both NetBIOS … Read more

Hide PowerShell Console from a GUI

PowerShell is a very powerfull scripting language that allows you to build many useful tools using command lines. For a better interactivity, it’s also possible to build a graphical user interface (GUI) allowing to pilot these tools. By default, when a PowerShell script containing a GUI is run, the user interface is displayed of course, … Read more

Windows 10 Customization

Here are a few customization that can be done on a Windows 10 image. Enable PowerShell Remoting Configure Remote Desktop Enable App-V Make IE the Default Browser Disable Quick Access: Recent Files Disable Quick Access: Frequent Folders Change Explorer Home Screen back to This PC Set Lock Screen Set Wallpaper Remove Built-in Apps Remove Edge … Read more

Import and Activate Power Scheme

How to import a power scheme and then activate it? Let’s consider the following power scheme: Name: Corporate-Balanced Power Scheme GUID: dam2e870-e11b-4b99-88d9-9bec021a7dbs This power scheme has been saved as mypowerscheme.pow . Import Power Scheme powercfg.exe /import mypowerscheme.pow dam2e870-e11b-4b99-88d9-9bec021a7dbs . . Activate Power Plan powercfg.exe /s dam2e870-e11b-4b99-88d9-9bec021a7dbs . . Result The following power plan is created … Read more

Disabling UAC for Individual Applications

1. UAC Incompatibility Some applications, even if compatible with the Operating System, are sometimes not compatible with UAC and prompt for administrator credentials when you try to launch them. This is really an issue for standard users who usually don’t have administrator account… For example, after having Lotus Notes 7 installed, when you try to … Read more