Custom scripts for Azure - v8.0

Hi Community,

For various reasons we have to use some custom scripts to connect to our Azure tenant and perform some operations using the Graph API

We have successfully done this using powershell cmdlets, but I was hoping we can do the same using custom VB.NET scripts since those are easier to work with. 

 I'm assuming we need to start by uploading Microsoft.Identity.Client.dll into software loader before being able to use it however I can't find any offline installer for it since our servers are not connected to the internet. 

Has anyone had any success in doing this? Any links/resources will be extremely useful

Using v8.0

Thanks

Kin

  • You can take a look at the NuGet packages of Microsoft.Identtity.Client. The assemblies should be inside the package (can be opened with nuGet tools or a archiver like 7Zip).

    Then just upload the DLL with SoftwareLoader and reference it in your script code.

    Or, better, write your script in the SystemDebugger. Then add the Microsoft.Identity.Client with NuGet to your project. You should upload any new DLL added by NuGet to your database using SoftwareLoader.

    HtH

  • Hello Markus

    Apologies the late response to this, I got the DLLs, loaded it using software loader and also put it in the same folder as where I am running designer from. I tried a simple script but it says its not able to find the function

    Imports Microsoft.Graph
    Imports Microsoft.Identity.Client

    Public Function Azure() As String

    Dim test As New Microsoft.Graph.GraphServiceClient()

    End Function

    Compiling this locally in designer gives an error Microsoft.Graph.GraphServiceClient is not defined

    Any suggestions where I might be missing the reference? I appreicate the code is not complete by any means but I was looking to see if the system is recognising the DLL but it seems like its not.

  • You need to specify the References statement in your Script to instruct the One IM  compiler to add this assembly reference to script code project.

    #If Not SCRIPTDEBUGGER
    
    References Microsoft.Identity.Client.dll
    
    #End If

  • Sorry I'm probably being thick here but that didn't work either, I've tried various combinations of Imports and References.. .interestingly when I use references on Microsoft.Graph the compiler fails with a system cannot find the file specified error

    Currently the code is

    'Imports Microsoft.Graph
    'Imports Microsoft.Identity.Client
    #If Not SCRIPTDEBUGGER
    References Microsoft.Identity.Client.dll
    References Microsoft.Graph
    #End If

    Public Function Azure() As String

    Dim test As New Microsoft.Graph.GraphServiceClient(Nothing)

    End Function

    Error on compile: could not find library 'Microsoft.Graph'

    PS: I'm not using visual studio, directly writing in designer.

  • Try this one:

    #If Not SCRIPTDEBUGGER
        References Microsoft.Identity.Client.dll
        References Microsoft.Graph.dll
    #End If
    
    Public Function Azure() As String
    
    Dim test As New Microsoft.Graph.GraphServiceClient(Nothing)
    
    End Function

  • Hi Markus

    Ah, I had forgotten to add the .dll part to my graph refernce. Got a bit further but still got a compiler error when compiling locally in designer

    Reference required to assembly 'System.Runtime, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' containing the base class 'System.Object'. Add one to your project. Azure 8

    I'll google this and see what comes up

    Thanks again

  • Got it working, had to add an explicit reference to System.Runtime.dll. This solution might vary depending on the .NET version I think

    Anyway, full code here (sorry I dont know how to format the code properly in the forum)

    #If Not SCRIPTDEBUGGER
    'References Microsoft.Identity.Client.dll
    References Microsoft.Graph.dll
    References System.Runtime.dll
    #End If

    Public Function Azure() As String

    Dim test As New Microsoft.Graph.GraphServiceClient(Nothing)

    End Function

  • Hi kinshasa, do you have a more detailed example script on how you insert the Authenticator object instead of nothing in the sample above?

    I try to do the following in VB.NET:

    GraphServiceClient graphClient = new GraphServiceClient( authProvider );

    var phoneAuthenticationMethod = new PhoneAuthenticationMethod
    {
    PhoneNumber = "+1 2065555555",
    PhoneType = AuthenticationPhoneType.Office
    };

    await graphClient.Me.Authentication.PhoneMethods
    .Request()
    .AddAsync(phoneAuthenticationMethod);

    Until now I have found how I can get the Authentication Token with: QER_GetAzureAccessTokenForApp

    Also with HttpWebRequest I can issue HTTP GET request , but I want to use the GraphServiceClient instead of pure HTTP REST.

    Regards, René