Multiple PowerShell commands at the same command line

Multiple PowerShell commands at the same command line

In some situations I want to be able to run 2 or more PowerShell statements on the same line, without using a script (PS1 file).

Semicolon can be used to chain Commands in PowerShell.

powershell -command get-date;get-host

image

This could for example come in handy in a Task Sequence as shown her:

PowerShell -command “&{Import-Module ServerManager;Add-WindowsFeature -Name AS-Ent-Services,AS-Tcp-Port-Sharing,AS-NET-Framework}”

image

+ posts

Table of Contents

Share this post
Search blog posts
Search
Authors
Modern Workplace consultant and a Microsoft MVP in Enterprise Mobility.

Modern Workplace consultant and a Microsoft MVP in Windows and Devices.

Infrastructure architect with focus on Modern Workplace and Microsoft 365 security.

Cloud & security specialist with focus on Microsoft backend products and cloud technologies.

Cloud & security specialist with focus on Microsoft 365.

Cloud & Security Specialist, with a passion for all things Cybersecurity

Cloud and infrastructure security specialist with background in networking.

Infrastructure architect with focus on design, implementation, migration and consolidation.

Infrastructure consultant with focus on cloud solutions in Office365 and Azure.

Modern workplace and infrastructure architect with a focus on Microsoft 365 and security.

follow us in feedly
Categories

Follow on SoMe