Tag: PowerShell
March 27, 2025 |
PowerShell Grep Command
The Unix/Linux grep command is a versatile text search utility used for log analysis, code scanning, and system diagnostics. It supports case-insensitive searches, recursive directory scans, inverted matches, line numbers, and advanced regex patterns like lookahead and lookbehind. On Windows,...
March 26, 2025 |
PowerShell Execution Policy
PowerShell execution policies control script execution conditions to reduce accidental or unsafe runs. They range from restrictive (Restricted, AllSigned) to permissive (Unrestricted, Bypass) and can be applied at multiple scopes such as Process, CurrentUser, and LocalMachine. While not a security...
February 20, 2025 |
PowerShell Foreach Loop Explained: Syntax, Examples and Best Practices
The PowerShell ForEach loop simplifies iterating over collections like arrays, lists, or pipeline output, making it essential for automation and data processing. It executes a block of code for each item, supporting use cases such as renaming files, updating Active Directory users, or parsing...
February 14, 2025 |
Mastering PowerShell Sleep for Script Management
PowerShell’s Start-Sleep cmdlet pauses script execution for a defined time, helping manage timing, synchronization, and throttling. It supports seconds, milliseconds, or time spans (-Duration) and is often used in loops, scheduling, or waiting for resources. Alternatives like Read-Host enable...
February 12, 2025 |
Functions in PowerShell Scripts
PowerShell functions group reusable code into modular, maintainable units that simplify scripting and reduce errors. Defined with the function keyword, they can include parameters, accept pipeline input, and behave like cmdlets using [CmdletBinding()]. Functions support advanced features such as...
January 14, 2025 |
PowerShell Environment Variables
PowerShell environment variables store system and user configuration as key-value pairs accessible across processes and scripts. They can be listed with Get-ChildItem Env:, accessed with $Env:<Name>, modified with Set-Item or [Environment]::SetEnvironmentVariable(), and removed with...
January 10, 2025 |
How to Run a PowerShell Script
PowerShell scripts automate administrative tasks across Windows, Linux, and macOS, but execution is restricted by default for security. Users must adjust execution policies, launch PowerShell or CMD, and specify full or relative script paths. Scripts can include parameters, run with elevated...
November 21, 2024 |
PowerShell Write to File: "Out-File" and File Output Techniques
PowerShell output goes to the console by default, but you can redirect results to files for logging, reporting, automation, or troubleshooting. The Out-File cmdlet gives full control over encoding, line width, and overwrite behavior, while redirection operators (>, >>) are quicker for simple jobs....
November 20, 2024 |
Add Alias in Active Directory
Active Directory supports email aliases through the proxyAddresses attribute, which stores primary and secondary addresses. Aliases allow role-based addresses, simplify administration, and centralize communication in Exchange or Microsoft 365 without extra mailboxes. You can manage them via ADUC...
November 5, 2024 |
Delete Registry Keys Using PowerShell
PowerShell enables safe, automated deletion of Windows Registry keys and values using cmdlets like Remove-Item for keys and Remove-ItemProperty for values. Before deletion, always back up keys with Registry Editor or PowerShell and verify their existence with Test-Path. Use -WhatIf, -Confirm, or...