Jump to content

Recommended Posts

Posted

Hi all,

I need to read a log file into an array, but the log file is encoded as $FO_UTF16_BE_NOBOM (2048) = Use Unicode UTF16 Big Endian (without BOM) per FileGetEncoding (it returns 2048).

I have searched how to convert these log files to UTF-8 and finally found a Powershell command. Since then I have been racking my brain trying to get the function to work. The command itself works from a Powerscript prompt:

C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -Command Get-Content C:\Logs\Myplayer_10-10-17-02-31.log | Set-Content -Encoding utf8 C:\Logs\Myplayer1.log

This is my sandbox;

#include <array.au3>
#include <File.au3>

Local $aArrayLogFile
Local $sLogDir = "C:\Logs\"
Local $sLogFile = "Myplayer_10-10-17-02-31.log"
Local $sConvertedLog = "ConvertedLog.log"
Local $sLogDirFile = $sLogDir&$sLogFile

RunWait("C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -Command Get-Content "&$sLogDirFile&" | Set-Content -Encoding utf8 "&$sConvertedLog,$sLogDir)

_FileReadToArray($sLogDirFile, $aArrayLogFile)
_ArrayDisplay($aArrayLogFile)

Also tried

RunWait("C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -Command Get-Content "&$sLogDirFile&" | Set-Content -Encoding utf8 "&$sConvertedLog,$sLogDir)

and

ShellExecuteWait("C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe"," -Command Get-Content "&$sLogDirFile&" | Set-Content -Encoding utf8 "&$sConvertedLog,$sLogDir)

Tried without -Command and a bunch of other parameters that were sprinkled throughout the internet from people trying to get this to work.

Thanks

Jibs

Posted

This one works for me :

RunWait("C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -Command Get-Content 'c:\SessionChange_20.06.2016 _ 12.53.11.log' | Set-Content -Encoding utf8 'c:\SessionChange_20.06.2016 _ 12.53.11222.log'")

I have done it with hard coded names for simplicity - using variables also works.

  • 2 years later...
Posted

I had to use the quotes as follows, otherwise the "Remove-AppxPackage" parameter is not recognized:

 

RunWait("C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -Command Get-AppxPackage ""*zunemusic* | Remove-AppxPackage"")

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...