Await custom scheduled tasks
This commit is contained in:
parent
ba058911e9
commit
5f02a650ad
3 changed files with 19 additions and 4 deletions
|
@ -57,7 +57,7 @@ function New-PersonalUser([Context] $context)
|
||||||
Enable-PersonalUserAutologon $context;
|
Enable-PersonalUserAutologon $context;
|
||||||
$context.RegisterReboot();
|
$context.RegisterReboot();
|
||||||
$context.SetStage("RemoveAdmin");
|
$context.SetStage("RemoveAdmin");
|
||||||
Write-EventLog -LogName Application -Source "Application" -EventId $context.Get($uacDisablerTriggerProperty) -Message "This event was created by $env:Username";
|
Start-EventDrivenTask $context.Get($uacDisablerTriggerProperty);
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
elseif ($context.GetStage() -eq "RemoveAdmin")
|
elseif ($context.GetStage() -eq "RemoveAdmin")
|
||||||
|
@ -83,11 +83,11 @@ function Enable-UACNextLogin([Context] $context) {
|
||||||
[System.Tuple]::Create(
|
[System.Tuple]::Create(
|
||||||
$autoLoginTrigger,
|
$autoLoginTrigger,
|
||||||
$autoLoginName,
|
$autoLoginName,
|
||||||
"{ $((Get-AutoLoginScript)) }.Invoke('$contextScript', '$preparedUsernameProperty', '$preparedPasswordProperty')")
|
"{ $((Get-AutoLoginScript)) }.Invoke($autoLoginTrigger, '$contextScript', '$preparedUsernameProperty', '$preparedPasswordProperty')")
|
||||||
[System.Tuple]::Create(
|
[System.Tuple]::Create(
|
||||||
$uacDisablerTrigger,
|
$uacDisablerTrigger,
|
||||||
$uacDisablerName,
|
$uacDisablerName,
|
||||||
"{ $((Get-UACDisablerScript)) }.Invoke('$contextScript', '$autoLoginName', '$uacDisablerName', '$autoLoginTriggerProperty', '$uacDisablerTriggerProperty')"));
|
"{ $((Get-UACDisablerScript)) }.Invoke($uacDisablerTrigger, '$contextScript', '$autoLoginName', '$uacDisablerName', '$autoLoginTriggerProperty', '$uacDisablerTriggerProperty')"));
|
||||||
|
|
||||||
foreach ($options in $optionCollection) {
|
foreach ($options in $optionCollection) {
|
||||||
$action = New-ScheduledTaskAction -Execute "pwsh.exe" -Argument (
|
$action = New-ScheduledTaskAction -Execute "pwsh.exe" -Argument (
|
||||||
|
@ -127,5 +127,16 @@ function Enable-PersonalUserAutologon([Context] $context)
|
||||||
|
|
||||||
$context.Set($preparedUsernameProperty, $context.UserName, "ExpandString");
|
$context.Set($preparedUsernameProperty, $context.UserName, "ExpandString");
|
||||||
$context.Set($preparedPasswordProperty, $password, "ExpandString");
|
$context.Set($preparedPasswordProperty, $password, "ExpandString");
|
||||||
Write-EventLog -LogName Application -Source "Application" -EventId $context.Get($autoLoginTriggerProperty) -Message "This event was created by $env:Username";
|
Start-EventDrivenTask $context.Get($autoLoginTriggerProperty);
|
||||||
|
}
|
||||||
|
|
||||||
|
function Start-EventDrivenTask() {
|
||||||
|
param(
|
||||||
|
[int]$EventID
|
||||||
|
);
|
||||||
|
|
||||||
|
$identifier = "EventLog$_";
|
||||||
|
Write-EventLog -LogName Application -Source "Application" -EventId $EventID -Message "This event was created by $env:Username";
|
||||||
|
Register-WmiEvent -Query "SELECT * FROM __InstanceCreationEvent WHERE TargetInstance ISA 'Win32_NTLogEvent' AND EventIdentifier=$EventID" -SourceIdentifier "$identifier";
|
||||||
|
Wait-Event -SourceIdentifier $identifier;
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
function Get-AutoLoginScript() {
|
function Get-AutoLoginScript() {
|
||||||
return {
|
return {
|
||||||
param(
|
param(
|
||||||
|
[int]$EventID,
|
||||||
[string]$ContextScriptPath,
|
[string]$ContextScriptPath,
|
||||||
[string]$PreparedUsernameProperty,
|
[string]$PreparedUsernameProperty,
|
||||||
[string]$PreparedSecretProperty
|
[string]$PreparedSecretProperty
|
||||||
|
@ -14,5 +15,6 @@ function Get-AutoLoginScript() {
|
||||||
$userName = $context.Get($PreparedUsernameProperty);
|
$userName = $context.Get($PreparedUsernameProperty);
|
||||||
$password = $context.Get($PreparedSecretProperty);
|
$password = $context.Get($PreparedSecretProperty);
|
||||||
$context.SetAutologin($userName, $password);
|
$context.SetAutologin($userName, $password);
|
||||||
|
Write-EventLog -LogName Application -Source "Application" -EventId $EventID -Message "This event was created by $env:Username";
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
function Get-UACDisablerScript() {
|
function Get-UACDisablerScript() {
|
||||||
return {
|
return {
|
||||||
param (
|
param (
|
||||||
|
[int]$EventID,
|
||||||
[string]$ContextScriptPath,
|
[string]$ContextScriptPath,
|
||||||
[string]$AutoLoginTaskName,
|
[string]$AutoLoginTaskName,
|
||||||
[string]$UACDisablerTaskName,
|
[string]$UACDisablerTaskName,
|
||||||
|
@ -19,6 +20,7 @@ function Get-UACDisablerScript() {
|
||||||
$context.Remove($AutoLoginTriggerProperty);
|
$context.Remove($AutoLoginTriggerProperty);
|
||||||
$context.Remove($UACDisablerTriggerProperty);
|
$context.Remove($UACDisablerTriggerProperty);
|
||||||
$context.DeregisterNewUserReboot();
|
$context.DeregisterNewUserReboot();
|
||||||
|
Write-EventLog -LogName Application -Source "Application" -EventId $EventID -Message "This event was created by $env:Username";
|
||||||
Restart-Computer -Force;
|
Restart-Computer -Force;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue