2014年6月9日 星期一

Ceate auto logon by using Power Shell script

Here we teach you how to use the Power Shell to Ceate auto logon

 param (
  [Parameter(Mandatory=$false)][String[]]$computer = ".",
  [Parameter(Mandatory=$false)][String[]]$computerName = $env:computername,
  [Parameter(Mandatory=$false)][String]$DefaultDomainName = $env:USERDOMAIN,
  [Parameter(Mandatory=$false)][String]$DefaultUserName = "test",
  [Parameter(Mandatory=$false)][String]$DefaultPassword  = "pwd",
  [Parameter(Mandatory=$false)][String]$Group  = "administrators",
  [Parameter(Mandatory=$false)][Int]$AutoLogonCount
 )




function add_autologon(){

foreach($computer in $computerName){ 
      #do local modifications here
      Write-Verbose "Adding required registry values on $($computer)"
      Write-Verbose "Saving curent location"
      Push-Location
      Set-Location "HKLM:\Software\Microsoft\Windows NT\Currentversion\WinLogon"
      New-ItemProperty -Path $pwd.Path -Name "AutoAdminLogon" -Value 1 -PropertyType "String" -Force | Out-Null
      New-ItemProperty -Path $pwd.Path -Name "DefaultUserName" -Value $DefaultUserName -PropertyType "String" -Force | Out-Null
      New-ItemProperty -Path $pwd.Path -Name "DefaultPassword" -Value $DefaultPassword -PropertyType "String" -Force | Out-Null
      New-ItemProperty -Path $pwd.Path -Name "DefaultDomainName" -Value $DefaultDomainName -PropertyType "String" -Force | Out-Null
      if ($AutoLogonCount) {
        New-ItemProperty -Path $pwd.Path -Name "AutoLogonCount" -Value $AutoLogonCount -PropertyType "Dword" -Force | Out-Null
      }

      Write-Verbose "restoring earlier location"
      Pop-Location
}
}

沒有留言:

張貼留言