Send log with customDimensions to Application Insights using Powershell - powershell

I want to send logs to my Application Insights using PowerShell script and I want it to contain customDimensions value.
I tried something like this:
$client = [Microsoft.ApplicationInsights.TelemetryClient]::new()
$client.InstrumentationKey = "xxxx"
$client.TrackTrace("MY CUSTOM LOG", "Information", #{foo="bar"})
$Client.Flush()
but it gives me an error:
Cannot find an overload for "TrackTrace" and the argument count: "3".
Ideally I want the code above to work so that I can read the log like this:
I know how to do it using Python and opencensus-ext-azure lib but now I also need Powershell as well.

Related

Sending named variables to SOAP via New-WebServiceProxy in Powershell

Please forgive any errors in terminology, I am self taught :)
I am using New-WebServiceProxy to interact with a SOAP API.
Everything works when variables are at a single level, as long as they are entered in the correct order they are parsed correctly. However I can't work out how to enter 2nd level variables.
For example once the web service proxy has been set up as $Forms via the WSDL the following SOAP call
<x:Body>
<pri:AddForm>
<pri:apiToken>12345</pri:apiToken>
<pri:FormTemplateID>xyz</pri:FormTemplateID>
<pri:OrganisationID>A1</pri:OrganisationID>
</pri:AddForm>
</x:Body>
Will work as $Forms.AddForm(1234, xyz, A1)
However if some of the variables are within a subheading such as
<x:Body>
<pri:AddForm>
<pri:apiToken>12345</pri:apiToken>
<pri:formRequest>
<pri:FormTemplateID>xyz</pri:FormTemplateID>
<pri:OrganisationID>A1</pri:OrganisationID>
</pri:formRequest>
</pri:AddForm>
</x:Body>
The same command won't work and presents an error "Cannot find an overload for "AddForm" and the argument count: "3".
Is there a way to structure the command so it will recognise the arguments within the subheading?
After a lot of trial and error I've found the following works
$formRequest = [PSCustomObject] #{
FormTemplateID = "xyz"
OrganisationID = "A1"
}
$FVForms.AddForm($apiToken, $FormRequest)

Parsing PowerBIRestMethod response to CSV

I've been working on a way to retrieve our PowerBI data, and managed to get exactly all the data I'd need to process, however I can't seem to figure out on how to actually parse the data to a proper CSV.
I use the invoke command to get user access to a certain dataset with the below command in PowerShell
Invoke-PowerBIRestMethod -Url 'https://api.powerbi.com/v1.0/myorg/admin/datasets/DATASETID/users' -Method Get
This then comes back with the below response:
{
"#odata.context":"http://wabi-north-europe-j-primary-redirect.analysis.windows.net/v1.0/myorg/admin/$metadata#Collection(Microsoft.PowerBI.ServiceContracts.Api.
Access.DatasetUser)","value":[
{
"datasetUserAccessRight":"ReadWriteReshareExplore","emailAddress":"hiddenemail","displayName":"hiddenname","identifier":"hiddenidentifier","graphId":"hiddengraphid","principalType":"User","userType":"Member"
},{
"datasetUserAccessRight":"Read","emailAddress":"hiddenemail","displayName":"hiddenname","identifi
er":"hiddenidentifier","graphId":"hiddengraphid","principalType":"Group"
}
]
}
As shown above it came back with 2 entries of permissions on that dataset, one being a user and the other a group.
I want to parse/export this to a simple CSV file containing the below information:
User rights
Email address
Displayname
Identifier
Principal Type
How would one achieve this? I've tried several ConvertFrom utilities in PowerShell, but those doesn't seem to work correctly. Is there any easy way to get this to export correctly?
Thank you in advance for any suggestions/advice!

How to send a list as parameter in databricks notebook task?

I am using Databricks Resi API to create a job with notebook_task in an existing cluster and getting the job_id in return.
Then I am calling the run-now api to trigger the job.
In this step, I want to send a list as argument via the notebook_params, which throws an error saying "Expected non-array for field value".
Is there any way I can send a list as an argument to the job?
I have tried sending the list argument in base_params as well with same error.
user_json={
"name": job_name,
"existing_cluster_id": cluster_id,
"notebook_task": {
"notebook_path": notebook_path
},
"email_notifications":{
"on_failure":[email_id]
},
"max_retries": 0,
"timeout_seconds": 3600
}
response=requests.post('https://<databricks_uri>/2.0/jobs/create',headers=head,json=user_json,timeout=5, verify=False)
job_id=response.json()['job_id']
json_job={"job_id":job_id,"notebook_params":{"name":"john doe","my_list":my_list}}
response = requests.post('https://<databricks_uri>/2.0/jobs/run-now', headers=head, json=json_job, timeout=200, verify=False)
Not found any native solution yet, but my solution was to pass the list as a string and parse it back out on the other side:
json_job={"job_id":job_id,
"notebook_params":{
"name":"john doe",
"my_list":"spam,eggs"
}
}
Then in databricks:
my_list=dbutils.widgets.get("my_list")
my_list=my_list.split(",")
With appropriate care around special characters or e.g. conversion to numeric types.
If the objects in the list are more substantial, then sending them as a file to dbfs using the CLI or API before running the job may be another option to explore.
Hi may be I'm bit late but found a better solution.
Step 1:
Use JSON.stringyfy() in the console of any browser to convert your value(object, array, JSON etc) into string
Ex:
Now use this value in the body of URL
In Databricks notebook convert string to JSON using python json module.
Hope this helps

Creating Azure Stream Analytics Job through Powershell

I would like to create a stream analytics job using only Powershell. I know that the command to do this is: New-AzureRMStreamAnalyticsInput. However it requires a JSON file with job details. I found a documentation provided by Microsoft where there is a small template of such a JSON file (check Create paragraph). However it's not enough for me.
I want to create an input from blob storage hence my JSON looks like this:
{
"properties":{
"type":"stream",
"datasource":{
"type":"Microsoft.Storage/Blob",
"properties":{
"accountName":"abc",
"accountKey":"###",
"container":"appinsights",
"pathPattern":"test-blob_2324jklj/PageViews/{date}/{time}",
"dateFormat":"YYYY-MM-DD",
"timeFormat":"HH"
}
}
}
}
After saving it and passing as an argument in New-AzureRMStreamAnalyticsInput I receive following error: New-AzureRMStreamAnalyticsInput : Stream analytics input name cannot be null. I think that my JSON file is not correct.
Do you have any templates of json files containing stream analytics job details or can you just tell me how to correctly set up a job through powershell?
A simple way of getting your template right is to manually create an input from Portal and then run PowerShell command Get-AzureRmStreamAnalyticsInput to get the JSON payload.
From your example, it seems you missed the input name. Try something like below:
{
"Name": "BlobInput1",
"Properties": {
... ...
}
}

Facebook batch operations custom object

I am trying to make some batch operations for custom objects that I have created oat Open graph API. I have seen tons of examples for feeds or images, but I still do not know if Facebook supports batch operations for custom objects. For example, I'd like to know if a batch operation for the following objects would work:
batch=[
{:method=>"post", :relative_url=>"/me/tfgtopquiz:win", "profile"=>"users/1/victories"}
{:method=>"post", :relative_url=>"/me/tfgtopquiz:guessed", "triviaquestion"=>"questions/1"} ]
Notice that I have custom types (triviaquestion). It seems that if I pass it as a parameter facebook ignores it, and I would need this information. After the request, I get this error message:
"The action you're trying to publish is invalid because it does not specify any reference objects. At least one of the following properties must be specified: triviaquestion."
I really tried to define the type "triviaquestion", but it looks like Facebook ignored it iside batch JSON.
Any thoughts?
Thanks!
After some time I realized that I should send the JSON in other format:
{:access_token=>"MY_ACCESS_TOKEN",
:requests=>
[{:action=>"guessed", :object_type=>"triviaquestion", :object_url=>"URL"},
{:action=>"guessed", :object_type=>"triviaquestion", :object_url=>"URL"},
{:action=>"guessed", :object_type=>"triviaquestion", :object_url=>"URL"},
{:action=>"play", :object_type=>"correct_answer", :object_url=>"URL"}]}
Thanks!