Tip: How to use the Current Version of PowerShell Core

The installation of UiPath Studio or Robot contains Microsoft PowerShell Core. On this way you can use PowerShell Core in Windows compatibility mode (x64) without additional software installation. The advantage of this approach is that the package contains all we need and we have nothing to do. UiPath delivers it and we can use it in our context. But we cannot always wait for the UiPath release updates to close known security leaks and vulnerabilities. It is our task to ensure security in our processes. Therefore it is possible to download the Microsoft.PowerShell.SDK via Manage Packages - with a fresh published date.

After the download and installation you can find the current Microsoft.PowerShell.SDK in the list of your dependencies of your project. This also has the advantage that the dependency is directly transparent in the project.json file - this is very good for analysis purposes.

image

A tiny test brings us very quick the desired result, with UiPath’s built-in Invoke PowerShell activity.

image

Here the Test.ps1 file:

#-Begin-----------------------------------------------------------------

"$($PSVersionTable.PSVersion) - $env:PROCESSOR_ARCHITECTURE"

#-End-------------------------------------------------------------------

We are responsible for our RPA processes to our customers - and its advocate, the Chief Information Security Officer (CISO). We must be aware of the use of additional libraries and know their dependencies, to ensure this aspect of security. PowerShell Core is a very powerful scripting language that can provide us with excellent support in automating business processes. Therefore, not only for security, but also for constantly improving functionality of PowerShell, the approach described here is certainly a valid one to keep PowerShell up to date.

Addendum 17.11.2022: This approach is deprecated, because it works only with Windows - Legacy compatibility mode.

6 Likes

Thanks a lot, @StefanSchnell .

Finally I was able to figure out that my project is not working anymore after converting it from Windows-Legacy to regular, non-legacy Windows, because the PowerShell versions they are using are different:

In my Windows-Legacy project, it is in:
“C:\Windows\SysWOW64\WindowsPowerShell\v1.0”
That is the 32-bit version that comes with the operating system.

In the non-legacy Windows one, it says it is:
“C:\Users[User].nuget\packages\system.management.automation\7.1.0\runtimes\win\lib\net5.0”

What the heck is that? Do they really expect our project after converting with such a mess?

Of course whatever dependencies, packages we installed, etc., are not gonna be there. Plus who knows what version is it really using and what the incompatibilities, security flaws, and whatever.

The one I use via console, when executed via the icon through the Windows start menu, it’s in C:\Windows\System32\WindowsPowerShell\v1.0 and this is the standard, 64-bit version that comes with the operating system, and common sense says to me that this should be the one used in every case.

Or at least there should be a way to tel UiPath which one we want to use.

Instead, the way you found it’s not even working anymore.

So clever!!