Why does powershell script from inno setup print spaces between each two characters? - powershell

I am running a powershell script from my inno setup installer via the command:
[Run]
Filename: {cmd}; Parameters: "/c powershell.exe -executionpolicy bypass -File ""{app}\InstallScripts\powershellScript.ps1""
and transcribing my commands/output to a text file by running the command:
StartTranscript -Path $logFile at the beginning of my script.
But in my log file which records all the commands/output I get really weird spaces between each pair of characters like so:
W i n d o w s P o w e r S h e l l T r a n s c r i p t S t a r t
S t a r t t i m e : 2 0 1 8 1 0 0 8 1 3 5 9 1 7
U s e r n a m e : D a v i d
But when I run the script manually I get the printings to the file normally, without the weird spaces.
Why is this happening and how can I correct it so when I run the script from my installer it will print the commands/output normally without these spaces between characters?

Related

VScode Exception occur: System.ArgumentOutOfRangeException

When I try to run any c++ program in vs code an exception occur and do not run the program
Oops, something went wrong. Please report this bug with the details below.
Report on GitHub: https://github.com/lzybkr/PSReadLine/issues/new
-----------------------------------------------------------------------
Last 101 Keys:
c d Space " c : \ U s e r s \ U S E R
\ D o c u m e n t s \ p r o g r a m m i n g \ " Space ; Space i f Space ( $ ?
) Space { Space g + + Space c o d e 2 . c p p Space - o Space c o d e 2 Space
} Space ; Space i f Space ( $ ? ) Space { Space . \ c o d e 2 Space } Enter
Exception:
System.ArgumentOutOfRangeException: The value must be greater than or equal to zero and less than the console's buffer size in that dimension.
Parameter name: left
Actual value was -1.
at System.Console.SetCursorPosition(Int32 left, Int32 top)
at Microsoft.PowerShell.Internal.VirtualTerminal.set_CursorLeft(Int32 value)
at Microsoft.PowerShell.PSConsoleReadLine.ReallyRender(RenderData renderData, String defaultColor)
at Microsoft.PowerShell.PSConsoleReadLine.ForceRender()
at Microsoft.PowerShell.PSConsoleReadLine.Insert(Char c)
at Microsoft.PowerShell.PSConsoleReadLine.SelfInsert(Nullable`1 key, Object arg)
at Microsoft.PowerShell.PSConsoleReadLine.ProcessOneKey(ConsoleKeyInfo key, Dictionary`2 dispatchTable, Boolean ignoreIfNoAction, Object arg)
at Microsoft.PowerShell.PSConsoleReadLine.InputLoop()
at Microsoft.PowerShell.PSConsoleReadLine.ReadLine(Runspace runspace, EngineIntrinsics engineIntrinsics)
-----------------------------------------------------------------------
By using manual command in terminal , I can run my c++ program.
I can find some issues in vscode github repository about this problem but can not understand any solution

VS Test failing in Pipelines with missing 'Microsoft.NET.Test.Sdk'

I'm getting a failed builds due to the Visual Studio Test step failing in my Build Pipeline.
I have a simple .NET Core v2.1 class library and associated MS Test library. I have 2 steps in my pipeline:
A .NET Core build step, and
A Visual Studio Test step
Both projects target the netcoreapp2.1 framework, see below for .csproj files.
I have tried enabling and disabling the Code coverage option, but this make no difference.
Thanks in advance,
Kaine
.csproj files
Main Project
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp2.1</TargetFramework>
<AssemblyName>Trustmarque.Core.ExtensionMethods</AssemblyName>
<RootNamespace>Trustmarque.Core.ExtensionMethods</RootNamespace>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Description>Generalised class extension methods build on the .NET Core.</Description>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="11.0.2" />
</ItemGroup>
</Project>
Test Project
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp2.1</TargetFramework>
<IsPackable>false</IsPackable>
<AssemblyName>Trustmarque.Core.ExtensionMethods.Tests</AssemblyName>
<RootNamespace>Trustmarque.Core.ExtensionMethods.Tests</RootNamespace>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.9.0" />
<PackageReference Include="MSTest.TestAdapter" Version="1.3.2" />
<PackageReference Include="MSTest.TestFramework" Version="1.3.2" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\ExtensionMethods\ExtensionMethods.csproj" />
</ItemGroup>
</Project>
YAML
queue:
name: Hosted VS2017
demands: vstest
steps:
- task: DotNetCoreCLI#2
displayName: '.NET Core Build'
- task: VSTest#2
displayName: 'VS Unit Test'
inputs:
testFiltercriteria: /diag
codeCoverageEnabled: true
otherConsoleOptions: '/framework:".NETCoreApp,Version=2.1"'
Test Output Log
2018-11-14T09:33:56.0414482Z ##[section]Starting: VS Unit Test
2018-11-14T09:33:56.0420823Z ==============================================================================
2018-11-14T09:33:56.0420887Z Task : Visual Studio Test
2018-11-14T09:33:56.0420941Z Description : Run unit and functional tests (Selenium, Appium, Coded UI test, etc.) using the Visual Studio Test (VsTest) runner. Test frameworks that have a Visual Studio test adapter such as MsTest, xUnit, NUnit, Chutzpah (for JavaScript tests using QUnit, Mocha and Jasmine), etc. can be run. Tests can be distributed on multiple agents using this task (version 2).
2018-11-14T09:33:56.0420983Z Version : 2.142.12
2018-11-14T09:33:56.0421033Z Author : Microsoft Corporation
2018-11-14T09:33:56.0421089Z Help : [More information](https://go.microsoft.com/fwlink/?LinkId=835764)
2018-11-14T09:33:56.0421126Z ==============================================================================
2018-11-14T09:33:56.9036862Z SystemVssConnection exists true
2018-11-14T09:33:57.0359241Z SystemVssConnection exists true
2018-11-14T09:33:57.1181619Z Running tests using vstest.console.exe runner.
2018-11-14T09:33:57.1181728Z ======================================================
2018-11-14T09:33:57.1182048Z Test selector : Test assemblies
2018-11-14T09:33:57.1182141Z Test filter criteria : null
2018-11-14T09:33:57.1182212Z Search folder : D:\a\1\s
2018-11-14T09:33:57.1182743Z VisualStudio version selected for test execution : latest
2018-11-14T09:33:57.8312901Z Run in parallel : false
2018-11-14T09:33:57.8314015Z Run in isolation : false
2018-11-14T09:33:57.8315114Z Path to custom adapters : null
2018-11-14T09:33:57.8319882Z Other console options : /framework:".NETCoreApp,Version=2.1"
2018-11-14T09:33:57.8320427Z Code coverage enabled : true
2018-11-14T09:33:57.8320689Z Diagnostics enabled : false
2018-11-14T09:33:57.8322155Z SystemVssConnection exists true
2018-11-14T09:33:57.8348561Z Run the tests locally using vstest.console.exe
2018-11-14T09:33:57.8348848Z ========================================================
2018-11-14T09:33:57.8349439Z Test selector : Test assemblies
2018-11-14T09:33:57.8352816Z Test assemblies : **\*test*.dll,!**\*TestAdapter.dll,!**\obj\**
2018-11-14T09:33:57.8353669Z Test filter criteria : null
2018-11-14T09:33:57.8360790Z Search folder : D:\a\1\s
2018-11-14T09:33:57.8361971Z Run settings file : D:\a\1\s
2018-11-14T09:33:57.8369736Z Run in parallel : false
2018-11-14T09:33:57.8370326Z Run in isolation : false
2018-11-14T09:33:57.8392182Z Path to custom adapters : null
2018-11-14T09:33:57.8393171Z Other console options : /framework:".NETCoreApp,Version=2.1"
2018-11-14T09:33:57.8395168Z Code coverage enabled : true
2018-11-14T09:33:57.8396140Z Diagnostics enabled : false
2018-11-14T09:33:57.8398717Z Rerun failed tests: false
2018-11-14T09:33:57.8401805Z VisualStudio version selected for test execution : latest
2018-11-14T09:33:58.9933609Z ========================================================
2018-11-14T09:33:58.9973631Z ======================================================
2018-11-14T09:33:59.0613609Z [command]"C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Common7\IDE\CommonExtensions\Microsoft\TestWindow\vstest.console.exe" #D:\a\_temp\69e3bc61-e7f0-11e8-8572-4338aa006dd6.txt
2018-11-14T09:34:06.3128046Z Microsoft (R) Test Execution Command Line Tool Version 15.8.0
2018-11-14T09:34:06.3130539Z Copyright (c) Microsoft Corporation. All rights reserved.
2018-11-14T09:34:06.3131113Z
2018-11-14T09:34:06.6145727Z vstest.console.exe
2018-11-14T09:34:06.6146432Z "D:\a\1\s\ExtensionMethods.Tests\bin\Debug\netcoreapp2.1\Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Interface.dll"
2018-11-14T09:34:06.6147591Z "D:\a\1\s\ExtensionMethods.Tests\bin\Debug\netcoreapp2.1\Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.dll"
2018-11-14T09:34:06.6147793Z "D:\a\1\s\ExtensionMethods.Tests\bin\Debug\netcoreapp2.1\Trustmarque.Core.ExtensionMethods.Tests.dll"
2018-11-14T09:34:06.6149501Z /EnableCodeCoverage
2018-11-14T09:34:06.6149657Z /logger:"trx"
2018-11-14T09:34:06.6149783Z /TestAdapterPath:"D:\a\1\s"
2018-11-14T09:34:06.6149907Z /framework:".NETCoreApp,Version=2.1"
2018-11-14T09:34:12.8077290Z Starting test execution, please wait...
2018-11-14T09:34:14.8437128Z Test run will use DLL(s) built for framework .NETCoreApp,Version=v2.1 and platform X86. Following DLL(s) do not match framework/platform settings.
2018-11-14T09:34:14.8437793Z Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Interface.dll is built for Framework 4.5 and Platform AnyCPU.
2018-11-14T09:34:14.8438215Z Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.dll is built for Framework 1.5 and Platform AnyCPU.
2018-11-14T09:34:14.8438617Z Go to http://go.microsoft.com/fwlink/?LinkID=236877&clcid=0x409 for more details on managing these settings.
2018-11-14T09:34:14.8438786Z
2018-11-14T09:34:23.5616980Z M i c r o s o f t ( R ) C o v e r a g e C o l l e c t i o n T o o l V e r s i o n 1 5 . 0 . 3 0 3 1 9 . 0
2018-11-14T09:34:23.5617265Z
2018-11-14T09:34:23.5617351Z
2018-11-14T09:34:23.5617457Z C o p y r i g h t ( c ) M i c r o s o f t C o r p o r a t i o n . A l l r i g h t s r e s e r v e d .
2018-11-14T09:34:23.5617498Z
2018-11-14T09:34:23.5617554Z
2018-11-14T09:34:23.5617591Z
2018-11-14T09:34:23.5617627Z
2018-11-14T09:34:24.4903850Z 2.8847
2018-11-14T09:34:25.4504736Z System.IO.FileNotFoundException: Unable to find tests for D:\a\1\s\ExtensionMethods.Tests\bin\Debug\netcoreapp2.1\Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Interface.dll. Make sure test project has a nuget reference of package "Microsoft.NET.Test.Sdk" and framework version settings are appropriate. Rerun with /diag option to diagnose further.
2018-11-14T09:34:25.4504927Z at Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Hosting.DotnetTestHostManager.GetTestHostProcessStartInfo(IEnumerable`1 sources, IDictionary`2 environmentVariables, TestRunnerConnectionInfo connectionInfo)
2018-11-14T09:34:25.4505025Z at Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Client.ProxyOperationManager.SetupChannel(IEnumerable`1 sources)
2018-11-14T09:34:25.4505077Z at Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Client.ProxyExecutionManager.StartTestRun(TestRunCriteria testRunCriteria, ITestRunEventsHandler eventHandler)
2018-11-14T09:34:25.6678123Z M i c r o s o f t ( R ) C o v e r a g e C o l l e c t i o n T o o l V e r s i o n 1 5 . 0 . 3 0 3 1 9 . 0
2018-11-14T09:34:25.6678286Z
2018-11-14T09:34:25.6678334Z
2018-11-14T09:34:25.6678492Z C o p y r i g h t ( c ) M i c r o s o f t C o r p o r a t i o n . A l l r i g h t s r e s e r v e d .
2018-11-14T09:34:25.6678566Z
2018-11-14T09:34:25.6678623Z
2018-11-14T09:34:25.6678664Z
2018-11-14T09:34:25.6678700Z
2018-11-14T09:34:26.8351769Z M i c r o s o f t ( R ) C o v e r a g e C o l l e c t i o n T o o l V e r s i o n 1 5 . 0 . 3 0 3 1 9 . 0
2018-11-14T09:34:26.8351940Z
2018-11-14T09:34:26.8352006Z
2018-11-14T09:34:26.8352092Z C o p y r i g h t ( c ) M i c r o s o f t C o r p o r a t i o n . A l l r i g h t s r e s e r v e d .
2018-11-14T09:34:26.8352125Z
2018-11-14T09:34:26.8352155Z
2018-11-14T09:34:26.8352199Z
2018-11-14T09:34:26.8352227Z
2018-11-14T09:34:26.8788931Z 2.3838
2018-11-14T09:34:26.8898822Z System.IO.FileNotFoundException: Unable to find tests for D:\a\1\s\ExtensionMethods.Tests\bin\Debug\netcoreapp2.1\Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.dll. Make sure test project has a nuget reference of package "Microsoft.NET.Test.Sdk" and framework version settings are appropriate. Rerun with /diag option to diagnose further.
2018-11-14T09:34:26.8899122Z at Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Hosting.DotnetTestHostManager.GetTestHostProcessStartInfo(IEnumerable`1 sources, IDictionary`2 environmentVariables, TestRunnerConnectionInfo connectionInfo)
2018-11-14T09:34:26.8899942Z at Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Client.ProxyOperationManager.SetupChannel(IEnumerable`1 sources)
2018-11-14T09:34:26.8900007Z at Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Client.ProxyExecutionManager.StartTestRun(TestRunCriteria testRunCriteria, ITestRunEventsHandler eventHandler)
2018-11-14T09:34:26.9247283Z M i c r o s o f t ( R ) C o v e r a g e C o l l e c t i o n T o o l V e r s i o n 1 5 . 0 . 3 0 3 1 9 . 0
2018-11-14T09:34:26.9247370Z
2018-11-14T09:34:26.9247428Z
2018-11-14T09:34:26.9247520Z C o p y r i g h t ( c ) M i c r o s o f t C o r p o r a t i o n . A l l r i g h t s r e s e r v e d .
2018-11-14T09:34:26.9247570Z
2018-11-14T09:34:26.9247619Z
2018-11-14T09:34:26.9247650Z
2018-11-14T09:34:26.9247681Z
2018-11-14T09:34:27.4568128Z M i c r o s o f t ( R ) C o v e r a g e C o l l e c t i o n T o o l V e r s i o n 1 5 . 0 . 3 0 3 1 9 . 0
2018-11-14T09:34:27.4568259Z
2018-11-14T09:34:27.4568335Z
2018-11-14T09:34:27.4568442Z C o p y r i g h t ( c ) M i c r o s o f t C o r p o r a t i o n . A l l r i g h t s r e s e r v e d .
2018-11-14T09:34:27.4568504Z
2018-11-14T09:34:27.4568543Z
2018-11-14T09:34:27.4568580Z
2018-11-14T09:34:27.4568631Z
2018-11-14T09:34:27.5016363Z 3.0114
2018-11-14T09:34:33.4517174Z M i c r o s o f t ( R ) C o v e r a g e C o l l e c t i o n T o o l V e r s i o n 1 5 . 0 . 3 0 3 1 9 . 0
2018-11-14T09:34:33.4517363Z
2018-11-14T09:34:33.4517409Z
2018-11-14T09:34:33.4517517Z C o p y r i g h t ( c ) M i c r o s o f t C o r p o r a t i o n . A l l r i g h t s r e s e r v e d .
2018-11-14T09:34:33.4517603Z
2018-11-14T09:34:33.4517641Z
2018-11-14T09:34:33.4517678Z
2018-11-14T09:34:33.4517715Z
2018-11-14T09:34:33.7048135Z Passed Timestamp_DateTime_CurrentDateTime_FormatAndValuesMatch
2018-11-14T09:34:33.7048569Z Passed ToJson_Object_ReturnsStringRepresentation
2018-11-14T09:34:33.7048660Z Passed ToJsonString_Object_ReturnsStringRepresentationIncludingObjectType
2018-11-14T09:34:33.7049036Z Passed IsNullOrEmpty_String_EmptyAndNullValues
2018-11-14T09:34:33.7049135Z Passed IsNullOrEmpty_String_NonEmptyOrNullValues
2018-11-14T09:34:33.7049190Z Passed Parse_String_ValidTypeParses_CorrectTypes
2018-11-14T09:34:33.7049257Z Passed Parse_String_ValidTypeParses_DefaultTypes
2018-11-14T09:34:33.7049297Z Passed FromJson_String_ValidObjects
2018-11-14T09:34:33.7049338Z Passed FromJson_String_InvalidObjects
2018-11-14T09:34:33.7049402Z Passed IsValidEmailAddress_String_ValidEmailAddresses_ReturnTrue
2018-11-14T09:34:33.7049465Z Passed IsValidEmailAddress_String_InvalidEmailAddresses_ReturnFalse
2018-11-14T09:34:35.8172642Z Results File: D:\a\1\s\TestResults\VssAdministrator_factoryvm-az552_2018-11-14_09_34_33.trx
2018-11-14T09:34:35.8203749Z
2018-11-14T09:34:35.8210373Z Attachments:
2018-11-14T09:34:35.8210758Z D:\a\1\s\TestResults\6c92c0b5-2e35-48af-867a-2a4575306a68\VssAdministrator_factoryvm-az552 2018-11-14 09_34_22.coverage
2018-11-14T09:34:35.8211079Z
2018-11-14T09:34:35.8211397Z Total tests: Unknown. Passed: 11. Failed: 0. Skipped: 0.
2018-11-14T09:34:35.8211670Z Test Run Aborted.
2018-11-14T09:34:35.8211939Z Test execution time: 10.7395 Seconds
2018-11-14T09:34:36.0240507Z ##[warning]Vstest failed with error. Check logs for failures. There might be failed tests.
2018-11-14T09:34:36.0769776Z ##[error]Error: C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Common7\IDE\CommonExtensions\Microsoft\TestWindow\vstest.console.exe failed with return code: 1
2018-11-14T09:34:36.3170630Z ##[error]VsTest task failed.
2018-11-14T09:34:36.3566464Z ##[section]Async Command Start: Publish test results
2018-11-14T09:34:36.4181634Z Publishing test results to test run '6'
2018-11-14T09:34:36.4181725Z Test results remaining: 11. Test run id: 6
2018-11-14T09:34:36.9962474Z Published Test Run : https://dev.azure.com/TrustmarqueIT/Test_2018-10-30/_TestManagement/Runs#runId=6&_a=runCharts
2018-11-14T09:34:36.9971952Z ##[section]Async Command End: Publish test results
2018-11-14T09:34:36.9972803Z ##[section]Finishing: VS Unit Test
I have solved my problem by revising my filter to find test assemblies. When i was messing around with my test step, accidentally set the filter to "/**/UnitTests.dll" and i did not realise that it was also matching UnitTests.dll in the "obj" folder and that folder does not have .deps.json files. From the logs i noticed that it was running tests twice (once for each matching dll) so then i ignored the obj folder by reverting back my filter to exclude obj folder. So i guess two things to take care in such cases,
You must have "Microsoft.NET.Test.Sdk" installed on your test
project and
Your filter does not include or exclude any unwanted
dll(s) which you (don't want / want to) be there
If anyone gets this after upgrading to .Net 5.0 it now creates a reference assembly in the ref folder, with the same name as the output assembly. You need to ignore this in your search criteria:
!**/ref/**
Thanks #Gurpreet for prompting me to document my solution.
It's been quite a while, so my memory of the steps is a bit shaky, but I believe that my mistake was thinking that, on the first screen after selecting a source repository, I assumed the templates listed were all that was available and that Empty job was the same as the YAML template. I'd incorrectly assumed that Empty job meant that I'd have to edit the YAML myself.
Jonathan Twite gave me some great pointers but I didn't quite grasp what he was suggesting at the time.
The Solution
Anyway, the solution was to select either Empty job or scroll to the bottom and select Empty pipeline, why they're referred to by different names is a mystery.
After selecting the empty template, the next screen provides you with a default Agent job. Clicking the plus, you can add a variety of different tasks. This was part of my original mistake, I confused the tasks with the templates on the previous screen.
I added the .NET Core task.
I changed the Display name and the Command, as well as making sure that the Version was correct. Interestingly, the Command has a number of interesting options, three of which that I found useful are:
restore
build
test
So, rather than adding a specific Test task, you add the .NET Core task and configure it to do the test bit. This was a bit confusing for me, I didn't realise that the .NET Core task was capable of doing the testing as well.
In my case, I also started testing the ability to deploy NuGet packages, but that's a whole other can of worms.
I hope that this has helped, and wish you all good luck with your projects.
Kaine
I got the same exception when I tried to run my unit test project from azure devops:
##[error]Unable to find C:\Users\Viktor\agent_work\2\s\Source\API\VCC_uTests\obj\Release\netcoreapp3.1\VCC_uTests.deps.json. Make sure test project has a nuget reference of package "Microsoft.NET.Test.Sdk".
The issue was that there was 2 VCC.uTests.dll in my $(System.DefaultWorkingDirectory) folder,that vstest started based on my run unit tests pipe line step.
I could recognize it from the step log:
vstest.console.exe
"C:\Users\Viktor\agent_work\2\s\Source\API\VCC.uTests\bin\Release\netcoreapp3.1\VCC_uTests.dll"
"C:\Users\Viktor\agent_work\2\s\Source\API\VCC.uTests\obj\Release\netcoreapp3.1\VCC_uTests.dll"
Therefore, I had to modify my run test step search pattern:
**\bin$(BuildConfiguration)**VCC_uTests.dll
This solved my issue and the step ran successfully in my build pipeline.

Powershell Subinacl.exe Double-Spaced Output, inability to capture summary information (statistics)

I try to run the following script on a remote machine, from the first line I get the normal output, "Command was successful" or something like that. For the second one it seems that its working, but the output its spaced and its not full, there are like 4 lines of output missing.
# This works as expected.
$output = Invoke-Command -ComputerName ServerName -ScriptBlock {auditpol /set /subcategory:"Registry" /success:enable /failure:enable}
# This creates double-spaced output and is missing the last 3 output lines.
$output = Invoke-Command -ComputerName ServerName -ScriptBlock {Subinacl.exe /verbose=1 /keyreg "HKEY_LOCAL_MACHINE\SYSTEM\Path" /sallowdeny="everyone"=SCD}
I want this output for the second code line:
SYSTEM\Path : delete Audit ACE 0 \everyone
SYSTEM\Path : new ace for \everyone
HKEY_LOCAL_MACHINE\SYSTEM\Path : 2 change(s)
Elapsed Time: 00 00:00:00
Done: 1, Modified 1, Failed 0, Syntax errors 0
Last Done : HKEY_LOCAL_MACHINE\SYSTEM\Path
But instead I get:
S Y S T E M \ P a t h : d e l e t e A u d i t A C E 0 \ e v e r y o n e
S Y S T E M \ P a t h : n e w a c e f o r \ e v e r y o n e
H K E Y _ L O C A L _ M A C H I N E \ S Y S T E M \ P a t h : 2 c h a n g e ( s )
Without the last 3 lines, which I want to see. I tried change the Output Encoding to Unicode or UTF8 but are not working. Any other solutions?
There are two unrelated problems:
(a) subinacl.exe produces UTF-16LE-encoded output.
(b) Its on-by-default /statistic option seems to write directly to the console, bypassing stdout, and therefore cannot be captured - or at least not easily; do tell us if you know how.
Therefore, the last block of lines containing statistics (summary information), which starts with Elapsed: ..., always prints to the console.
Related question subinacl get full output was prompted by the same problem.
(a), as stated, can be remedied by telling PowerShell what character encoding to expect when capturing output from external programs, via [Console]::OutputEncoding
(b) cannot be remedied if you do want to capture the statistics lines too; the next best thing is to suppress statistics output altogether with /nostatistic, which at least doesn't produce unwanted console output (but, obviously, you won't have the information at all).
Putting it all together:
$output = Invoke-Command -ComputerName ServerName -ScriptBlock {
# Tell PowerShell what character encoding to expect in subinacl's output.
[Console]::OutputEncoding = [Text.Encoding]::Unicode # UTF-16LE
# Note the addition of /nostatistic to suppress the direct-to-console summary info.
Subinacl.exe /nostatistic /verbose=1 /keyreg "HKEY_LOCAL_MACHINE\SYSTEM\Path" /sallowdeny="everyone"=SCD
}
Note: Normally, you'd restore the previous value of [Console]::OutputEncoding afterward, but since the session on the remote computer in which the script block runs ends right after, it isn't necessary here.
These tools don't often return proper object, hence your string output on the later.
You can work to handle that output differently than it's default and / or parse the string return to get the format you are after. Using the string cmdlets...
Get-Command -Name '*string*' | Format-Table -AutoSize
CommandType Name Version Source
----------- ---- ------- ------
Function ConvertFrom-SddlString 3.1.0.0 Microsoft.PowerShell.Utility
...
Function Format-String 1.3.6 PowerShellCookbook
...
Cmdlet ConvertFrom-String 3.1.0.0 Microsoft.PowerShell.Utility
Cmdlet ConvertFrom-StringData 3.1.0.0 Microsoft.PowerShell.Utility
Cmdlet Convert-String 3.1.0.0 Microsoft.PowerShell.Utility
...
Cmdlet Out-String 3.1.0.0 Microsoft.PowerShell.Utility
...
Since Subinacl is used to display or modify Access ControlEntries (ACEs) for file and folder Permissions, Ownership and Domain, whcih is the same thing that the native cmdlets...
Get-Command -Name '*acl*' | Format-Table -AutoSize
CommandType Name Version Source
----------- ---- ------- ------
...
Cmdlet Get-Acl 3.0.0.0 Microsoft.PowerShell.Security
...
Cmdlet Set-Acl 3.0.0.0 Microsoft.PowerShell.Security
...
Application cacls.exe 10.0.17134.1 C:\WINDOWS\system32\cacls.exe
Application icacls.exe 10.0.17134.1 C:\WINDOWS\system32\icacls.exe
...
... provide. Why not just use them instead as they return proper objects vs Subinacl?
As for encoding.
Are are you saying, you tried this answer, from this discussion and it did nto work for you?
Double spacing of output from SubInACL called from PowerShell
#set output encoding to unicode
[Console]::OutputEncoding = [Text.Encoding]::Unicode
$func_filePath = "G:\test\func.txt"
#use subinacl
[string]$SubInACLCommand = #"
subinacl.exe /file "$func_filePath" /setowner="hostname\Administrators"
"#
Invoke-Expression $SubInACLCommand
#revert output encoding back to default
[Console]::OutputEncoding = [Text.Encoding]::Default
Update for OP
Using RegEx to clean this up on your side. Remove double spaces and empty lines from a string.
('S Y S T E M \ P a t h : d e l e t e A u d i t A C E 0 \ e v e r y o n e
S Y S T E M \ P a t h : n e w a c e f o r \ e v e r y o n e
H K E Y _ L O C A L _ M A C H I N E \ S Y S T E M \ P a t h : 2 c h a n g e ( s )').replace(' ','|').Replace(' ','').Replace('|',' ') -creplace('(?m)^\s*\r?\n','')
# Results
SYSTEM\Path : delete Audit ACE 0 \everyone
SYSTEM\Path : new ace for \everyone
HKEY_LOCAL_MACHINE\SYSTEM\Path : 2 change(s)
Update for OP
Try this on your machine and see if the full results are actually coming back as you'd expect.
$SubinaclResults = Invoke-Command -ComputerName ServerName -ScriptBlock {Subinacl.exe /verbose=1 /keyreg "HKEY_LOCAL_MACHINE\SYSTEM\Path" /sallowdeny="everyone"=SCD}
$SubinaclResults
If the above does to bring back the full result set. My final suggestion would be to output this as a temp file on the remote machine and read it back to your workstation with Get-Content.

Gnuplot prints differently when piping

I have file like this:
662.0,,9624
663.0,,9625
771.0,9624,
772.0,,9626
912.0,9625,
913.0,,9627
1083.0,9626,
1083.0,,9628
1174.0,9627,
1175.0,,9629
And when I use gnuplit console, it prints as expected:
set datafile separator ',';
plot 'data-exchange.log' using 1:2 pt 7 ps 2, '' using 1:3 pt 7 ps 2;
However, when I do the same when piping, it doesn't plot as expected:
cat data-exchange.log | gnuplot -p -e 'set datafile separator ","; plot "<cat" using 1:2 pt 7 ps 2, "" using 1:3 pt 7 ps 2;'
Not sure why is that...

How do I run a PowerShell script inside of MSBuild?

Maybe there's something wrong with my installation, I'm not quite sure.
I've spent about two days looking and trying different solutions. It's obvious that people have done it, but their examples aren't working for me yet.
I am going to eventually want to run an external PowerShell script, but I will be happy to get this working first:
psTest.build:
<?xml version="1.0" encoding="utf-8" ?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0" DefaultTargets="Test">
<Target Name="Test">
<Exec Command='powershell -Command "Write-Host "Hello, world!""' />
</Target>
</Project>
Running the build script:
PS D:\> msbuild .\psTest.build /Target:test
Microsoft (R) Build Engine version 12.0.30723.0
[Microsoft .NET Framework, version 4.0.30319.18444]
Copyright (C) Microsoft Corporation. All rights reserved.
Build started 10/16/2014 3:20:31 PM.
Project "D:\psTest.build" on node 1 (test target(s)).
Test:
powershell -Command "Write-Host "Hello, world!""
I n t e r n a l W i n d o w s P o w e r S h e l l e r r o r . L o a d i n g m a n a g e d W i n d o w s
P o w e r S h e l l f a i l e d w i t h e r r o r 8 0 0 7 0 0 0 2 .
D:\psTest.build(5,5): error MSB3073: The command "powershell -Command "Write-Host "Hello, world!"" exited with c
ode -65536.
Done Building Project "D:\psTest.build" (test target(s)) -- FAILED.
Build FAILED.
"D:\psTest.build" (test target) (1) ->
(Test target) ->
D:\psTest.build(5,5): error MSB3073: The command "powershell -Command "Write-Host "Hello, world!"" exited with
code -65536.
0 Warning(s)
1 Error(s)
Time Elapsed 00:00:01.10
I've also tried using using MSBuild Extension Pack, but I still end up getting the same error.
So, it feels like there is a major disconnect, which once that's out of the way, everything else should just fit.