Multiple PowerShell commands from BAT file.
Posted: 16 Dec 2020 04:50
Hello,
I want help to understand some things and to resolve some issues.
I am trying to run multiple PowerShell commands from a bat file. I have problem on output or with execution of some commands.
For Example
Question1
I have test.bat
The output give that file and i have one error on last PowerShell command >> PowerShell.exe -nologo -noprofile -ExecutionPolicy Bypass -Command "& {get-winevent -FilterHashTable @{logname="Application"; id="1001"}| ?{$_.providername -match "wininit"} | fl timecreated, message }" >> .\user-info.txt
I don't know why. Probably from character { and } but i don't know alternative method to bypass this.
image1 -https://imgur.com/f3s9GlP
Question2
If i change the output method from this to this
then the results is like this on Notepad++ [image2] , and this if because has many spaces charecters [image3].
image2 - https://imgur.com/heKUCDH
image3 - https://imgur.com/ebWxlFD
I want help to understand some things and to resolve some issues.
I am trying to run multiple PowerShell commands from a bat file. I have problem on output or with execution of some commands.
For Example
Question1
I have test.bat
Code: Select all
@echo off
echo. > .\user-info.txt
whoami >> .\user-info.txt
echo. >> .\user-info.txt
wmic /APPEND: ".\user-info.txt " USERACCOUNT get Caption,Name,PasswordRequired,Status
net user >> .\user-info.txt
echo. >> .\user-info.txt
::
echo === DISK INFORMATION === >> .\user-info.txt
PowerShell.exe -nologo -noprofile -ExecutionPolicy Bypass -Command "& {get-psdrive -psprovider filesystem }" >> .\user-info.txt
wmic /APPEND: ".\user-info.txt " diskdrive get Name,InterfaceType,MediaType,Model,Size,Status
echo. >> .\user-info.txt
::
echo === Top 10 CPU Processes === >> .\user-info.txt
echo ----------------------------------- >> .\user-info.txt
PowerShell.exe -nologo -noprofile -ExecutionPolicy Bypass -Command "& {Get-Process | Sort-Object -Property CPU | Select-Object -Last 10 }" >> .\user-info.txt
echo. >> .\user-info.txt
::
echo === Chkdsk Logs === >> .\user-info.txt
echo ----------------------------------- >> .\user-info.txt
PowerShell.exe -nologo -noprofile -ExecutionPolicy Bypass -Command "& {get-winevent -FilterHashTable @{logname="Application"; id="1001"}| ?{$_.providername -match "wininit"} | fl timecreated, message }" >> .\user-info.txt
echo. >> .\user-info.txt
I don't know why. Probably from character { and } but i don't know alternative method to bypass this.
image1 -https://imgur.com/f3s9GlP
Question2
If i change the output method from this
Code: Select all
>> .\user-info.txt
Code: Select all
Out-File '.\user-info.txt' -Append
then the results is like this on Notepad++ [image2] , and this if because has many spaces charecters [image3].
image2 - https://imgur.com/heKUCDH
image3 - https://imgur.com/ebWxlFD