zoukankan      html  css  js  c++  java
  • Powershell-远程操作

    1. 查看WinRM是否开启

     Get-Service WinRM

    2. Enable-PSRemoting –Force

    3. 进行信任设置:

    Set-Item wsman:localhostclient rustedhosts *

    Restart-Service WinRM

    4. 测试远程连接

    Test-WsMan xxx.xxx.xxx.xxx

    5. 建立连接

    Enter-PSSession -ComputerName my-svr -Credential nickli

    创建凭证

    $Username = 'zhnaghao'

    $Password = 'mima'

    $pass = ConvertTo-SecureString -AsPlainText $Password -Force

    $Cred = New-Object System.Management.Automation.PSCredential -ArgumentList $Username,$pass

    进入会话

    $Username = 'zhnaghao'

    $Password = 'mima'

    $pass = ConvertTo-SecureString -AsPlainText $Password -Force

    $Cred = New-Object System.Management.Automation.PSCredential -ArgumentList $Username,$pass

    Enter-PSSession -ComputerName SDSVD13 -Credential $Cred

    退出会话

    Exit-PSSession

    执行单条命令:

    $Username = 'zhnaghao'

    $Password = 'mima'

    $pass = ConvertTo-SecureString -AsPlainText $Password -Force

    $Cred = New-Object System.Management.Automation.PSCredential -ArgumentList $Username,$pass

    Invoke-Command -ComputerName SDSVD13 -ScriptBlock {  [System.Net.DNS]::GetHostByName('').HostName

     } -credential $Cred 

    远程执行脚本

    $Username = 'zhnaghao'

    $Password = 'mima'

    $pass = ConvertTo-SecureString -AsPlainText $Password -Force

    $Cred = New-Object System.Management.Automation.PSCredential -ArgumentList $Username,$pass

    Invoke-Command -computername sdsvd13 -FilePath C:UsersSDSADMINDesktopPowershellNEWhostname.ps1  -credential $Cred 

    远程返回结果复制给变量

    $Username = 'zhnaghao'

    $Password = 'mima'

    $pass = ConvertTo-SecureString -AsPlainText $Password -Force

    $Cred = New-Object System.Management.Automation.PSCredential -ArgumentList $Username,$pass

    $mySession = new-PSSession -ComputerName SDSVD13 -Credential $Cred

    $sub = Invoke-Command -Session $mySession -ScriptBlock {[System.Net.DNS]::GetHostByName('').HostName}

    $sub

  • 相关阅读:
    Java字符串操作
    easyui Combotree根据用户输入显示对应的tree值
    maven
    引用 js表单验证大全 以后方便查看用
    对象内存模型
    高级性能服务器编程模型【IOCP完成端口】开发实现【一】
    高级性能服务器编程模型【IOCP完成端口】开发实现【二】
    高级性能服务器编程模型【IOCP完成端口】开发实现【三】
    探讨【IGE】的源代码【六】,承接【五】,内存池管理。
    hive beeline详解
  • 原文地址:https://www.cnblogs.com/JinweiChang/p/10748244.html
Copyright © 2011-2022 走看看