A True .EXE

This forum can be browsed by the general public. Posting is limited to current SAPIEN license holders with active maintenance and does not offer a response time guarantee.
Forum rules
DO NOT POST LICENSE NUMBERS, ACTIVATION KEYS OR ANY OTHER LICENSING INFORMATION IN THIS FORUM.
Only the original author and our tech personnel can reply to a topic that is created in this forum. If you find a topic that relates to an issue you are having, please create a new topic and reference the other in your post.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
This topic is 6 years and 4 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
User avatar
jsira2003@yahoo.com
Posts: 117
Last visit: Tue Jul 11, 2023 6:18 am

A True .EXE

Post by jsira2003@yahoo.com »

I realize that when we create an .exe with powershell studio 2017 all we get is an .exe wrapper around the code. Is there a way to get a true .exe? That is true that script into real machine code?

thanks,
John
User avatar
Alexander Riedel
Posts: 8489
Last visit: Thu Apr 18, 2024 9:59 am
Answers: 20
Been upvoted: 37 times

Re: A True .EXE

Post by Alexander Riedel »

That is why we call it a packager. I am not sure about the "all we get" part, but...
If you want real machine code you need to use an old fashioned compiler and its associated language, C or C++ for example. Even any .NET language (C#, VB.NET etc. )is technically not a 'true' exe, since the compiler only produces ILASM.
PowerShell is a high level interpreted console language, so there is no compiler that translates to machine op codes.
I guess that was a long winded way of getting to: Why do you ask? :D
Alexander Riedel
SAPIEN Technologies, Inc.
User avatar
jsira2003@yahoo.com
Posts: 117
Last visit: Tue Jul 11, 2023 6:18 am

Re: A True .EXE

Post by jsira2003@yahoo.com »

I mention it because of speed. I am using the get-childitem command and have a need to traverse large directory trees. I want my app to run as fast as possible. I tested it for 4 weeks doing all the optimizations on the web. I had some success removing the foreach loops and used interation instead. I have removed unnecessary conditions. I put the conditions in the most likely order of occurence. I could not use the filter command since it only filters one item and I have many. I had to use the other filtering mechanism.

I guess I'm out of additional options.
John
User avatar
Alexander Riedel
Posts: 8489
Last visit: Thu Apr 18, 2024 9:59 am
Answers: 20
Been upvoted: 37 times

Re: A True .EXE

Post by Alexander Riedel »

Give me some more information on what you need to do. Traversing large folder structures is never fast, it also depends on if you do that over the network or on a local hdd that is busy otherwise. What kind of filtering do you need to do?
Are you also aware that PowerShell Studio can create performance graphs as you execute a script, so you can compare CPU usage, memory consumption and overall duration of the script?
Alexander Riedel
SAPIEN Technologies, Inc.
User avatar
jsira2003@yahoo.com
Posts: 117
Last visit: Tue Jul 11, 2023 6:18 am

Re: A True .EXE

Post by jsira2003@yahoo.com »

I thought of writing an agent on the target system to do the processing. I am not sure how much that will speed up things? The network connection is at gigabit speed and I am running app off hours. I don't believe running app local will be worthwhile with the network bandwidth available. It may not be worth the programming effort.

Memory wise I am using the following: [System.Collections.ArrayList]$files
I found out the system.collections.arraylist instead of [array]$array allows me to modify and remove entries in the array without the need to re-create the array. I saved a ton of ram using this.

The filtering method i use is the include. I can have a long list of items like *.gif, *.tif etc. This has worked quite well.

Here is my get-childitem line:

[System.Collections.ArrayList]$files = get-childitem -recurse -force -Path $($shareDir) -include $array -ErrorAction SilentlyContinue | select @{ Name = "Server"; Expression = { $server }}, @{ Name = "shareDir"; Expression = { $shareDir }}, fullname, name, length, @{ Name = "Hash"; Expression = { get-filehash $_.fullname -Algorithm md5 | select -ExpandProperty hash }}, lastwritetime -ErrorAction SilentlyContinue

Any optimizations and speed adds would be huge!

thanks,
John
User avatar
davidc
Posts: 5913
Last visit: Mon Jul 08, 2019 8:55 am
Been upvoted: 2 times

Re: A True .EXE

Post by davidc »

Using .NET directly instead of Get-ChildItem will greatly improve performance. The .NET API took significantly less time then using Get-ChildItem when I tested the following code:

Measure-Command {

<#
.SYNOPSIS
Loads the folder's child directories and files into a List.

.DESCRIPTION
A detailed description of the Read-File function.

.PARAMETER Folder
A description of the Folder parameter.

.PARAMETER List
A description of the List parameter.

.NOTES
Additional information about the function.
#>
function Read-File
{
param
(
[string]$Folder,
[System.Collections.Generic.List[string]]$List
)

try
{
$list.AddRange([System.IO.Directory]::GetFiles($folder))

foreach ($subFolder in [System.IO.Directory]::GetDirectories($folder))
{
$list.Add($subFolder)
Read-File $subFolder $list
}
}
catch { }
}

$files = New-Object System.Collections.Generic.List[string]
Read-File 'C:\Program Files (x86)' $files
}
$files.Count #Check the count

Measure-Command {
$files = Get-ChildItem -Path "C:\Program Files (x86)" -Force -Recurse -ErrorAction SilentlyContinue

}
$files.Count #Check the count
Measure File Access.ps1
(1.39 KiB) Downloaded 117 times
David
SAPIEN Technologies, Inc.
User avatar
jsira2003@yahoo.com
Posts: 117
Last visit: Tue Jul 11, 2023 6:18 am

Re: A True .EXE

Post by jsira2003@yahoo.com »

I can look into that. My concern is my include list. Is there a way to add that to the .net line of code? I need to be able to pair down the results to only the files I am looking for.

thanks,
John
User avatar
jsira2003@yahoo.com
Posts: 117
Last visit: Tue Jul 11, 2023 6:18 am

Re: A True .EXE

Post by jsira2003@yahoo.com »

I can look into that. My concern is my include list. Is there a way to add that to the .net line of code? I need to be able to pair down the results to only the files I am looking for.

thanks,
John
User avatar
davidc
Posts: 5913
Last visit: Mon Jul 08, 2019 8:55 am
Been upvoted: 2 times

Re: A True .EXE

Post by davidc »

Yes, you can specify a filter in the GetFiles method call:

https://msdn.microsoft.com/en-us/library/wz42302f.aspx
David
SAPIEN Technologies, Inc.
User avatar
jsira2003@yahoo.com
Posts: 117
Last visit: Tue Jul 11, 2023 6:18 am

Re: A True .EXE

Post by jsira2003@yahoo.com »

I have concern with this .net command. I have played with it. I do recall when hitting files I had no permissions for the script crashed. There is no -SilentlyContinue with the command. The catch will just catch the failure and the command will stop. This is what I recall. I dabbled with this .net command. Not sure it will give me what I want.
If I hit files I can't read it must keep traversing the path.

thanks,
John
This topic is 6 years and 4 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.