Passing variable as a parameter for Set-MpPreference - windows

I'm trying to configure Windows Defender via Set-MpPreference.
This is my code:
$ASRIds = "01443614-cd74-433a-b99e-2ecdc07bfc25,92E97FA1-2EDF-4476-BDD6-9DD0B4DDDC7B"
$ASRValues = "1,1"
Set-MpPreference -AttackSurfaceReductionRules_Ids $ASRIds -AttackSurfaceReductionRules_Actions $ASRValues
however, I am getting error
Set-MpPreference : Cannot process argument transformation on parameter 'AttackSurfaceReductionRules_Actions'. Cannot
convert value "1,1" to type "Microsoft.PowerShell.Cmdletization.GeneratedTypes.MpPreference.ASRRuleActionType[]".
Error: "Cannot convert value "1,1" to type
"Microsoft.PowerShell.Cmdletization.GeneratedTypes.MpPreference.ASRRuleActionType". Error: "Unable to match the
identifier name 1,1 to a valid enumerator name. Specify one of the following enumerator names and try again:
Disabled, Enabled, AuditMode""
At line:1 char:96
+ ... tionRules_Ids $ASRIds -AttackSurfaceReductionRules_Actions $ASRValues
+ ~~~~~~~~~~
+ CategoryInfo : InvalidData: (:) [Set-MpPreference], ParameterBindingArgumentTransformationException
+ FullyQualifiedErrorId : ParameterArgumentTransformationError,Set-MpPreference
I know that this can be done directly like this:
Set-MpPreference -AttackSurfaceReductionRules_Ids 1443614-cd74-433a-b99e-2ecdc07bfc25,92E97FA1-2EDF-4476-BDD6-9DD0B4DDDC7B -AttackSurfaceReductionRules_Actions 1,1
but passing it as variable is a necessary part of my project. Is there anything I can do to make the variables work?
One by one (working with only one attack surface reduction rule at the time) works, but Windows Defender disabled the other rules if you enable just one. So I need to have multiple IDs in the variable at the same time.
Thanks

I'm guessing this is not liking the fact that you're passing a string - try passing an array arrays:
$ASRIds = #("01443614-cd74-433a-b99e-2ecdc07bfc25","92E97FA1-2EDF-4476-BDD6-9DD0B4DDDC7B")
$ASRValues = #(1,1)
Troubleshooting Notes
The [] in your error is telling us it is expecting an array
...Microsoft.PowerShell.Cmdletization.GeneratedTypes.MpPreference.ASRRuleActionType[]...
This part is telling us it's trying to match the whole string 1,1 to an enumerator - it should be matching one at a time.
Unable to match the identifier name 1,1 to a valid enumerator name
I'm guessing you want to specify Enabled? Consider this, to make your code more readable: $ASRValues = #('Enabled','Enabled')
Specify one of the following enumerator names and try again:
Disabled, Enabled, AuditMode
As for the error in the comments, well...

Related

Escaping underscore in SSIS

I have an SSIS expression.as per below:
I am sending the results of this package as an sms,however the sms does not show the underscores,I have therefore opted to using dashes for now.
The sms is showing at as OLEGALINITTEST
I there a way i can escape the underscore so that it shows on the sms?
REPLACE(#[System::PackageName], "_", "-") = O-LEGAL-INIT-TEST
Desired output is O_LEGAL_INIT_TEST
I am replacing the underscore's in the string with "-" dashes .I am sending the variable to an Oracle package that send the actual sms.
#[System::PackageName] is generally the same as the file name without the file extension so given a package named This-Is-Fun.dtsx we would expect to see the PackageName property as This-Is-Fun.
But, there are cases where this not the case. If we named our package A=B.C_D.dtsx, the resulting object name for our package is A B C_D. Each offending character is replaced with spaces.
If you attempt to name an SSIS object with "something weird" it will throw an error on the operation like
The name cannot contain any of the following characters: / \ : [ ] . =
The restrictions are similar, but different, for the package name itself as Windows/Visual Studio will balk with
contain any of the following characters: / ? : & \ * " < > | # %
contain Unicode control characters contain invalid surrogate
characters be system reserved names, including 'CON', 'AUX', 'PRN', 'COM1'
or 'LPT2' be '.' or '..'
As always with expressions in SSIS, check what you're building. Create an SSIS Variable where you specify an expression.
Assuming you create an SSIS variable called SMS_CONTENT data type of string and then I'm going to replace spaces with underscores. The expression is
REPLACE(#[System::PackageName], " ", "_")
Given a starting package name of
a=b.SO_61618859_This_Is_Fun.dtsx
System::PackageName becomes a b SO_61618859_This_Is_Fun
SMS_CONTENT becomes a_b_SO_61618859_This_Is_Fun
If it works fine during development but goes awry in production, log the value via a script task's information event so you can review logs after the run. https://billfellows.blogspot.com/2016/04/biml-script-task-test-for-echo.html You don't need to Biml it, just mark the variable as part of the Read only variable collection and the following script will record the values in the log. In your case, I'd add System::PackageName and then my SSIS variable, User::SMS_CONTENT
bool fireAgain = false;
string message = "{0}::{1} : {2}";
foreach (var item in Dts.Variables)
{
Dts.Events.FireInformation(0, "SCR Echo Back", string.Format(message, item.Namespace, item.Name, item.Value), string.Empty, 0, ref fireAgain);
}

Search Query Parameter

I want to search email which contains '+' in it. for example
something like this myemail.subdomain+1#domain.com.
URL - https://example.com?searchKey=myemail.subdomain+1#
I am using Laravel, this parameter is fetched from route using
$request->get('searchKey');
but it's converting '+' to ' ' ,
as a result i am getting
searchKey as myemail.subdomain 1#
which leads to improper result.
Any help?
PHP assumes that + from GET request is a space. Right encoded plus symbol is %2B.
You have to just prepare string from request to save plus symbol:
$searchKey= urlencode(request()->get('searchKey'));
In your case you'll get # as %40. Then you can replace plus with correct code and decode it. But then be careful with usual spaces!
$searchKey = urlencode(request()->get('searchKey'));
$searchKey = urldecode(str_replace('+', '%2B', $searchKey));
https://www.php.net/manual/en/function.urlencode.php
https://www.php.net/manual/en/function.urldecode.php
P.S. I suppose it is not the best soulution, but it should work.
P.P.S. Or, if you can prepare plus as a %2B before it will be at search parameter, do it

API Blueprint: Semantic Issue "no value(s) specified"

In my blueprint I'm defining a data structure and try to use it like so
+ Attributes
+ error: (Error Details, required)
Data structure definition at the end of the document:
# Data Structures
## Error Details
+ code : 1234 (number, required) - see list of error codes
+ message: User not found (string, required) - a human-readable error message
The resulting sample response body looks just like expected but the validation on apiary.io shows semantic issues for each of the places where I use constructs like this, saying "No value(s) specified".
Am I doing something wrong or is it a problem with the apiary.io parser?
I had the same problem and solved it by
omitting the colon
separating the object definition and type (see owner in this example):
Company (object)
name: Company name (string)
owner (OwnerResponse) (object)
A similar answer to other current answers, but none the less this fixed it for me.
No good:
+ Attributes
+ `status`: OK
+ `data`:
+ 5 (Channeldata)
+ 7 (Channeldata)
Fix:
+ Attributes
+ `status`: OK
+ `data`
+ 5 (Channeldata)
+ 7 (Channeldata)
As others have noted, losing a colon in the right place can fix things.
Attribute section can be also defined as + Attributes <Type Definition> (specification), so defining + Attributes (Error Details, required) should fix the given semantic issue.
Edit:
You have to omit a colon between attribute's name and its type, when an example value is not defined:
+ Attributes
+ error (Error Details, required)
Missed that before, sorry.

Array concatenation in IBM Filenet P8 Expression Builder?

In the Expression Builder for the Workplace Process Designer, I have an attachment variable of type String[] (array of strings). I'd like to add some elements to it using the Expression Builder, but I can't work out the syntax. Has anyone done this? Is it even possible to add elements to an existing array in Expression Builder?
The arraytostring solution only works if there is only one element the array.
Assign the additional value with the following expression:
stringarray[elementcount(stringarray) + 1] = value
The expected 'array out of bound exception' and the resizing of the array is handled during the assignment.
I originally thought that it is not possible that we had to resort to have a custom java component to do the job, however I had run a small experiment that should serve as a workaround for your case.
Suppose you have String[] arrayType={"string1, string2"}, you can use the following expression as a value for your updated array:
{(arraytostring(arrayType, " ", " ,", ","))+"string3"}
What I did was that,
First, I used arraytostring function to convert the array to a string separated by comma with a comma left at the end. My output is similar to string1,string2,
Second, I appended the string that I want to add to the end of the string, so that my output is string1,string2,string3
Lastly, I assigned the value above to my array, using the array expression format {}, so my final evaluated string is {string1,string2,string3}
For more information about array functions, please follow the link below:
https://www.ibm.com/support/knowledgecenter/SSNW2F_5.2.1/com.ibm.p8.pe.user.doc/bpfe003.htm
I had a case like this, here is what I did:
I get the array from the attachment using the CE-Operation and store
in an array property on the workflow
Then I used the following to
{(arraytostring(workflowArray, " ", " ,", ","))+workflowStringProp}
using the CE-Operation again to set the array in the attachment with
the workflowArray.

What's the difference between 'Array<_>' & 'Array'

I'm getting this error when trying to build the app:
<unknown>:0: error: cannot assign value of type 'Array<_>' to type 'Array'
but Xcode is not indicating a specific line or class for the failure.
If I could understand the difference between
Array<_>
&
Array
it may help me locate the issue.
When you app is crashing, than you can turn on All Exceptions for Debug breakpoint. This should stop on the line where the crash appears.
You find this in Xcode on the Left Panel-> BreakPoint Navigator.
Than press the + in the bottome left corner and Add Exception Breakpoint.
It looks like that you overwrite an array with an array that has a specific value definition. Good Luck :)
A generic argument clause is enclosed in angle brackets ( < > )
< generic argument list >
You can replace a type parameter with a type argument that is itself a specialized version of a generic type.For example, you can replace the type parameter T in Array < T > with a specialized version of an array, Array< Int > , Array< String >, to form an array whose elements are themselves array of integers / Strings
Regarding xour code Snippet the fix is:
u should define it with the right value ... userTweetsArray : [String] = String . or remove the : [String] because setting the value defines already the object and type :)
I don't like answering my own questions but for the sake of closure
I had this line of code
var userTweetsArray : Array = [String]()
I never actually used it. Once I removed that line the error had gone.
The error was caused by assigning an array of a type in this case String to an Array of no type.
So difference is Array<_> is an array of a type and Array is not.

Resources