- Как установить PowerShell в Arch Linux, Manjaro, BlackArch
- PowerShell в Linux
- Установка PowerShell 7 в Arch Linux, Manjaro, BlackArch
- Как запустить PowerShell в Arch Linux, Manjaro, BlackArch
- Примеры использования PowerShell в Linux
- Работа с Powershell Linux
- Что такое PowerShell?
- Установка PowerShell в Linux
- Работа с PowerShell в Linux
- Работа с файлами в PowerShell
- Работа с процессами в PowerShell
- Информация про PowerShell
- Выводы
- Install powershell on Arch Linux
- powershell
- PowerShell for every system!
- Details for powershell
- Enable snaps on Arch Linux and install powershell
- Enable snapd
- Install powershell
- Install PowerShell on Linux
- Alpine
- CentOS
- Debian
- Fedora
- Red Hat Enterprise Linux (RHEL)
- Ubuntu
- Raspberry Pi OS
- Community supported distributions
Как установить PowerShell в Arch Linux, Manjaro, BlackArch
PowerShell в Linux
PowerShell — это кроссплатформенный инструмент/платформа автоматизации и конфигурации. PowerShell имеет большое количество команд, ориентированных на системное администрирование. Но при этом PowerShell это полноценный язык программирования, позволяющий писать функциональные программы (скрипты).
Обратите внимание, что в настоящее время по умолчанию в Windows предустановлен PowerShell 5, а здесь показана установка последней версии PowerShell 7. На Windows также можно установить PowerShell 7.
Из-за различий операционных систем Windows и Linux, не все функции PowerShell работают в Linux.
Установка PowerShell 7 в Arch Linux, Manjaro, BlackArch
Рекомендуется установить утилиту pikaur по статье «Автоматическая установка и обновление пакетов AUR» и затем достаточно выполнить команду:
Если вы не хотите устанавливать pikaur то для установки PowerShell выполните следующую последовательность команд:
Как запустить PowerShell в Arch Linux, Manjaro, BlackArch
Для запуска интерактивной сессии PowerShell выполните команду:
Примеры использования PowerShell в Linux
Чтобы вывести список всех команд PS в вашем компьютере откройте PowerShell (команда pwsh), и введите там:
Есть возможность фильтровать информацию, выводимую командой Get-Command. Допустим вы хотим посмотреть команды PowerShell содержащие слово «Alias», для этого нужно выполнить следующую команду:
Чтобы вывести справку о команде (командлете) используйте следующее:
Например, чтобы вывести справку о командлете Get-Alias:
Чтобы получить самую полную справку о команде Get-Command выполните следующее:
Чтобы вывести содержимое папки (в данном случае корня файловой системы) запустите:
Чтобы вывести список процессов запустите:
Чтобы остановить процесс с ID 10500 используйте команду как показано ниже:
Источник
Работа с Powershell Linux
После того как компания Microsoft заинтересовалась Linux и открыла исходный код нескольких своих проектов, был открыт код командного интерпретатора и оболочки для выполнения системных скриптов Windows — PowerShell. Раньше PowerShell была доступна только для Windows, но теперь ее можно использовать даже в Linux и MacOS.
В этой статье мы рассмотрим что такое PowerShell, чем она может быть нам полезна, а также как выполняется работа с PowerShell Linux.
Что такое PowerShell?
PowerShell — это больше чем командная оболочка, это система автоматизации задач и управления конфигурацией, разработанная в Microsoft. Она состоит из интерпретатора команд (оболочки) и языка сценариев, основанного на платформе NET Framework. PowerShell реализует полный доступ к COM (Component Object Model) и WMI (Windows Management Instrumentation), поэтому позволяет системным администраторам выполнять различные административные действия на локальной или удаленных машинах. Также поддерживаются технологии WS-Management и CIM (Common Information Model), что позволяет управлять сетевыми устройствами.
Для решения каждой возникшей задачи необходимо создавать .NET классы, которые называются cmdlet или по-нашему коммандлеты. Для создания скриптов, так же как и в Linux можно сохранять группы коммандлетов в файл. Затем эти скрипты можно применить в качестве утилит командной строки или дополнительных инструментов.
Установка PowerShell в Linux
В официальных репозиториях оболочки PowerShell, к сожалению, нет, но в Microsoft создали свой PPA репозиторий, который мы можем использовать. Для добавления репозитория в Ubuntu используйте такие команды:
curl https://packages.microsoft.com/keys/microsoft.asc |sudo apt-key add —
$ curl https://packages.microsoft.com/config/ubuntu/16.04/prod.list |sudo tee /etc/apt/sources.list.d/microsoft.list
$ sudo apt-get update
Эти команды рассчитаны на Ubuntu 16.04, для добавления репозитория в Ubuntu 16.10 используйте такие команды:
curl https://packages.microsoft.com/keys/microsoft.asc |sudo apt-key add —
$ curl https://packages.microsoft.com/config/ubuntu/16.10/prod.list |sudo tee /etc/apt/sources.list.d/microsoft.list
$ sudo apt-get update
Затем используйте пакетный менеджер apt для установки powershell и необходимых компонентов:
sudo apt install -y powershell
Для Red Hat, Fedora и CentOS Microsft тоже подготовили отдельный репозиторий. Чтобы его добавить выполните:
sudo curl https://packages.microsoft.com/config/rhel/7/prod.repo> /etc/yum.repos.d/microsoft.repo
Затем используйте yum для установки:
sudo yum install -y powershell
Работа с PowerShell в Linux
После того как установка PowerShell Linux будет завершена, вы можете перейти к работе с этой оболочкой. Дальше мы рассмотрим как начать работать, разберем основные команды для работы с файлами, каталогами и процессами. Также рассмотрим как получить список всех доступных команд и справку по них.
Чтобы запустить сеанс PowerShell выполните такую команду:
Теперь, вы можете узнать версию PowerShell и ее компонентов с помощью такой команды:
Продолжим рассмотрение команд, с команд для получения информации. Следующие две команды позволяют узнать текущую дату и время бесперебойной работы компьютера:
А эта команда позволяет узнать текущую рабочую папку:
Работа с файлами в PowerShell
Чтобы создать новый пустой файл используйте команду:
Затем добавим в этот файл содержимое:
> set-content losst.txt -value «Linux Open Source Software Technologies»
И смотрим новое содержимое файла:
Чтобы удалить файл используйте команду remove-item:
> remove-item losst.txt
> get-content losst.txt
Создайте новый каталог и перейдите в него:
> mkdir losst-files
> cd losst-files
Затем создадим один файл в этой папке и посмотрим ее содержимое:
> new-item losst.txt
> ls
Если вы хотите получить полный список файлов в папке с подробной информацией используйте команду dir:
Работа с процессами в PowerShell
Чтобы посмотреть список запущенных процессов используйте команду get-process:
Также вы можете получить информацию только по определенному процессу или группе, для этого передайте его имя в параметрах команде:
Вот значения основных колонок, которые выводит команда:
- NPM (K) — количество оперативной памяти, которую процесс использует в килобайтах;
- PM(K) — количество выгружаемой оперативной памяти, используемой процессом в килобайтах;
- WS (K) — размер блока с исполняемыми инструкциями процесса в килобайтах;
- CPU(s) — занимаемый процент процессорного времени;
- ID — идентификатор процесса (PID);
- ProcessName — имя процесса.
Как видите, здесь можно увидеть всю основную информацию о процессах. Чтобы остановить процесс используйте команду stop-process, в параметрах ей нужно передать PID:
> get-process ping
> stop-process 29895
Информация про PowerShell
Вы можете узнать всю необходимую информацию про команды PowerShell Linux, чтобы работа с оболочкой была максимально удобной. Для просмотра информации про доступные команды:
Чтобы посмотреть более подробную информацию по нужной команде используйте функцию get-help. Например, узнаем информацию про команду Describe:
Чтобы посмотреть все доступные псевдонимы команд используйте:
И еще одна вещь, которая может вам понадобиться, это история команд. Для ее просмотра наберите:
Выводы
Вот и все. В этой статье мы показали как выполняется работа с PowerShell Linux, а также как установить эту оболочку во всех основных дистрибутивах. PowerShell очень сильно отличается от привычных оболочек Linux, которые имеют лучшие, продуктивные и более интересные команды для выполнения различных задач из командной строки или написания скриптов. Но, возможно, администраторам Windows будет интересно использовать именно эту оболочку.
Источник
Install powershell
on Arch Linux
powershell
- Microsoft PowerShell (microsoft-powershell) Publisher
Verified account
- Development
PowerShell for every system!
PowerShell is an automation and configuration management platform. It consists of a cross-platform (Windows, Linux, and macOS) command-line shell and associated scripting language.
Details for powershell
Enable snaps on Arch Linux and install powershell
Snaps are applications packaged with all their dependencies to run on all popular Linux distributions from a single build. They update automatically and roll back gracefully.
Snaps are discoverable and installable from the Snap Store, an app store with an audience of millions.
Enable snapd
On Arch Linux, snap can be installed from the Arch User Repository (AUR). The manual build process is the Arch-supported install method for AUR packages, and you’ll need the prerequisites installed before you can install any AUR package. You can then install snap with the following:
Once installed, the systemd unit that manages the main snap communication socket needs to be enabled:
To enable classic snap support, enter the following to create a symbolic link between /var/lib/snapd/snap and /snap :
Either log out and back in again, or restart your system, to ensure snap’s paths are updated correctly.
Install powershell
To install powershell, simply use the following command:
Источник
Install PowerShell on Linux
PowerShell can be installed on different Linux distributions. Most Linux platforms and distributions have a major release each year, and provide a package manager that is used to install PowerShell. This article describes what is currently supported and which package manager is used.
The rest of this article is a breakdown of each Linux distribution that PowerShell supports. All PowerShell releases remain supported until either the version of PowerShell reaches end-of-support or the Linux distribution reaches end-of-life.
For the best compatibility, choose a long-term release (LTS) version.
Alpine
The following table lists the supported PowerShell releases and the versions of Alpine they’re supported on. These versions are supported until either the version of PowerShell reaches end-of-support or the version of Alpine reaches end-of-life.
- A вњ… indicates that the version of the OS or PowerShell is still supported
- A вќЊ indicates that the version of the OS or PowerShell isn’t supported
- A рџџЎ indicates the version of PowerShell is no longer supported on that version of the OS
- When both the version of the OS and the version of PowerShell have вњ…, that combination is supported
Alpine | 7.0 (LTS) | 7.1 (current) | 7.2 (LTS-preview) |
---|---|---|---|
вњ… 3.12 | вњ… | вњ… | вќЊ |
вњ… 3.11 | вњ… | вњ… | вќЊ |
вќЊ 3.10 | рџџЎ | рџџЎ | вќЊ |
вќЊ 3.9 | рџџЎ | рџџЎ | вќЊ |
PowerShell has not been tested on Alpine versions 3.13 and 3.14.
CIM, PowerShell Remoting, and DSC are not supported on Alpine.
PowerShell is supported on Alpine for the following processor architectures.
Alpine | 7.0 (LTS) | 7.1 (current) | 7.2 (LTS-preview) |
---|---|---|---|
All supported versions | x64 | x64 | x64 |
PowerShell has not been tested on Alpine using Arm processors.
CentOS
CentOS 7 uses Yum as a package manager and CentOS 8 uses DNF.
The following table is a list of currently supported PowerShell releases and the versions of CentOS they are supported on. These versions remain supported until either the version of PowerShell reaches end-of-support or the version of CentOS reaches end-of-support.
- A вњ… indicates that the version of the OS or PowerShell is still supported
- A вќЊ indicates that the version of the OS or PowerShell isn’t supported
- A рџџЎ indicates the version of PowerShell is no longer supported on that version of the OS
- When both the version of the OS and the version of PowerShell have вњ…, that combination is supported
CentOS | 7.0 (LTS) | 7.1 (current) | 7.2 (LTS-preview) |
---|---|---|---|
вњ… 8 | вњ… | вњ… | вњ… |
вњ… 7 | вњ… | вњ… | вњ… |
Microsoft does not officially support PowerShell on the CentOS Stream releases. For more information, see Comparing CentOS Linux and CentOS Stream. CentOS Stream is community supported. For more information, see Community supported distributions.
PowerShell is supported on CentOS for the following processor architectures.
CentOS | 7.0 (LTS) | 7.1 (current) | 7.2 (LTS-preview) |
---|---|---|---|
All supported versions | x64 | x64 | x64 |
Debian
Debian uses APT (Advanced Package Tool) as a package manager.
The following table is a list of currently supported PowerShell releases and the versions of Debian they’re supported on. These versions remain supported until either the version of PowerShell reaches end-of-support or the version of Debian reaches end-of-life.
- A вњ… indicates that the version of the OS or PowerShell is still supported
- A вќЊ indicates that the version of the OS or PowerShell isn’t supported
- A рџџЎ indicates the version of PowerShell is no longer supported on that version of the OS
- When both the version of the OS and the version of PowerShell have вњ…, that combination is supported
Debian | 7.0 (LTS) | 7.1 (current) | 7.2 (LTS-preview) |
---|---|---|---|
вњ… 10 | вњ… | вњ… | вњ… |
вњ… 9 | вњ… | вњ… | вќЊ |
вќЊ 8 | рџџЎ | вќЊ | вќЊ |
PowerShell is supported on Debian for the following processor architectures.
Debian | 7.0 (LTS) | 7.1 (current) | 7.2 (LTS-preview) |
---|---|---|---|
Version 9+ | x64, Arm32, Arm64 | x64, Arm32, Arm64 | x64, Arm32, Arm64 |
Fedora
Fedora uses DNF as its package manager.
The following table lists the supported PowerShell releases and the versions of Fedora they’re supported on. These versions are supported until either the version of PowerShell reaches end-of-support or the version of Fedora reaches end-of-life.
- A вњ… indicates that the version of the OS or PowerShell is still supported
- A вќЊ indicates that the version of the OS or PowerShell isn’t supported
- A рџџЎ indicates the version of PowerShell is no longer supported on that version of the OS
- When both the version of the OS and the version of PowerShell have вњ…, that combination is supported
Fedora | 7.0 (LTS) | 7.1 (current) | 7.2 (LTS-preview) |
---|---|---|---|
вњ… 32 | рџџЎ | рџџЎ | вќЊ |
вќЊ 31 | рџџЎ | рџџЎ | вќЊ |
вќЊ 30 | рџџЎ | рџџЎ | вќЊ |
PowerShell has not been tested on Fedora versions 33 and 34.
PowerShell is supported on Fedora for the following processor architectures.
Fedora | 7.0 (LTS) | 7.1 (current) | 7.2 (LTS-preview) |
---|---|---|---|
All supported versions | x64 | x64 | x64 |
Red Hat Enterprise Linux (RHEL)
RHEL 7 uses yum and RHEL 8 uses the dnf package manager.
The following table is a list of currently supported versions of PowerShell and the versions of RHEL they are supported on. These versions remain supported until either the version of PowerShell reaches end-of-support or the version of RHEL reaches end-of-support.
- A вњ… indicates that the version of the OS or PowerShell is still supported
- A вќЊ indicates that the version of the OS or PowerShell isn’t supported
- A рџџЎ indicates the version of PowerShell is no longer supported on that version of the OS
- When both the version of the OS and the version of PowerShell have вњ…, that combination is supported
RHEL | 7.0 (LTS) | 7.1 (current) | 7.2 (LTS-preview) |
---|---|---|---|
вњ… 8 | вњ… | вњ… | вњ… |
вњ… 7 | вњ… | вњ… | вњ… |
PowerShell is supported on RHEL for the following processor architectures.
RHEL | 7.0 (LTS) | 7.1 (current) | 7.2 (LTS-preview) |
---|---|---|---|
All supported versions | x64 | x64 | x64, Arm64 |
Ubuntu
Ubuntu uses APT (Advanced Package Tool) as a package manager.
The following table is a list of currently supported PowerShell releases and the versions of Ubuntu they are supported on. These versions remain supported until either the version of PowerShell reaches end-of-support or the version of Ubuntu reaches end-of-support.
- A вњ… indicates that the version of the OS or PowerShell is still supported
- A вќЊ indicates that the version of the OS or PowerShell isn’t supported
- A рџџЎ indicates the version of PowerShell is no longer supported on that version of the OS
- When both the version of the OS and the version of PowerShell have вњ…, that combination is supported
Ubuntu | 7.0 (LTS) | 7.1 (current) | 7.2 (LTS-preview) |
---|---|---|---|
вњ… 20.04 (LTS) | вњ… | вњ… | вњ… |
вњ… 18.04 (LTS) | вњ… | вњ… | вњ… |
вќЊ 16.04 (LTS) | рџџЎ | рџџЎ | вќЊ |
Only the LTS releases of Ubuntu are officially supported. Microsoft does not support interim releases or their equivalent. Interim releases are community supported. For more information, see Community supported distributions.
PowerShell is supported on Ubuntu for the following processor architectures.
Ubuntu | 7.0 (LTS) | 7.1 (current) | 7.2 (LTS-preview) |
---|---|---|---|
All supported versions | x64, Arm32, Arm64 | x64, Arm32, Arm64 | x64, Arm32, Arm64 |
Raspberry Pi OS
Raspberry Pi OS (formerly Raspbian) is a free operating system based on Debian.
.NET is not supported on ARMv6 architecture devices, including Raspberry Pi Zero and Raspberry Pi devices prior to Raspberry Pi 2.
Community supported distributions
There are many distributions of Linux that are not officially supported by Microsoft. In some cases, PowerShell may be supported by the community for these releases. For more information, see Community support for PowerShell on Linux.
Источник