There can always be only one physically logged on user on a machine. The physically logged on user is the one sitting right at the machine. Here is...
ps1
Accessing an SQL Database with a Connection String
In a previous tip we explained how you can construct the connection string to a SQL database. Whether you use this to create the connection string,...
Getting SQL Server Connection String
If you’d like to contact an SQL Server database via PowerShell, you need a connection string. The connection string contains all pieces of...
Updating Your Office Phone Number in Active Directory
If you have installed the free RSAT tools from Microsoft, you can use PowerShell to update information stored in your AD user account, for example...
Adding Custom Attributes to AD Objects
If you’d like to add custom attributes to an AD object, simply use a hash table, and add the desired attribute names and their values. Then...
Cloning Active Directory Security Settings
Whenever you add delegation rights to an AD object (i.e. allow a user to manage the members of an organizational unit), you really invoke a change...
Get Command History as File
The built-in PowerShell ISE editor that ships with PowerShell 3.0 or better can be customized, and you can add your own menu items. When you run the...
Simple AD Group Management
Provided you have downloaded and installed Microsoft’s free RSAT tools, managing AD groups and group members is very simple. Here are some...
Using PowerShell Help
To access the full PowerShell help, you first need to download help information from the Internet. Simply launch a PowerShell console with full...
Setting AD Account Expiration Date
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...
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:...