PowerShell
Filter by Set
...see more

Writes the specified objects to the pipeline. If Write-Output is the last command in the pipeline, the objects are displayed in the console.

Write-Output
     [-InputObject] <PSObject[]>
     [-NoEnumerate]
     [<CommonParameters>]

Write-Output sends objects to the primary pipeline, also known as the "output stream" or the "success pipeline." To send error objects to the error pipeline, use Write-Error.

This cmdlet is typically used in scripts to display strings and other objects on the console. One of the built-in aliases for Write-Output is echo and similar to other shells that use echo. The default behavior is to display the output at the end of a pipeline.

Examples

Write-Output "Warning: setting not available"
Write-Output "Error message" >> $logfile
Write-Output "$Message" | Tee-Object $logFile -Append

Additional Resources

...see more

Saves command output in a file or variable and also sends it down the pipeline.

Tee-Object
   [-InputObject <PSObject>]
   [-FilePath] <String>
   [-Append]
   [[-Encoding] <Encoding>]
   [<CommonParameters>]

The Tee-Object cmdlet redirects output, that is, it sends the output of a command in two directions (like the letter T). It stores the output in a file or variable and also sends it down the pipeline. If Tee-Object is the last command in the pipeline, the command output is displayed at the prompt.

Example

Write-Output "$Message" | Tee-Object $logFile -Append
...see more

The PowerShell redirection operators are as follows, where n represents the stream number. The Success stream ( 1 ) is the default if no stream is specified.

  • > Send specified stream to a file. n>
  • >> Append specified stream to a file. n>>
  • >&1 Redirects the specified stream to the Success stream. n>&1

This example sends all Success stream data to a file called script.log.

.\script.ps1 > script.log

This example sends all streams output from a script called script.ps1 to a file called script.log

.\script.ps1 *> script.log

Source: about Redirection - PowerShell | Microsoft Docs

...see more

Writes customized output to a host.

Write-Host
     [[-Object] <Object>]
     [-NoNewline]
     [-Separator <Object>]
     [-ForegroundColor <ConsoleColor>]
     [-BackgroundColor <ConsoleColor>]
     [<CommonParameters>]

The Write-Host cmdlet's primary purpose is to produce for-(host)-display-only output, such as printing colored text like when prompting the user for input in conjunction with Read-Host. Write-Host uses the ToString() method to write the output. By contrast, to output data to the pipeline, use Write-Output or implicit output.

Write-Host "no newline test " -NoNewline
Write-Host "second string"

no newline test second string

Further information can be found at Write-Host (Microsoft.PowerShell.Utility) - PowerShell | Microsoft Docs.

...see more

The Copy-Item cmdlet copies an item from one location to another location in the same namespace. For instance, it can copy a file to a folder, but it can't copy a file to a certificate drive.

Copy a file to the specified directory

This example copies the mar1604.log.txt file to the C:\Presentation directory. The original file isn't deleted.

Copy-Item "C:\Wabash\Logfiles\mar1604.log.txt" -Destination "C:\Presentation"

Copy directory contents to an existing directory

This example copies the contents of the C:\Logfiles directory into the existing C:\Drawings directory. The Logfiles directory isn't copied.

If the Logfiles directory contains files in subdirectories, those subdirectories are copied with their file trees intact. By default, the Container parameter is set to True, which preserves the directory structure.

Copy-Item -Path "C:\Logfiles\*" -Destination "C:\Drawings" -Recurse

Further information and samples can be found at Copy-Item (Microsoft.PowerShell.Management) - PowerShell | Microsoft Docs

...see more

Selects objects or object properties.

The Select-Object cmdlet selects specified properties of an object or set of objects. It can also select unique objects, a specified number of objects, or objects in a specified position in an array.

To select objects from a collection, use the FirstLastUniqueSkip, and Index parameters. To select object properties, use the Property parameter. When you select properties, Select-Object returns new objects that have only the specified properties.

Example 1: Select objects by property

This example creates objects that have the Name, ID, and working set (WS) properties of process objects.

Get-Process | Select-Object -Property ProcessName, Id, WS

Select-Object (Microsoft.PowerShell.Utility) - PowerShell | Microsoft Docs

...see more

Module: Microsoft.PowerShell.Utility

Creates table-like custom objects from the items in a comma-separated value (CSV) file.

Import-Csv
      [[-Delimiter] <Char>]
      [-Path] <String[]>
      [-Header <String[]>]
      [-Encoding <Encoding>]
      [<CommonParameters>]

The Import-Csv cmdlet creates table-like custom objects from the items in CSV files. Each column in the CSV file becomes a property of the custom object and the items in rows become the property values. Import-Csv works on any CSV file, including files that are generated by the Export-Csv cmdlet.

Import-Csv (Microsoft.PowerShell.Utility) - PowerShell | Microsoft Docs

...see more

Module: Microsoft.PowerShell.Core

Performs an operation against each item in a collection of input objects.

ForEach-Object
            [-InputObject <PSObject>]
            [-Begin <ScriptBlock>]
            [-Process] <ScriptBlock[]>
            [-End <ScriptBlock>]
            [-RemainingScripts <ScriptBlock[]>]
            [-WhatIf]
            [-Confirm]
            [<CommonParameters>]

The ForEach-Object cmdlet performs an operation on each item in a collection of input objects. The input objects can be piped to the cmdlet or specified by using the InputObject parameter.

Starting in Windows PowerShell 3.0, there are two different ways to construct a ForEach-Object command.

...see more

Module: Microsoft.PowerShell.Utility

Converts object properties in comma-separated value (CSV) format into CSV versions of the original objects.

ConvertFrom-Csv
                [[-Delimiter] <Char>]
                [-InputObject] <PSObject[]>
                [-Header <String[]>]
                [<CommonParameters>]

The ConvertFrom-Csv cmdlet creates objects from CSV variable-length strings that are generated by the ConvertTo-Csv cmdlet.

ConvertFrom-Csv (Microsoft.PowerShell.Utility) - PowerShell | Microsoft Docs

...see more

Selects objects from a collection based on their property values.

Where-Object
     [-InputObject <PSObject>]
     [-Property] <String>
     [[-Value] <Object>]
     [-EQ]
     [<CommonParameters>]

The Where-Object cmdlet selects objects that have particular property values from the collection of objects that are passed to it. For example, you can use the Where-Object cmdlet to select files that were created after a certain date, events with a particular ID, or computers that use a particular version of Windows.

Example 1: Get stopped services

Get-Service | Where-Object {$_.Status -eq "Stopped"}
Get-Service | where Status -eq "Stopped"

Where-Object (Microsoft.PowerShell.Core) - PowerShell | Microsoft Docs

...see more

Module: Az.ConnectedMachine

Retrieves information about the model view or the instance view of a hybrid machine.

Get-AzConnectedMachine
   [-SubscriptionId <String[]>]
   [-DefaultProfile <PSObject>]
   [<CommonParameters>]

Retrieves information about the model view or the instance view of a hybrid machine.

Example 1: List all connected machines in a subscription

Get-AzConnectedMachine -SubscriptionId 67379433-5e19-4702-b39a-c0a03ca8d20c

Name           Location OSName   Status     ProvisioningState
----           -------- ------   ------     -----------------
winwestus2_1   westus2  windows  Connected  Succeeded
linwestus2_1   westus2  linux    Connected  Succeeded
winwestus2_2   westus2  windows  Connected  Succeeded
winwestus2_3   westus2  windows  Connected  Succeeded

Get-AzConnectedMachine (Az.ConnectedMachine) | Microsoft Docs

...see more

Gets preferences for the Windows Defender scans and updates.

Get-MpPreference
  [-CimSession <CimSession[]>]
  [-ThrottleLimit <Int32>]
  [-AsJob]
  [<CommonParameters>]

The Get-MpPreference cmdlet gets preferences for the Windows Defender scans and updates. For more information about the preferences that this cmdlet retrieves, see Windows Defender Preferences Class.

Example to view the scheduled scan day

  • The first command gets the preferences and then stores them in the $Preferences variable.
  • The second command uses standard dot syntax to display the ScanScheduleDay property of the object stored in the $Preferences variable.
$Preferences = Get-MpPreference
$Preferences.ScanScheduleDay

Details about the preferences for Windows Defender scans and updates can be found in Set-MpPreference PowerShell Cmdlet.

For additional details visit Get-MpPreference (Defender) | Microsoft Docs.

...see more

Module: Defender

Configures preferences for Windows Defender scans and updates.

The Set-MpPreference cmdlet configures preferences for Windows Defender scans and updates. You can modify exclusion filename extensions, paths, or processes, and specify the default action for high, moderate, and low threat levels.

Examples

Example to schedule to check for definition updates everyday.

This command configures preferences to check for definition updates every day.

Set-MpPreference -SignatureScheduleDay Everyday

Additional examples at Schedule antivirus scans using PowerShell | Microsoft Docs

Details about the cmdlet at Set-MpPreference (Defender) | Microsoft Docs

...see more

To construct an array of objects in PowerShell, each item within the array is inherently treated as an object. Unlike conventional arrays that may consist of strings or integers, PowerShell arrays primarily contain objects. Below is a structured example demonstrating the creation of an array comprising objects through explicit declaration:

$people = @(
    [PSCustomObject]@{Name='John'; Age=26},
    [PSCustomObject]@{Name='Jane'; Age=22}
)

In this illustration, $people is an array variable containing two objects. Each object is defined using the [PSCustomObject] syntax followed by property-value pairs enclosed within curly braces {}. This structured approach ensures clarity and ease of comprehension while creating arrays of objects in PowerShell.

...see more

Using the *-Content cmdlets. There are four *-Content cmdlets:

  • Add-Content – appends content to a file.
  • Clear-Content – removes all content of a file.
  • Get-Content – retrieves the content of a file.
  • Set-Content – writes new content which replaces the content in a file.

The two cmdlets you use to send command or script output to a file are Set-Content and Add-Content. Both cmdlets convert the objects you pass in the pipeline to strings and then output these strings to the specified file. A very important point here – if you pass either cmdlet a non-string object, these cmdlets use each object’s ToString() method to convert the object to a string before outputting it to the file.

See more at How to send output to a file - PowerShell Community (microsoft.com)

...see more

To install PowerShell on Windows, use the following link to get detailed instructions

For Windows 11 you can also use the Microsoft Store.

...see more

After you have created your PowerShell module, you will likely want to install the module on a system, so that you or others may use it. Generally speaking, this consists of copying the module files (ie, the .psm1, or the binary assembly, the module manifest, and any other associated files) onto a directory on that computer.

Installing a PowerShell Module - PowerShell | Microsoft Docs

...see more

Execution Policy is a Windows security measure that determines whether PowerShell scripts can run on a computer. PowerShell scripts cannot run on Windows by default (even for an administrator). The security policy that controls the ability to run PowerShell scripts on Windows is called Execution Policy.

You can check the current Execution Policy value in Windows 10 using the command:

Get-ExecutionPolicy

By default in Windows 10, this parameter is set to Restricted, which prevents any PowerShell scripts from executing.

You can set one of the following values in the PowerShell Execution Policy:

  • Restricted — it is a default value. It blocks the execution of any scripts and allows only to run of interactive commands in the PowerShell console;
  • All Signed — allows execution of PowerShell scripts with a digital signature;
  • Remote Signed — allows running local scripts without a signature. A digital signature is required to run PS1 files downloaded from the Internet or received from a local network;
  • Unrestricted — any PowerShell scripts are allowed. When you run an unsigned script that was downloaded from the Internet, a confirmation prompt will appear;
  • Bypass — in this mode, nothing is blocked, and no warnings or prompts appear.

By default, the LocalMachine = Restricted policy is set at the computer level. To allow PowerShell scripts to run only in the current session, you can run the commands:

Set-ExecutionPolicy RemoteSigned –Scope Process
...see more
> Get-ExecutionPolicy
AllSigned
> Get-ExecutionPolicy -List

        Scope ExecutionPolicy
        ----- ---------------
MachinePolicy       Undefined
   UserPolicy       Undefined
      Process       Undefined
  CurrentUser       Undefined
 LocalMachine       AllSigned
Add to Set
  • .NET
  • .NET 6.0 Migration
  • 5 Best websites to read books online free with no downloads
  • 5 surprising things that men find unattractive
  • 5 Ways To Take Control of Overthinking
  • 6 simple methods for a more productive workday
  • 6 Ways To Stop Stressing About Things You Can't Control
  • Add React to ASP.NET Core
  • Adding reCAPTCHA to a .NET Core Web Site
  • Admin Accounts
  • Adobe Acrobat
  • Afraid of the new job? 7 positive tips against negative feelings
  • Agile
  • AKS and Kubernetes Commands (kubectl)
  • API Lifecycle Management
  • arc42
  • Article Writing Tools
  • Atlassian
  • Azure API Management
  • Azure App Registration
  • Azure Application Gateway
  • Azure Arc
  • Azure Arc Commands
  • Azure Architectures
  • Azure Bastion
  • Azure Bicep
  • Azure CLI Commands
  • Azure Cloud Products
  • Azure Cognitive Services
  • Azure Container Apps
  • Azure Cosmos DB
  • Azure Cosmos DB Commands
  • Azure Costs
  • Azure Daily
  • Azure Daily 2022
  • Azure Daily 2023
  • Azure Data Factory
  • Azure Database for MySQL
  • Azure Databricks
  • Azure Diagram Samples
  • Azure Durable Functions
  • Azure Firewall
  • Azure Functions
  • Azure Kubernetes Service (AKS)
  • Azure Landing Zone
  • Azure Log Analytics
  • Azure Logic Apps
  • Azure Maps
  • Azure Monitor
  • Azure News
  • Azure PowerShell Cmdlets
  • Azure PowerShell Login
  • Azure Private Link
  • Azure Purview
  • Azure Redis Cache
  • Azure Security Groups
  • Azure Sentinel
  • Azure Service Bus
  • Azure Service Bus Questions (FAQ)
  • Azure Services Abstract
  • Azure SQL
  • Azure Tips and Tricks
  • Backlog Items
  • BASH Programming
  • Best LinkedIn Tips (Demo Test)
  • Best Practices for RESTful API
  • Bing Maps
  • Birthday Gift Ideas for Wife
  • Birthday Poems
  • Black Backgrounds and Wallpapers
  • Bootstrap Templates
  • Brave New World
  • Brian Tracy Quotes
  • Build Websites Resources
  • C# Development Issues
  • C# Programming Guide
  • Caching
  • Caching Patterns
  • Camping Trip Checklist
  • Canary Deployment
  • Careers of the Future You Should Know About
  • Cheap Vacation Ideas
  • Cloud Computing
  • Cloud Migration Methods
  • Cloud Native Applications
  • Cloud Service Models
  • Cloudflare
  • Code Snippets
  • Compelling Reasons Why Money Can’t Buy Happiness
  • Conditional Access
  • Configurations for Application Insights
  • Create a Routine
  • Create sitemap.xml in ASP.NET Core
  • Creative Writing: Exercises for creative texts
  • CSS Selectors Cheat Sheet
  • Cultivate a Growth Mindset
  • Cultivate a Growth Mindset by Stealing From Silicon Valley
  • Custom Script Extension for Windows
  • Daily Scrum (Meeting)
  • Dalai Lama Quotes
  • DataGridView
  • Decision Trees
  • Deployments in Azure
  • Dev Box
  • Development Flows
  • Docker
  • Don’t End a Meeting Without Doing These 3 Things
  • Drink More Water: This is How it Works
  • Dropdown Filter
  • Earl Nightingale Quotes
  • Easy Steps Towards Energy Efficiency
  • EF Core
  • Elon Musk
  • Elon Musk Companies
  • Employment
  • English
  • Escape Double Quotes in C#
  • Escaping characters in C#
  • Executing Raw SQL Queries using Entity Framework Core
  • Factors to Consider While Selecting the Best Earthmoving System
  • Feng Shui 101: How to Harmonize Your Home in the New Year
  • Flying Machines
  • Foods against cravings
  • Foods that cool you from the inside
  • Four Misconceptions About Drinking
  • Fox News
  • Free APIs
  • Funny Life Quotes
  • Generate Faces
  • Generate Random Numbers in C#
  • Genius Money Hacks for Massive Savings
  • GitHub
  • GitHub Concepts
  • Green Careers Set to Grow in the Next Decade
  • Habits Of Highly Stressed People and how to avoid them
  • Happy Birthday Wishes & Quotes
  • Helm Overview
  • How to Clean Floors – Tips & Tricks
  • How to invest during the 2021 pandemic
  • How To Make Money From Real Estate
  • How To Stop Drinking Coffee
  • Image for Websites
  • Inspirational Quotes
  • Iqra Technology, IT Services provider Company
  • Jobs Of 2050
  • jQuery
  • jQuery plugins
  • JSON for Linking Data (JSON-LD)
  • Json to C# Converters
  • Karen Lamb Quotes
  • Kubernetes Objects
  • Kubernetes Tools
  • Kusto Query Language
  • Lack of time at work? 5 simple tricks to help you avoid stress
  • Lambda (C#)
  • Last Minute Travel Tips
  • Last-Minute-Reisetipps
  • Latest Robotics
  • Leadership
  • List Of Hobbies And Interests
  • Logitech BRIO Webcam
  • Management
  • Mark Twain Quotes
  • Markdown
  • Meet Sophia
  • Message-Oriented Architecture
  • Microservices
  • Microsoft Authenticator App
  • Microsoft Power Automate
  • Microsoft SQL Server
  • Microsoft Teams
  • Mobile UI Frameworks
  • Motivation
  • Multilingual Applications
  • NBC News
  • NuGet
  • Objectives and Key Results (OKR)
  • Objectives and Key Results (OKR) Samples
  • OKR Software
  • Online JSON Viewer and Parser
  • Outlook Automation
  • PCMag
  • Phases of any relationship
  • Playwright
  • Popular cars per decade
  • Popular Quotes
  • PowerShell
  • PowerShell Array Guide
  • PowerShell Coding Samples
  • PowerToys
  • Prism
  • Pros & Cons Of Alternative Energy
  • Quill Rich Text Editor
  • Quotes
  • RACI Matrix
  • Razor Syntax
  • Reasons why singletasking is better than multitasking
  • Regular Expression (RegEx)
  • Resize Images in C#
  • RESTful APIs
  • Rich Text Editors
  • Rob Siltanen Quotes
  • Robots
  • Run sudo commands
  • Salesforce Offshore Support Services Providers
  • Sample Data
  • Save Money On Food
  • Score with authenticity in the job interview
  • Security
  • Semantic Versioning
  • Serialization using Thread Synchronization
  • Service Worker
  • Snipps
  • Speak and Presentation
  • SQL References
  • SQL Server Full-Text Search
  • Successful
  • Surface Lineup 2021
  • Surface Lineup 2021 Videos
  • SVG Online Editors
  • Team Manifesto
  • Technologies
  • Technology Abbreviations
  • Technology Glossary
  • TechSpot
  • That is why you should drink cucumber water every day
  • The Cache Tag Helper in ASP.NET Core
  • The Verge
  • Theodore Roosevelt Quotes
  • These 7 things make you unattractive
  • Things Successful People Do That Others Don’t
  • Things to Consider for a Great Birthday Party
  • Things to Consider When Designing A Website
  • Thoughts
  • TinyMCE Image Options
  • TinyMCE Toolbar Options
  • Tips for a Joyful Life
  • Tips for fewer emails at work
  • Tips for Making Better Decisions
  • Tips for Managing the Stress of Working at Home
  • Tips for Writing that Great Blog Post
  • Tips On Giving Flowers As Gifts
  • Tips you will listen better
  • Top Fitness Tips
  • Top Healthy Tips
  • Top Money Tips
  • Top Ten Jobs
  • Track Authenticated Users in Application Insights
  • Unicode Characters
  • Visual Studio 2022
  • Vital everyday work: tips for healthy work
  • Walking barefoot strengthens your immune system
  • Walt Disney Quotes
  • Ways for Kids to Make Money
  • Web Design Trends & Ideas
  • Web Icons
  • Web Scraping
  • Webhooks
  • Website Feature Development
  • What are my options for investing money?
  • What happens when you drink water in the morning
  • What Is Stressful About Working at Home
  • What To Eat For Lunch
  • Windows 11 Top Features You Should Know
  • Winston Churchill Quotes
  • XPath
  • You'll burn out your team with these 5 leadership mistakes
  • ZDNet
 
Sets