Ответы пользователя по тегу PowerShell
  • Есть возможности выполнения команд powershell на удаленной винде из локального linux (bash)?

    @kavabangaungava
    Всякое бывало.
    Можно через ssh

    #!/bin/bash
    
    rem_host="10.10.8.5"
    rem_user="Username"
    remote_password="pass"
    
    ps_script="/path/to/my_script.ps1"
    
    sshpass -p "$remote_password" ssh "$remote_user"@"$remote_host" -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null << EOF
    
    plink -ssh -t -pw $remote_password $remote_user@$remote_host "powershell.exe -ExecutionPolicy Bypass -File $ps_script"
    
    EOF


    а можно через winrm

    #!/bin/bash
    
    rem_host="10.10.8.5"
    rem_user="Username"
    remote_password="pass"
    
    ps_script="/path/to/my_script.ps1"
    
    powershell -NoLogo -NonInteractive -NoProfile -Command "$secure_password = ConvertTo-SecureString '$remote_password' -AsPlainText -Force; $credential = New-Object System.Management.Automation.PSCredential('$remote_user', $secure_password); $session = New-PSSession -ComputerName $remote_host -Credential $credential -UseSSL; Invoke-Command -Session $session -FilePath $ps_script"
    Ответ написан
    2 комментария