PowerShell, Scripting
comments 4

Enable-AutoAdminLogon: PowerShell to enable auto admin logon on local and remote systems

I have been working on quite a few utility scripts for my test bed automation. This is just one of those scripts. I, generally, use OS unattend XML to enable auto admin logon. But, when that is not done, there are situations when I have to enable this for a set of servers for doing application deployment that requires multiple reboots. So, the following function lets me enable auto-admin logon on a set of servers.

This script requires remote registry service be enabled on the remote systems. If not, you receive an error. Also, the DefaultDomainName & DefaultUserName are not mandatory parameters. These are, by default, taken from the environment variables. AutoLogonCount can be used to disable auto admin logon after a specified auto logons. Again, this parameter is not mandatory.

Here is the script:

I am also performing a few checks to make sure the architecture of PowerShell host you use is a valid one for the architecture of remote system. For example, if the remote system is x64 and you use a x86 PowerShell host to run this script, you will end up adding the registry values to SysWow64 node in the registry on the remote machine. This is of no use. So, this script will throw an error in that case.

This is how you use it:

Enable-AutoAdminLogon

Enable-AutoAdminLogon without DefaultUserName & DefaultDomainName

In the above example, I was using the script to add auto admin logon settings on multiple servers and notice that I’d not provided DefaultDomainName and DefaultUserName properties. These were picked up from the current environment.

And, you can specify DefaultDomainName & DefaultUserName, if you like to:

Enable-AutoAdminLogon

Enable-AutoAdminLogon with DefaultUserName and DefaultDomainName

This is it. The script assumes that the logged on user has permissions to access remote registry & WMI name spaces. This is in my TODO.

Filed under: PowerShell, Scripting

by

Ravikanth is a principal engineer and the lead architect for Microsoft and VMware virtualized and hybrid cloud solutions within the Infrastructure Solutions Group at Dell EMC. He is a multi-year recipient of Microsoft Most Valuable Professional (MVP) award in Windows PowerShell (CDM) and Microsoft Azure. Ravikanth is the author of Windows PowerShell Desired State Configuration Revealed (Apress) and leads Bangalore PowerShell and Bangalore IT Pro user groups. He can be seen speaking regularly at local user group events and conferences in India and abroad.