How to Export the Task Scheduler jobs using Powershell - powershell

I am trying to export the Task Scheduler jobs under Task Scheduler Library using Power shell.
But when i try to run the script it displays all the tasks which are in my machine, i don't want to export all those to a file,just need the tasks which are under Task Scheduler Library.
"ScheduledTasks"
schtasks.exe /query /V /FO CSV | ConvertFrom-Csv
Output
HostName : XXXXXXXXX
TaskName : \Mozilla\Firefox Default Browser Agent
308046B0AF4A39CB
Next Run Time : 25-06-2021 18:03:40
Status : Ready
Logon Mode : Interactive only
Last Run Time : 24-06-2021 18:03:41
Last Result : 0
Author : Mozilla
Task To Run : C:\Program Files\Mozilla
Firefox\default-browser-agent.exe
do-task 308046B0AF4A39CB""
Start In : N/A
Comment : The Default Browser Agent task checks
when the default changes from Firefox
to another browser. If the change
happens under suspicious circumstances,
it will prompt users to change back to
Firefox no more than two times. This
task is installed automatic
Scheduled Task State : Enabled
Idle Time : Disabled
Power Management :
Run As User : XXXX
Delete Task If Not Rescheduled : Disabled
Stop Task If Runs X Hours and X Mins : 00:35:00
Schedule : Scheduling data is not available in
this format.
Schedule Type : Daily
Start Time : 18:03:40
Start Date : 21-06-2021
End Date : N/A
Days : Every 1 day(s)
Months : N/A
Repeat: Every : Disabled
Repeat: Until: Time : Disabled
Repeat: Until: Duration : Disabled
Repeat: Stop If Still Running : Disabled
Thanks In Advance

Related

Facing issue while exporting the report from Tally using command line

We want some functionality where we can export the report using the command line so that we can execute that command through some batch file and export reports on a daily schedule time.
Issue:
For this ,we are trying some code snippet from Tally developer "Help --> TDL Sample"(this is complete path of sample code C:\Program Files\TallyPrimeDeveloper\Samples\Whats New\Rel 3.x\Rel 3.0\Programmable Configurations\Export Report Trial Balance.txt).
The following code sample works properly on button click and we are successfully exported the report in our folder
"""[Button: TSPL Smp Export PC]
Key : Ctrl + E
Action : Call : TSPL Smp PC Export Report
Title : "Export Report"
;; Function Definition begins
[Function: TSPL Smp PC Export Report]
Local Formula : SysDate : $$SysInfo:SystemDate
00 : SET : SVExportLocation : "."
10 : SET : SVExportFormat : $$SysName:PDF
20 : SET : SVPrintFileName : "List of Ledgers as onShri_1234 " + $$String:#SysDate + ".PDF"
30 : SET : SVPrintFileName : $$MakeExportName:##SVPrintFileName:##SVExportFormat
40 : EXPORT REPORT : . : TRUE
50 : Msg Box : "TestMsg2" :"We need to download this report through command line" """
But we are facing issue when we are trying to call this same function through command line
Command line is : "C:\Program Files\TallyPrime\tally.exe" /Load:10000 /Action:Call:TSPLSmpPCExportReport .
As per our observations and debugging, the above function gets successfully called through the command line because when I am executing it through the command line,I am getting a "TestMsg2" popup but the file is not getting exported. It seems there is some issue only in file export through the command line, not in function calling through the command line.
I have a solution that works, but without TDL and uses C# or Python
Using C# you can create console app, and you can use that in command line
using Python, you can create script and run from command line
Refer this video for python

Powershell forms application different output in console and ISE

I created complex forms application in powersheel and it is running correctly in Powershell ISE and powershell console too, but there is little difference in behaviour:
when I run application by double clicking in windows explorer, powershell console opens, but there is toooo much of "debug" data from creating all form controls(checkboxes, labels, buttons...). It takes too long to start and it looks like this:
TextImageRelation : Overlay UseMnemonic : True UseCompatibleTextRendering : True UseVisualStyleBackColor : True AccessibilityObject : ControlAccessibleObject: Owner = System.Windows.Forms.CheckBox, CheckState: 0 AccessibleDefaultActionDescription : AccessibleDescription : AccessibleName : AccessibleRole : Default AllowDrop : False Anchor : Top, Left AutoScrollOffset : {X=0,Y=0} LayoutEngine : System.Windows.Forms.Layout.DefaultLayout BackgroundImage : BackgroundImageLayout : Tile BindingContext : {} Bottom : 208 Bounds : {X=165,Y=190,Width=96,Height=18} CanFocus : False CanSelect : False Capture : False CausesValidation : True ClientRectangle : {X=0,Y=0,Width=96,Height=18}
This output is not in powershell ISE(there is none) - there application starts immediately.
I was not able to resolve this issue and I would like to remove debug output when run from console, if it is possible - to speed up script start.
Script source code is same as examples on internet, for example like this:
https://learn.microsoft.com/en-us/powershell/scripting/samples/creating-a-custom-input-box?view=powershell-7
I tried yo add | Out-Null to some controls/rows - which i saw in logs, but it did not help.
Also I tried to identify which command is making output by manually adding some controls to console, but none generated that output.
I tried to create ISE profile and load it in script run from console, but it did not help, because created profile file was empty.
If I run new console window like this:
start-process powershell -argumentlist "-noexit", "-noprofile" and run script from that, it works without logs.
But if I run script like this:
start-process powershell -argumentlist "-noexit", "-noprofile", "-command $path"
it outputs logs again.
Any ideas how to do it? What should I check/modify.
Thank you.
solved: problem was a space in script name as I mentioned in comment.

Extracting values from AnalyzeComponentStore?

Hello everyone and thanks in advance for the possible answers.
Where I work we have different WS2016 virtual machines and we read that the updates could be a pain due to the very long time they could take and we can't stay a lot with the services down (we have several virtual machines to update soon).
In the same thread we read an advice: cleaning the WinSXS folder could drastically reduce this time.
WS2016 already has this scheduled but it has got a 1 hour timeout so if it takes more than that the process gets killed.
The solution is creating the schedule manually so we made a script for this that checks the current date and the last update date and, if the difference is more than 30 days, it runs the command:
dism.exe /Online /Cleanup-Image /AnalyzeComponentStore
and then the command:
dism.exe /Online /Cleanup-Image /StartComponentCleanup
Now the real question...One of the results of AnalyzeComponentStore is:
Component Store Cleanup Recommended
And the answer could be Yes or No
Is there a way to check if this value is "Yes" (so launch the StartComponentCleanup) or "No" (so exit from the script)?
Thanks again!
#Doug Maurer...this is the result of the AnalyzeComponentStore
PS C:> dism.exe /Online /Cleanup-Image /AnalyzeComponentStore
Deployment Image Servicing and Management tool
Version: 10.0.14393.3750
Image Version: 10.0.14393.3241
[===========================99.7%========================= ]
Component Store (WinSxS) information:
Windows Explorer Reported Size of Component Store : 8.08 GB
Actual Size of Component Store : 7.94 GB
Shared with Windows : 6.12 GB
Backups and Disabled Features : 1.49 GB
Cache and Temporary Data : 323.47 MB
Date of Last Cleanup : 2016-09-12 13:40:35
Number of Reclaimable Packages : 0
Component Store Cleanup Recommended : Yes
The operation completed successfully.
PS C:>
There are several ways to achieve this, I will list two and you can choose the one you like better. Others may offer alternative approaches.
First using Select-String - simply pipe the output into select string
$output = #'
Deployment Image Servicing and Management tool Version: 10.0.14393.3750
Image Version: 10.0.14393.3241
[===========================99.7%========================= ]
Component Store (WinSxS) information:
Windows Explorer Reported Size of Component Store : 8.08 GB
Actual Size of Component Store : 7.94 GB
Shared with Windows : 6.12 GB
Backups and Disabled Features : 1.49 GB
Cache and Temporary Data : 323.47 MB
Date of Last Cleanup : 2016-09-12 13:40:35
Number of Reclaimable Packages : 0
Component Store Cleanup Recommended : Yes
The operation completed successfully.
'#
$output | Select-String "Component Store Cleanup Recommended : (\w*)" | foreach {$_.matches.groups[1].value}
I used the outvariable paremeter of Foreach, you could also just assign normally
$cleanup = $output | Select-String "Component Store Cleanup Recommended : (\w*)" | foreach {$_.matches.groups[1].value}
Second suggestion is to use -Match
$cleanup = if($output -match "Component Store Cleanup Recommended : (\w*)"){$matches[1]}
Both will end up setting $cleanup to the yes/no value you're after.
Get-Variable cleanup
Name Value
---- -----
cleanup {Yes}
Now you can simply check if it's yes and run the cleanup if so.
if($cleanup -eq 'yes'){"run cleanup code"}

Windows Defender/Update issues when running inside Windows Docker Container Windows Server 2016

I've created a ASP.NET Web API that retrieves a file as a stream content, saves to disk and scans the file using Windows defender (MpCmdRun.exe). When running the API locally on my computer, everything is fine. However, I want to host this API in the cloud (Azure), as the rest of my applications are there. I decided to put this Web API inside a docker container, and then publish it to Azure. However, when running Windows Defender inside the Docker Container, I get the following error:
Running:
C:\Program Files\Windows Defender>MpCmdRun.exe -Scan -ScanType 3 -File ThirdPartyNotices.txt
Returns:
Scan starting...
CmdTool: Failed with hr = 0x8050800C. Check C:\Users\ContainerAdministrator\AppData\Local\Temp\MpCmdRun.log for more information
The log file doesn't give much more information.
MpCmdRun: Command Line: MpCmdRun.exe -Scan -ScanType 3 -File
ThirdPartyNotices.txt
Start Time: ?Sun ?Dec ?03 ?2017 23:53:16
Starting RunCommandScan.
INFO: ScheduleJob is not set. Skipping signature update.
Scanning path as file: ThirdPartyNotices.txt.
Start: MpScan(MP_FEATURE_SUPPORTED, dwOptions=16385, path
ThirdPartyNotices.txt, DisableRemediation = 0, BootSectorScan
= 0, Timeout in days = 1)
MpScan() started
Warning: MpScan() encounter errror. hr = 0x8050800c
MpScan() was completed
ERROR: MpScan(dwOptions=16385) Completion Failed 8050800C
MpCmdRun: End Time: ?Sun ?Dec ?03 ?2017 23:53:16
Dockerfile:
FROM microsoft/aspnet
COPY ./bin/Release/PublishOutput/ /inetpub/wwwroot
#So I can write sent file to disk in container
RUN powershell New-Item c:\inetpub\wwwroot\temp_files -type directory
RUN icacls c:\inetpub\wwwroot\temp_files /grant IIS_IUSRS:F
#Without this Windows Update is disabled
RUN powershell Set-Service wuauserv -StartupType "Automatic"
#Without this Windows defender is disabled
RUN reg add "HKLM\SYSTEM\CurrentControlSet\services\WinDefend" /v Start /t REG_DWORD /d 2 /f
#Tried running these, as well as Update-MpSignature in powershell, to no success.
#RUN ["c:\\Program Files\\Windows Defender\\MpCmdRun.exe", "-RemoveDefinitions", "-All"]
#RUN ["c:\\Program Files\\Windows Defender\\MpCmdRun.exe", "-SignatureUpdate"]
When inside the docker container (docker exec -it test powershell). Running Get-MpComputerStatus in powershell returns the following:
AMEngineVersion : 1.1.14306.0
AMProductVersion : 4.10.14393.1794
AMServiceEnabled : True
AMServiceVersion : 4.10.14393.1794
AntispywareEnabled : True
AntispywareSignatureAge : 0
AntispywareSignatureLastUpdated : 12/3/2017 8:15:49 PM
AntispywareSignatureVersion : 1.257.1327.0
AntivirusEnabled : True
AntivirusSignatureAge : 0
AntivirusSignatureLastUpdated : 12/3/2017 8:15:51 PM
AntivirusSignatureVersion : 1.257.1327.0
BehaviorMonitorEnabled : False
ComputerState : 0
FullScanAge : 4294967295
FullScanEndTime :
FullScanStartTime :
IoavProtectionEnabled : False
LastFullScanSource : 0
LastQuickScanSource : 0
NISEnabled : False
NISEngineVersion : 0.0.0.0
NISSignatureAge : 4294967295
NISSignatureLastUpdated :
NISSignatureVersion : 0.0.0.0
OnAccessProtectionEnabled : False
QuickScanAge : 4294967295
QuickScanEndTime :
QuickScanStartTime :
RealTimeProtectionEnabled : False
RealTimeScanDirection : 0
PSComputerName :
Here I'm concerned about the NIS settings being 0.0.0.0.
When trying to update the Windows Defender signatures with
Update-MpSignature
Returns:
Update-MpSignature : Virus and spyware definitions update was completed with
errors.
At line:1 char:1
+ Update-MpSignature
+ ~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified:
(MSFT_MpSignature:ROOT\Microsoft\...SFT_MpSignature) [Update-MpSignature],
CimException
+ FullyQualifiedErrorId : HRESULT 0x80070643,Update-MpSignature
I'm not really able to RDP into the docker container (as far as I can tell it's not possible with the microsoft/aspnet image). This means I have to do everything in the command prompt/powershell, and I'm still quite new to that.
This might not be enough information, or even the right information to track this problem, but I've been stuck with this for way to long now. If anyone can give me some pointers on what to look for/how to proceed with locating/fixing these issues that'd be awesome. Thank you in advance!
run this as admin to completely disable windows defender
Set-MpPreference -DisableRealtimeMonitoring $true
Windows Server 2016 by default uses process isolation (not HyperV) and antivirus already scans your files on unlabeled disk and volume.

Powershell 2 ISE, not stopping on breakpoints in imported modules

When we set breakpoints within a Module we've imported the debugger ignores the breakpoint. Has anybody else seen this behaviour?
This is driving me nuts, we use PowerShell Modules extensively.
The thing that's really weird is I can see the breakpoint if I run get-psbreakpoint
PS H:\Projects\Powershell> get-psbreakpoint | format-list -force
Id : 0
Script : H:\projects\Powershell\Shared\SFTP\SFTP.psm1
Line : 25
Column : 0
Enabled : True
HitCount : 0
Action :
Id : 1
Script : H:\projects\Powershell\Trading\CPPIB\scripts\CppibBorrowReturns.ps1
Line : 12
Column : 0
Enabled : True
HitCount : 1
Action :
EDIT: Seems to work if I delete the psd1 (Manifest file)
Debugging modules can be tough. One way I have been able to do it is load both the module and the code that calls the function you are debugging. In the code that calls a function in the module, place a break point. Then when it its the call to the function in the module, step in to it. Once it steps into the module you should be able to hit F5 again to hit your break point in the module.
Sorry if that is not as clear as it should be, still reeling from day light savings on a Monday.