zoukankan      html  css  js  c++  java
  • Powershell实例小结(服务管理)

    有关服务管理的具体实例脚本如下:

    #$lists="1.1.1.1","2.2.2.2"  #远程ip列表
    foreach ($list in $lists){
        $uname='abc'
        $PWD=Convertto-securestring "defgh" -AsPlainText -Force
        $cred = New-Object system.Management.Automation.PSCredential($uname,$PWD)
        write-output "***************************************"
        write-output "*************"$list"*************"
        write-output "***************************************"
        Invoke-Command -ComputerName $list -command {
            #get-service |where {$_.Name -contains 'msiserver'}|Stop-Service -PassThru|Set-Service -StartupType Disabled
        #get-wmiobject win32_service | where {$_.Name -contains 'msiserver'}
        #get-service |where {$_.Name -contains 'msiserver'}|Set-Service -StartupType Disabled
        #get-service |where {$_.Name -contains 'msiserver'}|Start-Service -PassThru
        get-wmiobject win32_service | where {$_.Name -contains 'msiserver'}
        #Get-Service |where {$_.Name -contains 'ClusSvc'}
            #Get-Service |where {$_.Name -contains 'ClusSvc'}|set-service -StartupType Automatic |start-service
            #Get-Service |where {$_.Name -contains 'MSSQLSERVER' }
            } -credential $cred
    }

    上述脚本的相关注释如下:

    #查看具体服务的运行状态以及属性
    get-wmiobject win32_service | where {$_.Name -contains 'msiserver'}        #属性以及运行状态
    get-service |where {$_.Name -contains 'msiserver'}     #运行状态以及描述名
    #开启服务
    get-service |where {$_.Name -contains 'msiserver'}|Start-Service -PassThru
    #关闭服务  # 重启 restart
    get-service |where {$_.Name -contains 'msiserver'}|Stop-Service -PassThru
    
    #更改服务属性
    get-service |where {$_.Name -contains 'msiserver'}|Set-Service -StartupType Disabled        #其中启动类型有 Automatic  Disabled   Manual

    在使用powershell远程管理服务器的时候可能遇到的疑难问题:

    直接运行powershell时提示“无法加载文件ps1,因为在此系统中禁止执行脚本。有关详细信息,请参阅 "get-help about_signing"。

    主要是由于没有权限执行脚本,修改其策略可以解决:

    set-executionpolicy remotesigned

    网络无法连接出现红叉,仍可以上网,这种小概率事件是由于windows在运行中出错会使得系统服务变得不稳定而出现错误无法自我重启修复导致的,一般需要cmd中(即dos模式下)指令重启该项目服务组就好,必须使用管理员权限,建议关闭所有防护软件

    net localgroup administrators localservice /add
    net localgroup administrators networkservice /add

    #网络连接模式 不能是公共网络
    #开启powershell远程管理

    Enable-PSRemoting -force

    # 添加信任ip列表

    Set-Item WSMan:localhostclient	rustedhosts * -Force

    在添加信任ip列表的时候出错,可以参考的链接 http://www.cnblogs.com/dreamer-fish/archive/2013/03/15/2961497.html

     #使sqlserver开启对xp_cmdshell 的支持:

    sp_configure 'show advanced options',1
    reconfigure
    go
    sp_configure 'xp_cmdshell',1
    reconfigure
    go
    如果你是蜗牛,那你就不必害怕自己前进的缓慢,相信你自己,因为你的脚步永远不会落空,只要你一步步的向上爬,金字塔也必定被你踩在脚下。
  • 相关阅读:
    背水一战 Windows 10 (61)
    背水一战 Windows 10 (60)
    背水一战 Windows 10 (59)
    背水一战 Windows 10 (58)
    背水一战 Windows 10 (57)
    背水一战 Windows 10 (56)
    背水一战 Windows 10 (55)
    背水一战 Windows 10 (54)
    背水一战 Windows 10 (53)
    背水一战 Windows 10 (52)
  • 原文地址:https://www.cnblogs.com/lx823706/p/5386566.html
Copyright © 2011-2022 走看看