Powershell & Windows Defender limitations - powershell

I'm trying to write a PowerShell script to automate some scanning activities using Windows Defender. I've noticed a limitation with the published code which I'm interested to know whether or not there is a workaround.
Is there any reason why when you run this:
Start-MpScan -ScanType CustomScan -ScanPath "C:\Files"
That the scan does not get added into the event viewer?
I need this because I need a way to keep a log of what files were scanned?
If I could output the results of scan directly from PowerShell that would be even better but I don’t believe this function returns anything.
Any pointers appreciated.

Related

Is there a faster way to run SQL Compare through powershell?

We currently use a house written PS script to compare developers' local SQL databases with live databases to generate deployment scripts. We use Redgate SQL Compare through powershell, typically calling it as such (where $SQLComparepath is the file path of the executable for SQLcompare):
$AllArgs = #("/server1:$DevServer", "/Database1:$DevDB", "/Scripts2:$folder", "/Include:$type", "/Include:$type:\[$schema]\.\[$name]", '/Synchronize')
&$SQLComparePath $AllArgs
We find that while this works, it takes a long time to generate scripts for large numbers of objects since we are calling the exe serially for each object. I've searched through the documentation and don't see any way of passing more than one set of arguments at a time. Does anyone know of a more efficient way of calling SQL Compare, through powershell or otherwise?
Thanks!

Need PowerShell help! Very strange things are happening

So I'm using PowerShell to manipulate a SharePoint 2010 library. I am uploading, downloading, and deleting files in a script using a custom module I made. My errors are so odd I can't understand them.I am using PowerGUI, Windows PowerShell ISE, and PowerShell Management Shell all in admin mode.
PowerGUI:
I sometimes can't get an spWeb object, sometimes I can. The URL string is being pulled from a CSV file so it never changes and neither does the code before I call Get-SPWeb -Identity $correctURL
Sometimes when I call a list RootFolder it returns $false for the Exists property, using management shell I can get past this. Otherwise I can touch it by calling $ListName.RootFolder.Files and it will magically return and hold the $true for Exists in future executions of my script.
Then when I call an XML file full of file properties(for uploaded files) it will return file property names for $fileFieldsXML.row.Attributes | foreach {$_} and values for $fileFieldsXML.row.Attributes | foreach {$_.ToString()}. This is, unless I set them to variables. When two very distinct vars are set to these two differentish calls they both are set to the array of property names! Why??
Windows PowerShell ISE and PowerShell Management Shell
I think these are just outdated somehow. I can call Get-SPWeb in Management Shell but I can't in ISE due to I guess outdated versions. Lately the management shell will act as if I haven't been doing anything to the files unless I close it out and reopen it. Does the management shell just hold a copy of all files when it starts or something? Can I make it update these files?
Can anyone suggest a better way to debug? Also why does a module seem to severely increase runtime? When everything was in the same script it was quick but my long functions take several times longer to execute now.
I also have been using PowerShell and SharePoint for almost two months now, so I am a beginner and intern. Perhaps that is really the cause of my problems :)

output from corFlags.exe and dumpbin.exe disappear when redirected

We are trying to automate some procedures using corFlags.exe and dumpbin.exe. Trying to capture the output from either of these programs has been impossible so far. In detail, executing
corFlags.exe yourfavorite.dll
in cmd.exe or in powershell.exe (with appropriate change of syntax) produces output just fine, but as soon as one attempts to capture the output, either through re-direction or piping, e.g.
corflags.exe yourFavorite.dll >>out.txt
or
$l_result = &corflags yourFavorite.dll | select-string -pattern "32BIT"
and the output of corflags is lost. There is a similar problem with dumpbin.
This is occuring on a Windows 7 sp1 machine (6.1.7601 sp1 build 7601).
I am guessing they suffer from the flaw of not flushing their output streams before exiting. See Output shows up in console, but disappears when redirected to file for example.
We have found no way of working around this problem so far (executing in sub-process/batch process/etc. etc.) Does anyone know of a work-around to this problem? Thanks.
A nice, simple demonstration of the problem is as follows. Open the PowerShell ISE and try to run "corFlags.exe some.dll" within the console window. You will not be able to get any output from it!

What all VBScript operations are not allowed in HTA

I want to develop a script using hta which will mainly interact with an excel file for data transaction. I developed earlier this using Excel macro but I want to do the same with hta also for learning purpose.
Now, problem is I can see few vbscript operations are not allowed within hta e.g. echo. Can someone give me a list of such operations/keywords which are not applicable in hta. Is there a better way to achieve this?
I code in Core Java hence did not try VB/.net!
VBScript is VBScript whether you execute it under the WScript or the Mshta/Ie host. Not having the WScript host, means no WScript.Echo - and no WScript.Arguments.Unnamed.Count, WScript.Whatever.... either.
But: VBA is not VBScript. So don't expect those features to work in a .HTA.

Please help me with a Power shell Script which rearranges Paths

I have both Sybase and MSFT SQL Servers installed. There is a time when Sybase interferes with MS SQL because they have they have some overlapping commands.
So, I need two scripts:
A) When runs, script A backs up the current path, grabs all paths that contain sybase or SYBASE or SyBASE (you get the point) in them and move them all at the very end of the path, while preserving the order.
B) When it runs, script B restores the path from back-up.
Both script a and script b should affect the path immediately. So, if a.bat that calls patha.ps1, pathb.ps1 looks like so:
#REM Old path here
call patha.ps1
#REM At this point the effective path should be different.
call pathb.ps1
#REM Effective old path again
Please let me know if this does not make sense. I am not sure if call command is the best one to use.
I have never used P.S. before. I can try to formulate the same thing in Python (I know S.O. users tend to ask for "What have you tried so far"). Well, at this point I am VERY slow at writing anything in Power Shell language.
Please help.
First of all: call will be of no use here as you are apparently writing a batch file and PowerShell scripts have no association to run them by default. call is for batch files or subroutines.
Secondly, any PowerShell script you call from a batch file cannot change environment variables of the caller's environment. That's a fundamental property of how processes behave and since you are calling another process, this is never going to work.
I'm not so sure why you are even using a batch file here in the first place if you have PowerShell. You might just as well solve this in PowerShell completely.
However, what I get from your problem is that the best way to resolve this is probably the following: Create two batch files that each set the PATH appropriately. You can probably leave out both the MSSQL and Sybase paths from your usual PATH and add them solely in the batch files. Then create shortcuts to
cmd /k set_mssql_path.cmd
and
cmd /k set_sybase_path.cmd
each of which now is a shortcut to a shell to work with the appropriate database's tools. This is how the Visual Studio Command Prompt works and it's probably the cleanest solution you have. You can use the color and prompt commands in those batches to make the two different shells distinct so you always know what environment you have. For example the following two lines will color the console white on blue and set a prompt indicating MSSQL:
color 1f
prompt MSSQL$S$P$G
This can be quite handy, actually.
Generally, trying to rearrange the PATH environment variable isn't exactly easy. While you could trivially split at a ; this will fail for paths that itself contain a semicolon (and which need to be quoted then). Even in PowerShell this will take a while to get right so I think creating shortcuts specific to the tools is probably the nicest way to deal with this.