Powershell forms application different output in console and ISE - forms

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.

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 command for Create OSDisk and DataDisk snapshot

I am writing powershell script for capture OS-disk snapshot for Azure VM but While configuring snapshot I am getting some error.
I am using below command to create snapshot.I am using managed disk.
New-AzSnapshotConfig -OsType Linux -CreateOption copy -SourceUri Microsoft.Azure.Management.Compute.Models.OSDisk -DiskSizeGB 40 -Location 'East US'
Not sure how to do that. If anyone could you please help me to solve this issue.
OUTPUT
WARNING: Breaking changes in the cmdlet 'New-AzSnapshotConfig' :
WARNING: - "The output type 'Microsoft.Azure.Commands.Compute.Automation.Models.PSSnapshot' is changing"
- The following properties in the output type are being deprecated :
'EncryptionSettings'
- The following properties are being added to the output type :
'EncryptionSettingsCollection' 'HyperVGeneration'
WARNING: NOTE : Go to https://aka.ms/azps-changewarnings for steps to suppress this breaking change warning, and other information on breaking changes in
Azure PowerShell.
ResourceGroupName :
ManagedBy :
Sku :
TimeCreated :
OsType : Linux
HyperVGeneration :
CreationData : Microsoft.Azure.Management.Compute.Models.CreationData
DiskSizeGB : 40
EncryptionSettingsCollection :
ProvisioningState :
Id :
Name :
Type :
Location : East US
Tags :
EncryptionSettings :
Thanks
Rohit
Did you go to the link provided in the warning note? It says very clearly:
How do I get rid of the warnings?
To suppress these warning messages, set the environment variable 'SuppressAzurePowerShellBreakingChangeWarnings' to 'true'.
Set-Item Env:\SuppressAzurePowerShellBreakingChangeWarnings "true"
The error message is trying to tell you that the property EncryptionSettings you see in the output you provided will soon be changing from a single property of some type, to a collection property that you would have to iterate over to find all of the settings. They are trying to let you know that if you are capturing the output of New-AzSnapshotConfig to a variable and then calling $variable.EncryptionSettings, your code will work for now, but in the next breaking change release, that call will stop working. Most likely, since that property will no longer exist, the result of that call will simply be a $NULL.
So suppress this warning at your own risk because Microsoft is trying to do you a service here and let you know that if you don't do something about this your code could break. But if you are certain that you never reference property then you have nothing to worry about.

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.

Installing an exe with Powershell DSC Package resource gets return code 1619

I'm trying to use Powershell DSC's Package resource to install an exe... Perforce's P4V to be specific. Here's my code:
Configuration PerforceMachine
{
Node "SERVERNAME"
{
Package P4V
{
Ensure = "Present"
Name = "Perforce Visual Components"
Path = "\\nas\share\p4vinst64.exe"
ProductId = ''
Arguments = "/S /V/qn" # args for silent mode
LogPath = "$env:ProgramData\p4v_install.log"
}
}
}
When running this, this is the error Powershell gives me:
PowerShell provider MSFT_PackageResource failed to execute Set-TargetResource functionality with error message: The return code 1619 was not expected. Configuration is likely not
correct
+ CategoryInfo : InvalidOperation: (:) [], CimException
+ FullyQualifiedErrorId : ProviderOperationExecutionFailure
+ PSComputerName : SERVERNAME
According to documentation, return code 1619 means the MSI package couldn't be opened. However, when I manually log in to the machine and run "\\nas\share\p4vinst64.exe /S /V/qn", the install works flawlessly.
Does anyone know why this is failing? Alternately, can anyone tell me how to troubleshoot this? I pasted all the error information I got from the terminal, my log file (p4v_install.log) is a 0 byte file, and there are no events in the event viewer. I don't know how to troubleshoot it any further!
EDIT: I should note that I also tried using the File resource to copy the file locally, and then install it from there. Sadly, that met with the same result.
Daniel over at the Powershell.org forums was able to figure this out for me.
The P4V InstallShield setup wrapper puts the MSI file into wrong path if you execute as LocalSystem.
I’ve managed to develop a Configuration that works, see below. The key is the /b switch here which puts the MSI file into a defined location. I’ve added ALLUSERS=1 to get the shortcuts visible to all users and REBOOT=ReallySuppress to avoid a sudden restart (which will happen otherwise).
Configuration PerforceMachine
{
Package P4V
{
Ensure = "Present"
Name = "Perforce Visual Components"
Path = "C:\My\p4vinst64.exe"
ProductId = ''
Arguments = '/b"C:\Windows\Temp\PerforceClient" /S /V"/qn ALLUSERS=1 REBOOT=ReallySuppress"' # args for silent mode
}
}
Well, what happens here is that the package gets installed (not tested with p4vinst64.exe yet! So, not sure why it says pack cannot be opened as the error) but since you did not specify a ProductID value, the verification at the end of install fails. That is the error you are seeing. The Package resource is no good for installing .exe packages or even MSIs with no ProductID represented as a GUID.
You can use the WindowsProcess resource instead.

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.