[PS] Enabling and disabling a single user account in Windows 7

I wrote a Test.ps1 script that is started during startup of Windows 7. To do this, I created a scheduled task in this way:

schtasks /create /sc onstart /ru System /v1 /z /tn "Test" /tr "C:\WINDOWS\system32\windowspowershell\v1.0\powershell.exe -ExecutionPolicy Unrestricted -file \"D:\Users\xxx\Documents\Test.ps1\" \"Administrator test\""

Since this script is 45 minutes and, in that time, the "Administrator test" administrator not must log on, I wrote at the beginning and end of this script, follow these instructions:


Get-WmiObject Win32_UserAccount -filter "LocalAccount=True AND Name=$AdministratorAccount" | % {$_.disable = $true;$_.put()}


Get-WmiObject Win32_UserAccount -filter "LocalAccount=True AND Name=$AdministratorAccount" | % {$_.enable = $true;$_.put()}

I noticed, however, that during the execution of that script, the "Administrator test" administrator can still access the system with the "Administrator test" account.

Where I wrong?



0 Comments   [ + ] Show comments

Answers (0)

Be the first to answer this question

Rating comments in this legacy AppDeploy message board thread won't reorder them,
so that the conversation will remain readable.
This website uses cookies. By continuing to use this site and/or clicking the "Accept" button you are providing consent Quest Software and its affiliates do NOT sell the Personal Data you provide to us either when you register on our websites or when you do business with us. For more information about our Privacy Policy and our data protection efforts, please visit GDPR-HQ