none
VBScript 2 PowerShell script RRS feed

  • Вопрос

  • Помогите перекодировать скрипт с VBS в PowerShell

    Code Snippet

    sOld=wscript.arguments.named("old")
    sNew=wscript.arguments.named("new")
    if sOld="" or sNew="" then
      wscript.echo "Run this as renamecomp.vbs /old:oldname /new:newname"
    end if
    sDomainUser = "administrator@group"
    sDomainPasswd ="mdfg@CVB5!"
    sAdminUser=sOld & "\Administrator"
    sAdminPassword= "asdfgh1!"

    set oWMILocator = CreateObject("WbemScripting.SWbemLocator")
    oWMILocator.Security_.AuthenticationLevel = 6
    set oWMIComputer = oWMILocator.ConnectServer(sOld, "root\cimv2",sOld & sAdminUser,sAdminPassword)
    set oWMIComputerSystem = oWMIComputer.Get("Win32_ComputerSystem.Name='" & sOld & "'")

    rc = oWMIComputerSystem.Rename(sNew,sDomainPasswd,sDomainUser)
    if rc <> 0 then
     WScript.Echo "Rename failed with error: " & rc
    else
     WScript.Echo "Successfully renamed " & sOld & " to " & sNew
     wscript.echo "Now rebooting"
     rebootMachine sOld
    end if

    Sub RebootMachine(scompName)
        Set oWMI = GetObject("winmgmts:{impersonationLevel=impersonate,(Security,Shutdown)}!\\" & scompName & "\root\cimv2")
        Set OS_Set = oWMI.Get("Win32_OperatingSystem")
        For Each os in OS_Set.Instances_()
          '*** Force Reboot ***
          ret = os.Win32Shutdown(6)
        Next
    End Sub


    Зарание благодарю.
    30 апреля 2008 г. 14:07

Ответы