Sometimes powershell fails to Import-Module Microsoft.PowerShell.LocalAccounts - powershell

I have a simple PowerShell script that is supposed to be run on the Windows Server 2019 64 bit machine. I use the Get-LocalGroupMemeber cmdlet in this script, which is part of the LocalAccounts module.
The problem is that my script fails to run because the module couldn't be loaded and the worst part is that the problem appears only a few times out of hundreds. Meaning, if I re-run the script right after its failure it will be finished successfully. Another strange thing is that it's not the only module that fails from time to time, the same happens with the SQLPS module.
I use the following batch file for my script invocation because in reality it is invoked from a 32-bit application, whereas the OS version is 64 bit.
if "%PROCESSOR_ARCHITEW6432%"=="AMD64" (
set pwshPass=%SystemRoot%\Sysnative\WindowsPowerShell\v1.0\powershell.exe
) else (
set pwshPass=%SystemRoot%\System32\WindowsPowerShell\v1.0\powershell.exe
)
%pwshPass% -ExecutionPolicy Bypass -File ".\Run.ps1"
Here is the stack trace of the error:
The 'Get-LocalGroupMember' command was found in the module 'Microsoft.PowerShell.LocalAccounts', but the module could not be loaded.
For more information, run 'Import-Module Microsoft.PowerShell.LocalAccounts'.
---$gt; System.Management.Automation.CmdletInvocationException: Could not load file or assembly 'file:///C:\windows\system32\WindowsPowerShell\v1.0\Modules\Microsoft.PowerShell.LocalAccounts\1.0.0.0\Microsoft.Powershell.LocalAccounts.dll' or one of its dependencies.
Catastrophic failure (Exception from HRESULT: 0x8000FFFF (E_UNEXPECTED)) ---$gt; System.IO.FileLoadException: Could not load file or assembly 'file:///C:\windows\system32\WindowsPowerShell\v1.0\Modules\Microsoft.PowerShell.LocalAccounts\1.0.0.0\Microsoft.Powershell.LocalAccounts.dll' or one of its dependencies.
Catastrophic failure (Exception from HRESULT: 0x8000FFFF (E_UNEXPECTED)) ---$gt; System.Runtime.InteropServices.COMException:
Catastrophic failure (Exception from HRESULT: 0x8000FFFF (E_UNEXPECTED))

Related

How to fix missing simulink simulation artificats issue when running test in parallel mode?

I have 29 Simulink/Matlab Test. It has a lot of different reference models. Before running a 20 second simulation , it has to load all reference models and create a lot of simulation artifacts in a work folder. A lot of reference model are shared in-between test.
When running one test at a time, I have no issue, all simulation artifact are created and used to run the various simulation. Everything Passes.
When running it all via parallel processing. I have a issue.Some simulation artifact are not built or missing, hence my simulation fails even before running.But surprisingly, not all 29 of them fail. It actually random,last time it was 17, another time it was 22. And it even ran once with 0 fail.
Another note, I only have this issue when running it on a self-hosted computer on Azure-Pipelines for CI purposes.
I would like to fix this issue and reproduce stable test pass/fail results of one at a time run, but on parallel process run. How would I do that?
Error:
2020-11-03T03:16:27.1083996Z Making simulation target "Foo_src_sfun", ...
2020-11-03T03:16:27.1084227Z
2020-11-03T03:16:27.1084361Z
2020-11-03T03:16:27.1084502Z
2020-11-03T03:16:27.1084789Z Microsoft (R) Program Maintenance Utility Version 14.00.24210.0
2020-11-03T03:16:27.1085188Z Copyright (C) Microsoft Corporation. All rights reserved.
2020-11-03T03:16:27.1085441Z
2020-11-03T03:16:27.1085815Z NMAKE : fatal error U1052: file 'Foo_src_sfun.mak' not found
2020-11-03T03:16:27.1086175Z Stop.
2020-11-03T03:16:27.1089399Z ================================================================================
2020-11-03T03:16:27.1089936Z Error occurred in TestSim/testSim(File=test_FooTest1_slx) and it did not run to completion.
2020-11-03T03:16:27.1090308Z
2020-11-03T03:16:27.1090497Z ---------
2020-11-03T03:16:27.1090720Z Error ID:
2020-11-03T03:16:27.1090946Z ---------
2020-11-03T03:16:27.1091254Z 'Slvnv:simcoverage:SimulationFailed'
2020-11-03T03:16:27.1091481Z
2020-11-03T03:16:27.1091669Z --------------
2020-11-03T03:16:27.1091919Z Error Details:
2020-11-03T03:16:27.1092186Z --------------
2020-11-03T03:16:27.1092419Z Error using cvsim
2020-11-03T03:16:27.1092659Z Simulation failed
2020-11-03T03:16:27.1092864Z
2020-11-03T03:16:27.1093112Z Error in testRunner (line 145)
2020-11-03T03:16:27.1093477Z [cvdo, simOutRes] = cvsim(testObj,paramStruct) ;
2020-11-03T03:16:27.1093765Z
2020-11-03T03:16:27.1094034Z Error in TestSim/testSim (line 30)
2020-11-03T03:16:27.1094373Z [cvdo, simOutRes, ErrLog] = testRunner(File,20);
2020-11-03T03:16:27.1094638Z
2020-11-03T03:16:27.1094830Z Caused by:
2020-11-03T03:16:27.1095168Z Error using autobuild_kernel>autobuild_local (line 219)
2020-11-03T03:16:27.1095612Z Unable to create mex function 'Foo_src_sfun.mexw64'
2020-11-03T03:16:27.1096006Z required for simulation.
2020-11-03T03:16:27.1096427Z ================================================================================
Update:
I found that I have also another kind of error, leads pretty much to same result.
2020-11-03T03:18:36.1668328Z Making simulation target "Foo2_src_sfun", ...
2020-11-03T03:18:36.1668601Z
2020-11-03T03:18:36.1668735Z
2020-11-03T03:18:36.1669087Z 'Foo2_src_sfun.bat' is not recognized as an internal or external command,
2020-11-03T03:18:36.1669483Z operable program or batch file.
2020-11-03T03:18:36.1669685Z
2020-11-03T03:18:36.1669892Z >>Removing MiL paths...
2020-11-03T03:18:36.1670104Z >>Done
I made a runSingleTest() that I run before my parallel run. Before running it creates all required model reference mexw64 files in the **/work/sim_artifact folder.
Hence when the parallel run they don't need to create any new files, they either use whats already there or update the files.
I have been having no issue since that change. Just a longer run time because of that repetitive test.

unable to start a Process in Scala/Play application

I have a ccm.py script which runs Cassandra cluster on local machine. I am able to run the command using windows command prompt. But I get error if I try to do so using Process class in Scala.
I want to run it before starting my test cases. So I am calling Process in beforeAll.
override def beforeAll():Unit = {
println("starting cassandra cluster locally")
val ccmCommand = Process("ccm.py start").!
}
The error I get is
An exception or error caused a run to abort: Cannot run program "ccm.py": CreateProcess error=193, %1 is not a valid Win32 application
java.io.IOException: Cannot run program "ccm.py": CreateProcess error=193, %1 is not a valid Win32 application
at java.lang.ProcessBuilder.start(ProcessBuilder.java:1048)
I also tried using cassandra -f command (which also works from cmd prompt) but I got error
An exception or error caused a run to abort: Cannot run program "cassandra": CreateProcess error=2, The system cannot find the file specified
java.io.IOException: Cannot run program "cassandra": CreateProcess error=2, The system cannot find the file specified
at java.lang.ProcessBuilder.start(ProcessBuilder.java:1048)
How can I solve the issue?
Update
Thanks to Alex Ott, I have made some progress but I think there has to be a better and more reliable way to test the code and also make the code more portable
The code which seem to work so far is
override def beforeAll():Unit = {
println("starting cassandra cluster locally")
val ccmCommand = Process("python",Seq("C:\\Users\\manu\\Documents\\manu\\ccm-3.1.4.tar\\dist\\ccm-3.1.4\\ccm.py","start")).run //NOT GOOD. Using hardcoded path!!
println(s"ccm returned ${ccmCommand}")
Thread.sleep(30000) //the wait is too long and there is no guarantee that the cluster will be up properly
}
Is there a better (w.r.t reliable without hard coding the path) to bring up the cluster before tests get executed.

error on Teamcity running command line custom script

I'm trying to run command line -custom script on Teamcity and getting this error (127):
[02:22:25][Step 1/1] /mnt/teamcity/temp/agentTmp/custom_script8657691082445726475: 1: /mnt/teamcity/temp/agentTmp/custom_script8657691082445726475: ./run.sh: not found
[02:22:25][Step 1/1] Process exited with code 127
[02:22:26][Step 1/1] Step run protractor test (Command Line) failed
any ideas?
It looks like some dependency of your script is not found where it expects it:
./run.sh: not found
Is that the actual script you are running? or is your script trying to call that script?
what solved it was adding 'Agent Requirements' (under build Configuration Settings) saying that 'system.agent.name' equals to the name of the Agent we use.

Powershell Try Catch

I've a simple powershell script below which basically executes the abc.exe (console application) with few arguments.
& abc.exe ar1 ar2
abc.exe file is .net so it has it's own exception handler.
Whenever abc.exe throws exception I would like the Powershellscript to catch and log/echo.
Could someone help me how to achieve above.
No.
The exception in abc.exe will bubble up to main method, not any more. But you can check the ERRORLEVEL of abc.exe by looking at $LASTEXITCODE. (Check this)
What you should do:
Your abc.exe, as any exe, should return errorlevel 0 if everything was ok and other number in case of error
Abc.exe main method could write an error message in case of problem. This way when you invoke it from a PowerShell script you will see the error message in console and later your script will check for errorlevel.
Additionally, you can also use different exitcodes for errorlevels in abc.exe to provide some information to PowerShell script. For example these are 7zip error levels.
0 --> No error
1 --> Warning
2 --> Fatal error
7 --> Command line error
8 --> Not enough memory for operation
255 --> User stopped the process

Chain psexec and nunit is not working (psexec exit with code 1 and nunit is crashed)

Sorry for unclear subject but i really don't understand where problem.
I use a system for autotests c#+webdriver for chrome + nunit (2.6) + cc.net ( 1.6.7981.1)
And my tests is run on remote machine (Windows XP SP 2 x86)via psexec which start bat file on remote machine
bat file includes 2 commands:
run msbuild
run nunit-console
Well, psexec has next arguments
/accepteula \MachineName -u Login -p Pass -s Path\start.bat
Bat file has next command
nunit-console-x86.exe "%PROJECT_FOLDER%\Path\Tests.dll" "/xml=%TEST_RESULT_PATH%"
When cc.net launch psexec tests is started and the tests work during some time. Unexpected, psexec exit with code 1
message level="Error">Path\start.bat exited on MachineName with error code 1. message
But nunit-console on remote machine is continue working
And after some time console is crashed with error
szAppName : nunit-console-x86.exe szAppVer : 2.6.0.12051
szModName : kernel32.dll szModVer : 5.1.2600.2180 offset :
0001eb33
Message from Event log
Application: nunit-console-x86.exe Framework Version: v4.0.30319
Description: The process was terminated due to an unhandled exception.
Exception Info: System.IO.IOException Stack: at
System.IO._Error.WinIOError(Int32, System.String) at
System.IO._ConsoleStream.Write(Byte[], Int32, Int32) at
System.IO.StreamWriter.Flush(Boolean, Boolean) at
System.IO.StreamWriter.Write(Char[], Int32, Int32) at
System.IO.TextWriter.WriteLine(System.String) at
System.IO.TextWriter.WriteLine(System.String, System.Object) at
System.IO.TextWriter+SyncTextWriter.WriteLine(System.String,
System.Object) at System.Console.WriteLine(System.String,
System.Object) at NUnit.ConsoleRunner.Runner.Main(System.String[])
at NUnit.ConsoleRunner.Class1.Main(System.String[])
If run nunit locally than no problem(nunit-console works fun).
Some time ago system worked, and i don't know what is changed (This is most bad case)
How can i resolve this problem?
Thanks!
This problem is resolved!
Now system is working