Showing posts with label Azure. Show all posts
Showing posts with label Azure. Show all posts

The term 'New-AzResourceGroup' is not recognized as the name of a cmdlet, function, script fiel or operable program.

 The term 'New-AzResourceGroup' is not recognized as the name of a cmdlet, function, script fiel or operable program.

Issue:

New-AzResourceGroup : The term 'New-AzResourceGroup' is not recognized as the name of a cmdlet, function, script file,  or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and

try again.

At line:1 char:1

+ New-AzResourceGroup

+ ~~~~~~~~~~~~~~~~~~~

    + CategoryInfo          : ObjectNotFound: (New-AzResourceGroup:String) [], CommandNotFoundException

    + FullyQualifiedErrorId : CommandNotFoundException


Solution:

You need to install the Azure Powershell module:

You can look for just the one for this command:

Install-Module -Name Az.Resources -AllowClobber -Scope CurrentUser

Or all of them:

Install-Module -Name Az -AllowClobber -Scope CurrentUser


Hope this will help you and save your time.

Enjoy !!!

:)

Azure : LogicApp If Condition

Azure : LogicApp If Condition



Here is sample code to send email using Azure function app

API Response

body
{
    "ResultCode": "OK",
    "Message": "Success",
    "Data": "demo@gmail.com"
}

If Condition Step, get http API response result value, Here we are getting above result and want to get value of "ResultCode", and based on we need to perform another action, so we can get it as below,



 "expression": {
 "and": [
  {
  "equals": [
   "@outputs('HttpStepName')['body']?['ResultCode']",
   "OK"
  ]
  }
 ]
},


Hope this will help you and save your time.

Enjoy !!!

:)

Azure : Function App

Azure : Function App



Here is sample code to send email using Azure function app

Encryption


namespace DemoFunctionApp
{
    public class EmailUsers
    {
        public string ToEmail { get; set; }
    }

    public class Response
    {
        public string StatusCode { get; set; }
        public string Message { get; set; }
        public string Data { get; set; }

    }
    public static class Function1
    {
        [FunctionName("Function1")]
        public static async Task<HttpResponseMessage> Run([HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)]HttpRequestMessage req, TraceWriter log)
        {
            log.Info("C# HTTP trigger function processed a request.");

            var mailmessage = new MailMessage { From = new MailAddress("user@gmail.com", "UserName") };

            var emailUsers = await req.Content.ReadAsAsync<EmailUsers>();
            
            mailmessage.To.Add(emailUsers.ToEmail);

            mailmessage.Subject = "Test email from function app" + System.DateTime.Now;
            mailmessage.IsBodyHtml = true;
            mailmessage.Body = "TEst email from function app" + System.DateTime.Now;

            SmtpClient smtpClient = null;
            smtpClient = new SmtpClient();

            smtpClient.Host = "smtp.gmail.com";
            smtpClient.Port = 587;
            smtpClient.UseDefaultCredentials = false;

            smtpClient.DeliveryMethod = SmtpDeliveryMethod.Network;
            smtpClient.Credentials = new NetworkCredential("user@gmail.com", "userEmailPassword");

            smtpClient.EnableSsl = true;

            smtpClient.Send(mailmessage);

            Response response = new Response
            {
                StatusCode = HttpStatusCode.OK.ToString(),
                Message = "Success",
                Data = emailUsers.ToEmail
            };

            return req.CreateResponse(HttpStatusCode.OK, response);
        }
    }
}

Hope this will help you and save your time.

Enjoy !!!

:)