Since PowerShell Core 6, PowerShell became cross-platform, free and open source. There is, of course, some limitations when it comes to PowerShell for non-Windows platforms. Microsoft documentation explains that: “PowerShell on Linux and macOS uses .NET Core, which is a subset of the full .NET Framework on Microsoft Windows. As a result, scripts that run […]
Automatically elevate a Powershell session
By default, recent versions of Windows ship with something called User Account Control (UAC). Because of this, “standard users and administrators access resources and run apps in the security context of standard users”. For this to work Windows creates two different types of tokens based on the user privileges: Standard user access token Administrator access […]
Programmatically switch between audio devices in Windows
Recent versions of Windows offer simple ways to change your default audio devices to play or record sounds. In the case of Windows 10, that option is conveniently located in the task bar. But what if you want to automatically change the audio device? Manage your audio devices from PowerShell with AudioDeviceCmdlets AudioDeviceCmdlets is a […]
Use CSS to style HTML reports in PowerShell
ConvertTo-HTML allows to add all kind of different elements into an HTML file. HTML files have a simple structure that usually include a head and a body. Those elements can be modified with ConvertTo-HTML parameters. Let us check the syntax of this cmdlet first (this cmdlet has two sets of parameters, we are using the […]
Encrypting data with a key in PowerShell
If you need to encrypt text in your PowerShell code, ConvertFrom-SecureString can help you do it. The -Key parameter of that cmdlet allows you to use a key that can be stored in a file. This could be useful if you don’t want to have sensitive information in plain text in your code. Let us […]
Create a new Windows Domain with Ansible using the win_powershell module
In this entry, we are going to use Ansible to manage a Windows host. To create a control node, the machine that is going to run Ansible, you have to use a UNIX-like system. This opens the possibility to use the Windows Subsystem for Linux if an independent control node is not an option for […]
Creating your own objects with PSCustomObject
PSCustomObject offers us an excellent way to create structured data in PowerShell. According to the documentation, [pscustomobject] is a type accelerator. Type accelerators “allow you to access specific .NET framework classes without having to explicitly type the entire class name”. The full class name for PSCustomObject is System.Management.Automation.PSObject, which means PSCustomObject is just an alias […]