User Profile
RedModSK
Copper Contributor
Joined Jan 01, 2022
User Widgets
Recent Discussions
Re: PromptForChoice menu not working in vertical mode.
Hello Lain, thank you for the explanation and the links. It is more clear to me now. It explains also the behavior for the default choice and the "?" choice as they are already predefined singe values. I will probably use some visual workaround. I can use a the title or question section to display the vertical menu as a simple text. Or i can spend more time and give the script a GUI with WinForms.2.6KViews1like0CommentsRe: PromptForChoice menu not working in vertical mode.
NikolinoDE Hello, NikolinoDE Unfortunately it did not help. $decision = $Host.UI.PromptForChoice($title, $question, $options, [int[]]@()) [S] Status [D] Disable [T] Start [E] Enable [C] Clean [X] Exit [?] Help Choice[0]: D Choice[1]: since "@" is used as array operator - how would it influence the action?2.8KViews0likes3CommentsPromptForChoice menu not working in vertical mode.
Hello, i seek the wisdom of the community again. I have a script with few options in a menu and it works fine this way: $option1 = New-Object System.Management.Automation.Host.ChoiceDescription "&Status", "Show the current Status" $option2 = New-Object System.Management.Automation.Host.ChoiceDescription "&Disable", "Disabled actions." $option3 = New-Object System.Management.Automation.Host.ChoiceDescription "S&tart", "Start actios." $option4 = New-Object System.Management.Automation.Host.ChoiceDescription "&Enable", "Enable actions." $option5 = New-Object System.Management.Automation.Host.ChoiceDescription "&Clean", "Cleanup actions ." $option6 = New-Object System.Management.Automation.Host.ChoiceDescription "E&xit","Exit the script." $options = [System.Management.Automation.Host.ChoiceDescription[]]($option1, $option2, $option3, $option4, $option5, $option6) $decision = $Host.UI.PromptForChoice($title, $question, $options, 0) I have now more options with longer choice names and it is becoming unclear, as it is stretching the choices on two (or more) lines. So, after some searching, i have found a solution to display the choices menu vertically: $decision = $Host.UI.PromptForChoice($title, $question, $options, [int[]](0)) However, i have a strange issue with it. Using Enter for default choice and typing "?" with Enter is executing correctly. Other options are not executing after typing the letter + Enter, but waiting for another choice input, until Enter is pressed without a letter. $decision = $Host.UI.PromptForChoice($title, $question, $options, [int[]](0)) [S] Status [D] Disable [T] Start [E] Enable [C] Clean [X] Exit [?] Help (default is "S") Choice[0]: ? S - Show the current Status D - Disabled actions. T - Start actios. E - Enable actions. C - Cleanup actions . X - Exit the script. Choice[0]: D Choice[1]: PS C:\temp> $decision 1 Can someone please tell me why does it behave like that? Thanks in advance.Solved3.1KViews0likes5CommentsRe: Check Disabled state after Disable-ScheduledTask status on Running Task
i was poking around the system where could i see some additional info and i found this, when running schtasks /query: PS C:\Windows\System32> schtasks /query /TN "\RtkAudUService64_BG" /XML <?xml version="1.0" encoding="UTF-16"?> <Task version="1.2" xmlns="http://schemas.microsoft.com/windows/2004/02/mit/task"> <RegistrationInfo> <Date>2010-07-30T20:43:10</Date> <Author>Realtek</Author> <URI>\RtkAudUService64_BG</URI> </RegistrationInfo> <Principals> <Principal id="Author"> <GroupId>S-1-5-32-545</GroupId> </Principal> </Principals> <Settings> <DisallowStartIfOnBatteries>false</DisallowStartIfOnBatteries> <StopIfGoingOnBatteries>false</StopIfGoingOnBatteries> <Enabled>false</Enabled> <ExecutionTimeLimit>PT0S</ExecutionTimeLimit> <MultipleInstancesPolicy>Parallel</MultipleInstancesPolicy> <IdleSettings> <Duration>PT10M</Duration> <WaitTimeout>PT1H</WaitTimeout> <StopOnIdleEnd>false</StopOnIdleEnd> <RestartOnIdle>false</RestartOnIdle> </IdleSettings> </Settings> <Triggers> <LogonTrigger> <Delay>PT30S</Delay> </LogonTrigger> </Triggers> <Actions Context="Author"> <Exec> <Command>""C:\WINDOWS\System32\DriverStore\FileRepository\realtekservice.inf_amd64_ed3f04e1261e4822\RtkAudUService64.exe""</Command> <Arguments>-background</Arguments> </Exec> </Actions> </Task> The <Enabled>false</Enabled> line in Settings, is visible only when the task is disabled. I would rather however use the PowerShell commandlets, to get the values.3.5KViews0likes2CommentsRe: Check Disabled state after Disable-ScheduledTask status on Running Task
Hello LainRobertson thank you for your fast reply. I think i understand your State and Trigger explanation. However, the trigger comes back the same enabled : True, when the task is enabled or disabled. Looking at your script i am a bit confused. You are running a foreach-object, but there seems to be only one state and one trigger property for a service, as far as i can see. For example: $task = Get-ScheduledTask -TaskName "RtkAudUService64_BG" -TaskPath \ $task | Get-Member TypeName: Microsoft.Management.Infrastructure.CimInstance#Root/Microsoft/Windows/TaskScheduler/MSFT_ScheduledTask Name MemberType Definition ---- ---------- ---------- Dispose Method void Dispose(), void IDisposable.Dispose() Equals Method bool Equals(System.Object obj) GetCimSessionComputerName Method string GetCimSessionComputerName() GetCimSessionInstanceId Method guid GetCimSessionInstanceId() GetHashCode Method int GetHashCode() GetType Method type GetType() ToString Method string ToString() Actions Property CimInstance#InstanceArray Actions {get;set;} Author Property string Author {get;set;} Date Property string Date {get;set;} Description Property string Description {get;set;} Documentation Property string Documentation {get;set;} Principal Property CimInstance#Instance Principal {get;set;} PSComputerName Property string PSComputerName {get;} SecurityDescriptor Property string SecurityDescriptor {get;set;} Settings Property CimInstance#Instance Settings {get;set;} Source Property string Source {get;set;} TaskName Property string TaskName {get;} TaskPath Property string TaskPath {get;} Triggers Property CimInstance#InstanceArray Triggers {get;set;} URI Property string URI {get;} Version Property string Version {get;set;} State ScriptProperty System.Object State {get=[Microsoft.PowerShell.Cmdletization.GeneratedTypes.ScheduledTask.StateEnum]($this.PSBase.CimInstanceProperti $task.Triggers Enabled : True EndBoundary : ExecutionTimeLimit : Id : Repetition : MSFT_TaskRepetitionPattern StartBoundary : Delay : PT30S UserId : PSComputerName : Or do you mean that every object has a corresponding trigger in WMI MSFT_TaskLogonTrigger object? Sorry for the confusion 😞3.4KViews0likes3CommentsCheck Disabled state after Disable-ScheduledTask status on Running Task
Hello to all, i seek your wisdom! I am trying to automate the following steps performed manually: - Disable a running scheduled task, but keeping it running. - Do actions that stop the task process. - Do additional actions. - Enable scheduled task and run it. I can do all the steps in PowerShell, but the issue i have is that when i use: Disable-ScheduledTask -TaskName 'TaskName' -TaskPath '\TaskPath\' while the task remains running, i am not able to get the Disabled state with: Get-ScheduledTask -TaskName 'TaskName' -TaskPath '\TaskPath\' In the taskschd.msc ui i can see the option to enable the task, so i see hat is is disabled But i need to confirm the Disabled state from PowerShell. I am not able to find anything in task cim properties either. I hope one of you knows the solution to my dilema.Solved4.6KViews0likes5Comments
Recent Blog Articles
No content to show