POWERSHELL SUR LINUX
INSTALLATION
apt upgrade && apt full-upgrade && apt install curl apt-transport-https gnupg2 -y
curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add -
sh -c 'echo "deb [arch=amd64] https://packages.microsoft.com/repos/microsoft-debian-bullseye-prod bullseye main" > /etc/apt/sources.list.d/microsoft.list'
apt update && apt install -y powershell gss-ntlmssp
SE CONNECTER À DISTANCE EN POWERSHELL
- Installation des modules nécessaires en BASH
pwsh -Command 'Install-Module -Name PSWSMan' --> Redémarrer une session - Installation des module nécessaire en POWERSHELL
Install-Module -Name PowerShellGet Install-Module -Name PSWSMan -force Install-WSMan - Connexion sur un WINDOWS SERVER
PS /root> Enter-PSSession -ComputerName 172.16.0.3 -Authentication Negotiate -Credential megaproduction\administrator PowerShell credential request Enter your credentials. Password for user megaproduction\administrator: ******** [172.16.0.3]: PS C:\Users\Administrator\Documents> hostname ads-front-01
Il faudra au préalable avoir lancé ces commande sur le serveur distant:
Enable-PSRemoting -Force
DÉBUT D'AUTOMATISATION
- Création de la commande à lancer
$creds = Get-Credential -UserName megaproduction\administrator $block = {Get-WindowsFeature | Where { $_.Installed } | Select Name,DisplayName,Description | select -First 4} Invoke-Command -ComputerName 172.16.0.3 -Authentication Negotiate -Credential $creds ` -ScriptBlock $block - Résultat attendus
PS /root> Invoke-Command -ComputerName 172.16.0.3 -Authentication Negotiate -Credential $creds ` >> -ScriptBlock $block -verbose Name : AD-Domain-Services DisplayName : Active Directory Domain Services Description : Active Directory Domain Services (AD DS) stores information about objects on the network and makes this information available to users and network administrators. AD DS uses domain controllers to give network users access to permitted resources anywhere on the network through a single logon process. PSComputerName : 172.16.0.3 RunspaceId : 553f7cb6-c422-4fa2-a93e-62525616f57a Name : DNS DisplayName : DNS Server Description : Domain Name System (DNS) Server provides name resolution for TCP/IP networks. DNS Server is easier to manage when it is installed on the same server as Active Directory Domain Services. If you select the Active Directory Domain Services role, you can install and configure DNS Server and Active Directory Domain Services to work together. PSComputerName : 172.16.0.3 RunspaceId : 553f7cb6-c422-4fa2-a93e-62525616f57a Name : FileAndStorage-Services DisplayName : File and Storage Services Description : File and Storage Services includes services that are always installed, as well as functionality that you can install to help manage file servers and storage. PSComputerName : 172.16.0.3 RunspaceId : 553f7cb6-c422-4fa2-a93e-62525616f57a Name : File-Services DisplayName : File and iSCSI Services Description : File and iSCSI Services provides technologies that help you manage file servers and storage, reduce disk space utilization, replicate and cache files to branch offices, move or fail over a fil e share to another cluster node, and share files by using the NFS protocol. PSComputerName : 172.16.0.3 RunspaceId : 553f7cb6-c422-4fa2-a93e-62525616f57a