Waiting for activation

Hello everybody,
I have a script that activates a window before sending it a keystroke.
It works jolly good to select a PowerShell window, but for other windows, such as for instance Numpad, the window was not closed, so it was not properly selected.
With C# I did it at the first time : the difference is between SendKeys.Send, and SendKeys.SendWait (or for a previous version, the difference is in the boolean parameter that tells whether the instruction has to wait for the window to be focused before rendering the control.
In PowerShell, $wshell.AppActivate does not wait for the window to be focused.
Is there any other instruction or parameter, that waits for the window to be focused, before rendering the control?
I saw many people launching a loop to activate the window again and again, but this does not seem to work.

Attempting to manage windows or apps with AppActivate() and SendKeys() is never going to be a solid solution, imho. There are other tools like AutoIT or PowerAutomate that are providing Robotic Process Automation (RPA) functionality. Typically, this is still fraught with the same issues, such as any unknown popup, application opening, notification can break the entire process. Folks spin up workstations just to run the automation to control what apps are installed to essentially create a controlled environment. With that said, the best course of action is attempting to solve the issue you are trying to solve with commands or API interface rather than an RPA approach.

Well, we shall see robotics later, for a production line for instance, for the moment being I am trying and getting a not too buggy user interface.
Visual Studio and PowerShell are nice tools for that, provided we know what to ask them.
For instance, the wait parameter of the SendKeys instruction.

Regarding AppActivate, have you reviewed the documentation? There is a boolean parameter for wait:

AppActivate statement (VBA) | Microsoft Learn

Assume you have seen this content:

Extending PowerShell with VBScript and CSharp - powershell.one

The interwebs are plagued with folks attempting to focus apps as you can see with the many topics on Stackoverflow and other forums:

powershell appactivate is focused - Search (bing.com)

You know, I have 15 years of experience in VBA, so this is why I said “or for a previous version, the difference is in the boolean parameter that tells whether the instruction has to wait for the window to be focused before rendering the control” (sorry I forgot to close the parenthesis).
It would have been of interest to know that this can apply to PowerShell.

As I said at one point, it seems that when I search a topic concerning PowerShell on Internet (at least on Qwant), I get the forums threads before the documentation.
Using Get-Help would be nice, but update-help failed. Do you think I have to reinstall Windows PowerShell ?

Powershell is just utilizing the COM object, it is not specific to Powershell, it is the same COM object that Visual Basic (VBA, VBS) uses. If you look at automation of Excel or Word, it uses the same .COM object without Application\Global Variable references. For instance, this vba code, the variables xlLastCell, xlYes, TableStyleMedium15 would need to be manually defined as constants in Powershell code, but it is using the same COM object to manipulate Office documents (provide methods, properties, etc.) that VBA uses:

Sub A_SelectAllMakeTable()
    Dim tbl As ListObject
    Dim rng As Range

    Set rng = Range(Range("A1"), Range("A1").SpecialCells(xlLastCell))
    Set tbl = ActiveSheet.ListObjects.Add(xlSrcRange, rng, , xlYes)
    tbl.TableStyle = "TableStyleMedium15"
End Sub

Using Powershell does get access to leverage C# as the link in the last post discusses to provide some further capabilities outside of the old COM objects.

Get-Help will not really provide insight, it will show help for installed modules on the systems. For help to work, a common fix is to run Powershell as Administrator and the run the Update-Help -Force. This isn’t going to have AppActivate, only help for Powershell cmd-lets that are installed on the local system.

So, as I understand, if the command Get-Help had worked properly, I should have known all that.
It does not find the resources on line for the update. Do you think I have to suspect a problem with the DNS, as I had a few weeks ago on another connexion ?
Or is PowerShell to be reinstalled ?
About the dns I have to precise that now, PowerShell help update is the only problem.

In a near future I shall prepare two installations, one on Windows 10 and one on Windows 11, to be ready to react when I have no telecom available with free volume.

This will expose me to double difficulties, but if it gives me better chances of having something that works …

What is the full output of the error message when you run Update-Help?

Please copy and paste the error (all of the red text) here, and use the </> button to format your post.

How to format code on PowerShell.org

Pretty good question indeed, as when doing it again I have less errors than last time: I had forgotten to launch it as an administrator.

But I still have one, that tells that HelpInfo XML file cannot be extracted, and that I have to verify the HelpInfoUri property in the module manifest.

OK. I presume that once I find the suspect
Uri (supposing it is obvious at first sight), I shall need the correct one.

I presume that I shall easily find a file with a manifest extension, in a folder with PowerShell in its name. Going to begin the search by the program files directory.

PS C:\Windows\system32> update-help                                                       update-help : Échec lors de la mise à jour de l’aide du ou des modules «ConfigDefender,
ConfigDefenderPerformance, PSReadline» avec la ou les cultures d’interface utilisateur
{fr-FR} : Impossible d’extraire le fichier XML HelpInfo pour la culture d’interface
utilisateur fr-FR. Assurez-vous que la propriété HelpInfoUri du manifeste de module est
valide ou vérifiez votre connexion réseau, puis réessayez d’exécuter la commande.
Au caractère Ligne:1 : 1
+ update-help
+ ~~~~~~~~~~~
    + CategoryInfo          : ResourceUnavailable: (:) [Update-Help], Exception
    + FullyQualifiedErrorId : UnableToRetrieveHelpInfoXml,Microsoft.PowerShell.Commands.

I realize that this is a good exercise for a PowerShell script.

This has two steps: finding the folders with PowerShell in their names, and then in them finding the files with extension manifest.
The second step seems pretty easy, in fact there will be a third step, to extract the Uris from the files.

Let us begin by step 1 …
Finding items with PowerShell in their names can be
Get-ChildItem "*PowerShell*", but that looks only in the current directory.
Do I have to write a functions structure to browse the whole arborescence recursively?

Oh, I see that Get-ChildItem has a -Depth property, and a -Recurse one. I should have waited them in reverse order, but never mind.
This looks like a good track to begin with …
On a long path nevertheless.

Yes, the need to run as Administrator is easily overlooked in the mass of red text telling you it can’t update all the various modules - I thought that might the case.

My ConfigDefenderPerformance and PSReadline help also doesn’t update (en-GB).

The PSReadline problem I’m aware of, and there is a fix for that:

The ConfigDefenderPerformance problem was new to me, but I found it has already been reported:

Yes, everybody knows that when the whether is cold, you have to get more covered, but remember Pr Tournesol: sometimes people forget about that.

Well for the rest, if I read properly, listing the manifests was an interesting exercise, but it will not help for the updates, as the problem is on the server side?

Thank you for the information.
And thanks to everybody who tried and helped.