I'm using Get-Diskfree function described here: https://binarynature.blogspot.com/2010/04/powershell-version-of-df-command.html
I want to sum all values from Used column, but as I try to call out a specific properties of Get-Diskfree output, I've got nothing, null.
Function is showing output like this:
FileSystem : NTFS
Type : Local Fixed Disk
Volume : C:
Available : somevalue
Computer : somevalue
Used : somevalue
Size : somevalue
FileSystem : NTFS
Type : Local Fixed Disk
Volume : D:
Available : somevalue
Computer : somevalue
Used : somevalue
Size : somevalue
I want to be able to call out Used property by parsing Get-Diskfree output into variable like this:
function {...}
$variable = Get-Diskfree
$variable.Used
Last line don't give me any output, in comparision to for example:
$variable = get-service
$variable.Name
long list of service names
Is function (or functions overall) designed in a way, that this method is impossible to use?
I plan to sum them by using more less the method I used in this script Powershell: System.Object[] in export-csv file
What I want to achieve is to sum Used column for first 8 disks (there are 20 of them on VM), export an output as csv and send an html email based on that csv file.
Related
This is my json which read via a lookup activity
{
"key1" : { "id" = "100" },
"key2" : "XYZ",
"key3" : [1,2,3]
}
I need a activity that gives me all the keys alone from above json
Lookup.output.firstrow.key2 gives me the string XYZ
What expression i can use to get all the keys alone
I really looking for some expression like Lookup.output.firstrow.getKeys() which returns array of keys such as
["key1", "key2", "key3"]
How do i get only the Json keys as a output from ADF lookup activity
There is no such direct way to achieve this you have to do it by setting the variables and string manipulation.
Follow below procedure:
I took json file in look up and its output is as follow:
To get all keys from above Json first I took set variable activity and created a demo string variable with value.
#substring(string(activity('Lookup1').output.value),2,sub(length(string(activity('Lookup1').output.value)),4))
here we are converting lookup output to string and removing braces from start and end.
Then I took another set variable activity and created a demo2 array variable with value.
#split(substring(string(split(variables('demo'),':')),2,sub(length(string(split(variables('demo'),':'))),4)),',')
Here we are splitting the string with : and ,
Then I created an array with default range of even numbers of values 0,2,4,6 etc.
Then Passed it to ForEach activity
Then Inside For Each activity I took append variable activity and gave value as
#variables('demo2')[item()]
Output:
Note: if your values contain : or , the above expression will also split those values. and if we split the values with : then I will split the string with : only and rest thing it will consider as single value. In below image the highlighted value it is taking as single value.
I am getting the above error when I am trying to run this function on a text column in power query[Excel].
The column contains different names and this function checks if the entry has either of "AbbVie", "Roche" or "Pfizer" in it. It returns the names from the list that is present in the entry.
(txt as text) =>
[
create_val = (val as text,check as text, output as text) =>
let
output = if Text.Contains(val,check)
then Text.Combine({output, check},",")
else output
in
output,
final_value = List.Accumulate({"AbbVie","Roche","Pfizer"},"",(state,current) => create_val(txt,current,state))
][final_value]
I struggled with this one too so I though I'd share how I solved it.
I was using a custom function recursively, as a means to implement looping. It turns out I was modifying variables from the function definition, i.e. variables that the function had been called with. By declaring local variables, the function worked as expected.
I use the UDF.Javascript function to process the message,when after converting to json object ,I see the UDF.Javascript alias name getting added to the json.
{"Device":{"deviceId":"DJT3COE4","productFilter":"pcmSensor","SignalDetails":[{"Devicevalue":"72.04","DisplayName":"Valve Open Status","Description":"Machine Valve Open State Information","DataType":"BOOLEAN","Precision":"undefined","DefaultUoM":"undefined"},{"Devicevalue":"2.7","DisplayName":"Temperature","Description":"Temperature Sensor Reading","DataType":"TEMPERATURE","Precision":"2","DefaultUoM":"DEG_CELSIUS"},{"Devicevalue":"2.99","DisplayName":"Location","Description":"Location","DataType":"LOCATION","Precision":"undefined","DefaultUoM":"LAT_LONG"},{"Devicevalue":"15","DisplayName":"Valve Control","Description":"On / Off control","DataType":"BOOLEAN","Precision":"undefined","DefaultUoM":"undefined"}]}}
Remove the aliasname : {"Device": from the json.
Maybe you could use WITH...AS... in your sql,please see below example:
WITH
c AS
(
SELECT
udf.processArray(input)
from input
)
SELECT
c.processarray.item,c.processarray.name
INTO
output
FROM
c
Output:
My columns are very few,you need to define all of your columns which is a little bit tedious.But it does works,please have a try.
I have an elasticsearch index that contains various member documents. Each member document contains a membership object, along with various fields associated with / describing individual membership. For example:
{membership:{'join_date':2015-01-01,'status':'A'}}
Membership status can be 'A' (active) or 'I' (inactive); both Unicode string values. I'm interested in providing a slight boost the score of documents that contain active membership status.
In my groovy script, along with other custom boosters on various numeric fields, I have added the following:
String status = doc['membership.status'].value;
float status_boost = 0.0;
if (status=='A') {status_boost = 2.0} else {status_boost=0.0};
return _score + status_boost
For some reason associated with how strings operate via groovy, the check (status=='A') does not work. I've attempted (status.toString()=='A'), (status.toString()=="A"), (status.equals('A')), plus a number of other variations.
How should I go about troubleshooting this (in a productive, efficient manner)? I don't have a stand-alone installation of groovy, but when I pull the response data in python the status is very much so either a Unicode 'A' or 'I' with no additional spacing or characters.
#VineetMohan is most likely right about the value being 'a' rather than 'A'.
You can check how the values are indexed by spitting them back out as script fields:
$ curl -XGET localhost:9200/test/_search -d '
{
"script_fields": {
"status": {
"script": "doc[\"membership.status\"].values"
}
}
}
'
From there, it should be an indication of what you're actually working with. More than likely based on the name and your usage, you will want to reindex (recreate) your data so that membership.status is mapped as a not_analyzed string. If done, then you won't need to worry about lowercasing of anything.
In the mean time, you can probably get by with:
return _score + (doc['membership.status'].value == 'a' ? 2 : 0)
As a big aside, you should not be using dynamic scripting. Use stored scripts in production to avoid security issues.
I am trying to create a file with a name based on an integer value from a function, clearly below does not work but gives you the idea :
getValue() -> 1.
createFile() ->
{ok, File} = file:open( getValue(), [write]),
io:format(File,"Test~n"),
file:close(File).
This ought to be simple, even with Erlangs lack of support for strings, so I must just be missing something obvious ( as is the price of being new to something ) :
If you just want to open a file whose name is "1", then you can use integer_to_list/1 to do that (since a string is just a list of integers for the ASCII values of the characters):
getValue() -> 1.
....
{ok, File} = file:open(integer_to_list(getValue()), [write]),
If you're wanting to create a filename based on the value from getValue/0, then the same principle applies, but you just create your filename from gluing several lists together.