To safely use temporary AD accounts, for example for guests or consultants, always make sure to set an expiration date. Here is some sample code...
Powershell
Bulk-Remove Protection for Accidental Deletion in AD
By default, AD objects are protected from accidental deletion. To remove this protection for all objects in a given scope (i.e. all objects in an...
First Steps Automating AD
When you download the free RSAT tools from Microsoft, these include the ActiveDirectory module. It contains a rich set of cmdlets to manage Active...
Changing Local Administrator Account Password
To access local user accounts and assign a new password, you can use the low-level WinNT: namespace. Note: you do need Administrator privileges to...
Encrypting Text
There are many ways to encrypt text. Here is an approach that does not use an explicit “secret”. Instead, the secret is defined as your...
Moving Outdated Log Files to Archive
Occasionally, you may want to move files to an archive folder when they are older than a given number of days. Here is an example that illustrates...
Create Benign “Task Kill” Application
In a previous tip we showed how you can select applications and kill them immediately. All unsaved data in the applications would get lost. Here is...
Create “Task Kill” Application
With just one pipeline command, PowerShell can open a list of running applications. You can then select one or more in the list (hold CTRL to select...
Open Web Page
To quickly open a new web page in the Internet Explorer, you could define a new function called Show-WebPage like this: #requires -Version 2...
Getting Active Directory User Name
Here is a quick way to find the current user in your Active Directory and retrieve account information such as the display name:...
Adding "List All Variables" to PowerShell ISE
In a previous tip we showed a script that would find all variable names in all scripts open in PowerShell ISE. Here is an adaption that adds a new...
Listing All Variables in All Scripts
Ever wanted an inventory of variable names used in all open scripts in the PowerShell ISE? Here is some code that you can run to create such a list:...
Quick Loop
Requires PowerShell 4.0 There are plenty of looping constructs in PowerShell. Here is a rather unusual way introduced in PowerShell 4.0 to repeat...
Analyzing (All) Event Log Entries
You probably know Get-EventLog. This cmdlet can dump all entries from a given event log: Get-EventLog -LogName System However, Get-EventLog can only...
Finding the Most Important Event Log Error Sources
If you don't have much time yet would like to know what the most common sources of errors are in your System event log, try this line:...
Refresh Newly Mounted Disks
If your script has just mounted a new drive, PowerShell may not immediately be able to access it (via Get-ChildItem, for example), because...
Load Cmdlets from PSSnapins
Most cmdlets these days are organized in modules. Modules were introduced in PowerShell 2.0. Their main advantage is copy&paste deployment (no...
Loading PowerShell Modules
All cmdlets live in modules or snap-ins. To see which modules are currently loaded, use Get-Module. In PowerShell 3.0 or better, most modules are...
How to find Commands that have the Specified Parameter
Get-Command is your primary tool when you need to find a command to accomplish something. You can search for verbs and/or nouns like this: # find...
Get CPU Cores and Processor Information
WMI can find out details about your CPUs in just one line: PS> Get-WmiObject -Class Win32_Processor | Select-Object -Property Name, Number* Name...
Installing Windows Features
On servers, PowerShell can install Windows features with the cmdlet Install-WindowsFeature. When you save the result emitted by...
Create Dynamic Script Blocks
Script blocks are pieces of executable PowerShell code. You typically create them by enclosing code in braces. To dynamically create script blocks...
Manage NTFS Permission Inheritance
By default, folders and files inherit permissions from their parents. To stop inheritance and make sure only the explicitly assigned permissions are...
Removing Explicit NTFS Permissions
In previous examples, we showed you how you can add new NTFS permissions to an existing folder. If you want to reset permissions and make sure all...