<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:atom="https://www.w3.org/2005/Atom" xmlns:sy="https://purl.org/rss/1.0/modules/syndication/" xmlns:dc="https://purl.org/dc/elements/1.1/" xmlns:content="https://purl.org/rss/1.0/modules/content/" xmlns:wfw="https://wellformedweb.org/CommentAPI/" xmlns:slash="https://purl.org/rss/1.0/modules/slash/"
  version="2.0">
  <channel>
    <title>Theo Browning</title>
    <atom:link
      href="https://docs.microsoft.com/archive/blogs/thbrown/feed.xml"
      rel="self"
      type="application/rss+xml" />
    <link>https://docs.microsoft.com/archive/blogs/thbrown/feed.xml</link>
    <description>Talk is cheap, show me the code!</description>
    <lastBuildDate>Tue, 16 Apr 2019 06:18:46 GMT</lastBuildDate>
    <language>en-US</language>
    <sy:updatePeriod>hourly</sy:updatePeriod>
    <sy:updateFrequency>1</sy:updateFrequency>
    <item>
      <title>Add a custom or non-standard PowerShell module to Azure Functions</title>
      <link>https://docs.microsoft.com/archive/blogs/thbrown/add-a-custom-or-non-standard-powershell-module-to-azure-functions</link>
      <pubDate>Sun, 25 Feb 2018 21:24:25 GMT</pubDate>
      <dc:creator><![CDATA[Theo Browning]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.technet.microsoft.com/thbrown/?p=755</guid>
      <description><![CDATA[When you need to do a bit more than an Azure Logic App will let you or when there is a bit of custom...]]></description>
      <content:encoded><![CDATA[When you need to do a bit more than an Azure Logic App will let you or when there is a bit of custom code/actions that need to be taken this where do you go? That's right, Azure Functions! Azure Functions allow quite a bit of flexibility and customization including a bunch of languages we can write in! PowerShell is one of those (In beta as of this writing) however, it seems the question of the day here lately is; How do I add my own custom module to my PowerShell Azure Function???!!! Well it is really quite simple and that is the purpose of this blog post so let's get to it.

First off you need your module, now I have created my own but you can reference and use any module in your Azure Functions app. The first detail of info to share here is that this is NOT application wide, you will need to do this for each function inside your app that you want to have access to this external resource.

Step 1: Creating the folder to store it in, in the right place. You need to have a folder named "<strong>modules</strong>" in the root folder of your function, this is the folder where the <strong>run.ps1</strong> is located. How do we do that? <strong>Kudu</strong> is the answer.
<ul>
 	<li>Go to your <strong>Functions App</strong> -&gt; Click on the <strong>Platform Features</strong> tab -&gt; Under <strong>Development Tools</strong> choose <strong>Advanced Tools (Kudu)</strong>:</li>
</ul>
<a href="https://msdnshared.blob.core.windows.net/media/2018/02/Kudu.png"><img src="https://msdnshared.blob.core.windows.net/media/2018/02/Kudu-1024x658.png" alt="" width="691" height="444" class=" wp-image-765 alignnone" /></a>
<ul>
 	<li>Next, On the Kudu page at the top, Click on the <strong>Debug Console</strong> drop down and choose <strong>PowerShell or Cmd</strong> (doesn't matter). Both will lead you to a view of your folder structure and a console window.</li>
</ul>
<a href="https://msdnshared.blob.core.windows.net/media/2018/02/Kudu1.png"><img src="https://msdnshared.blob.core.windows.net/media/2018/02/Kudu1.png" alt="" width="589" height="432" class=" wp-image-785 alignnone" /></a>

&nbsp;
<ul>
 	<li>Now we need to navigate to your Functions Site Directory. My function is named PowerShellTimed (as you see in the screen shot above) so that is where I will navigate too. Click on the folder <strong>Site</strong> -&gt; <strong>wwwroot</strong> -&gt; <strong>YourFunctionsName</strong> and you will land a folder that has your run.ps1 and a function.json like below:</li>
</ul>
<a href="https://msdnshared.blob.core.windows.net/media/2018/02/Kudu2.png"><img src="https://msdnshared.blob.core.windows.net/media/2018/02/Kudu2.png" alt="" width="591" height="523" class=" wp-image-795 alignnone" /></a>
<ul>
 	<li>Now you are going to click on the <strong>+</strong> sign and choose <strong>New Folder</strong> and you will name it "<strong>modules</strong>":</li>
</ul>
&nbsp;

<a href="https://msdnshared.blob.core.windows.net/media/2018/02/Kudu3.png"><img src="https://msdnshared.blob.core.windows.net/media/2018/02/Kudu3.png" alt="" width="422" height="203" class=" wp-image-805 alignnone" /></a>

<a href="https://msdnshared.blob.core.windows.net/media/2018/02/Kudu4.png"><img src="https://msdnshared.blob.core.windows.net/media/2018/02/Kudu4.png" alt="" width="429" height="183" class=" wp-image-815 alignnone" /></a>
<ul>
 	<li>Ok, we have our folder created and now we can journey back to the <strong>Azure Portal</strong>. Navigate to your Functions App and click on the PowerShell function you are working with. All the way on the right of the screen (on the side) you should see a tab for "<strong>View files</strong>" and click on it. That will open your files blade and you should see a folder "<strong>modules</strong>" and your <strong>function.json</strong> and <strong>run.ps1</strong>.</li>
</ul>
<a href="https://msdnshared.blob.core.windows.net/media/2018/02/ViewFiles0.png"><img src="https://msdnshared.blob.core.windows.net/media/2018/02/ViewFiles0-1024x342.png" alt="" width="707" height="236" class=" wp-image-825 alignnone" /></a>
<ul>
 	<li>Now, click on the <strong>modules</strong> folder and click <strong>Upload</strong>, this will open a folder browser dialog. Navigate to your files and put them directly in the modules folder.</li>
</ul>
<strong>NOTE</strong>: Do <strong>NOT</strong> create any sub folders and place them in there, the files must be in the <strong>root modules folder</strong> even if you have many modules you are wanting to place here.

<a href="https://msdnshared.blob.core.windows.net/media/2018/02/ViewFiles1.png"><img src="https://msdnshared.blob.core.windows.net/media/2018/02/ViewFiles1.png" alt="" width="376" height="374" class=" wp-image-835 alignnone" /></a>

<a href="https://msdnshared.blob.core.windows.net/media/2018/02/ViewFiles2.png"><img src="https://msdnshared.blob.core.windows.net/media/2018/02/ViewFiles2.png" alt="" width="385" height="293" class=" wp-image-845 alignnone" /></a>
<ul>
 	<li>Once that is done, simply call your module commands from the run.ps1 script and viola it works! You do <strong>NOT</strong> need to call import-modules <strong>UNLESS</strong> you have conflicting modules and you want to explicitly override them. Notice I have two command I am calling directly <strong>Get-FooDate</strong> and <strong>Write-Foo</strong> and as you can see in the logs below work successfully!</li>
</ul>
<a href="https://msdnshared.blob.core.windows.net/media/2018/02/Result.png"><img src="https://msdnshared.blob.core.windows.net/media/2018/02/Result.png" alt="" width="615" height="610" class=" wp-image-865 alignnone" /></a>

&nbsp;

&nbsp;

Hope that helps my friends, enjoy and PowerShell \ Azure on!

~Theo]]></content:encoded>
    </item>
    <item>
      <title>Edit/Update an Azure Alert Rule: Part 1 = Using Azure PowerShell Cmdlets.</title>
      <link>https://docs.microsoft.com/archive/blogs/thbrown/editupdate-an-azure-alert-rule-part-1-using-azure-powershell-cmdlets</link>
      <pubDate>Wed, 21 Feb 2018 06:19:30 GMT</pubDate>
      <dc:creator><![CDATA[Theo Browning]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.technet.microsoft.com/thbrown/?p=636</guid>
      <description><![CDATA[Azure allows us to create Metric Alert Rules for a resource to trigger when something we want...]]></description>
      <content:encoded><![CDATA[<span>     Azure allows us to create Metric Alert Rules for a resource to trigger when something we want to know about happens like CPU being to high for a certain time, available memory dropping too low, or an Azure Function Starting (much more). We will not get much deeper that here about alert types but, you can read more here: <a href="https://docs.microsoft.com/en-us/azure/monitoring-and-diagnostics/insights-alerts-portal">Azure Metric Alert Rule</a> . Now, say you need to complete a task (maintenance etc.) and this task is going to do something that triggers the rule(s) over and over. Well you don't want this sending you a ton of emails or lighting up your Health Status Board or whatever you have the alert(s) setup to do as a notification(s). So how do you turn it off? Well, there is the manual way of logging into the portal, navigating to the alert and then finally clicking on the disable button. Ugg manual clicks! And what if you have like 20,30,40 or more alerts setup, well then 3 hours later once you have clicked them all to disabled you can start your maintenance... Ok, maybe not 3 hours but definitely not fast... So automation is the only way to go here.</span>

<span>     Now unfortunately there isn't an easy PowerShell Set- command to do this for us. If we go look at the AlertRule commands you'll see our options are Add, Get, New, and Remove:</span>

<a href="https://msdnshared.blob.core.windows.net/media/2018/02/PowerShellAlertCmds.png"><img src="https://msdnshared.blob.core.windows.net/media/2018/02/PowerShellAlertCmds-1024x293.png" alt="" width="716" height="205" class="wp-image-645 alignnone" /></a>

Now if you use Add-AzureRMMetricAlertRule and there is a rule present present with the same name then it will over write the present rule with the updated settings. However, you cannot do something like we normally use in PowerShell doing a "Get-AzureRmAlertRule | Add-AzureRmMetricAlertRule -DisableRule" as the properties for each cmdlets are not one to one mappings. So one needs to be a little creative to approach this. The approach we will use is to get all the Alert Rules for a given Resource Group and save them in a collection. Then then through the power of the pipeline we will remap all the relevant properties from the Get to the correct counter part property of the Add cmdlet.

FYI: <strong>In part 2 we are going to do this in C# using the REST API for Azure Management.</strong>

Ok enough talk, let's see the code:

<script src="https://gist.github.com/CodeHeadTheo/4c654fa264b1610c10a980d57afbe796.js"></script>

Happy coding and Azure on my friends!

Full script can be downloaded from the Microsoft Script Center: <a href="https://gallery.technet.microsoft.com/scriptcenter/Disables-or-Enables-all-cfaf75dd">Disable_Enable_AllAlertRulesInRG.ps1</a>

~Theo
<ul>
 	<li>Reference data:
<ul>
 	<li><a href="https://docs.microsoft.com/en-us/powershell/module/azurerm.insights/get-azurermalertrule?view=azurermps-5.3.0">Get-AzureRmAlertRule</a></li>
 	<li><a href="https://docs.microsoft.com/en-us/powershell/module/azurerm.insights/add-azurermmetricalertrule?view=azurermps-5.3.0">Add-AzureRmMetricAlertRule</a></li>
</ul>
</li>
</ul>]]></content:encoded>
    </item>
    <item>
      <title>Check all Azure Resources in a Azure Resource Group for the presence of a configured Alert Rule with PowerShell.</title>
      <link>https://docs.microsoft.com/archive/blogs/thbrown/check-all-resources-in-a-resource-group-for-the-presence-of-a-configured-alert-rule-with-powershell</link>
      <pubDate>Tue, 20 Feb 2018 05:25:18 GMT</pubDate>
      <dc:creator><![CDATA[Theo Browning]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.technet.microsoft.com/thbrown/?p=735</guid>
      <description><![CDATA[I have had a slew of Resource Group questions coming in lately and just as many of those being about...]]></description>
      <content:encoded><![CDATA[I have had a slew of Resource Group questions coming in lately and just as many of those being about Alert Rules. So I am working on few posts/scripts right now around these topics. This script checks all Azure Resources in a given Azure Resource Group for the presence of a configured Alert Rule and reports the status for each Resource. This script does not check for multiple Alert Rules, simply the presence of one or none as that was the request given to me.
&nbsp;
You could easily edit this script to list out rules per resource, output as a grouped hashtable or lots of other fun customization. Please don't hesitate to request for customization or ask questions. Below is the script for copy or download full script from <a href="https://gallery.technet.microsoft.com/scriptcenter/Check-all-resources-in-a-93316a74">Microsoft Script Center</a>.

&nbsp;
<script src="https://gist.github.com/CodeHeadTheo/6a3b8bb817e9bd603a1a81c78e9c25b0.js"></script>
&nbsp;
Full script published to Microsoft Script Center:

<a href="https://gallery.technet.microsoft.com/scriptcenter/Check-all-resources-in-a-93316a74">https://gallery.technet.microsoft.com/scriptcenter/Check-all-resources-in-a-93316a74</a>]]></content:encoded>
    </item>
    <item>
      <title>Add an application to Azure Active Directory so your application can gain access to resources through APIs.</title>
      <link>https://docs.microsoft.com/archive/blogs/thbrown/add-an-application-to-azure-active-directory-so-your-application-can-gain-access-to-resources-through-apis</link>
      <pubDate>Mon, 19 Feb 2018 06:13:57 GMT</pubDate>
      <dc:creator><![CDATA[Theo Browning]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.technet.microsoft.com/thbrown/?p=665</guid>
      <description><![CDATA[In this post we are going to add an application to Azure Active Directory and our purpose here is...]]></description>
      <content:encoded><![CDATA[<span>In this post we are going to add an application to Azure Active Directory and our purpose here is simply to let a PowerShell application access resources through REST APIs (same process for all languages, PowerShell app post coming next). </span>This is quite simple and this post will stay strictly to this task.

First, go to "Azure Active Directory", next click on "App registrations", then click on "New application registration".<a href="https://msdnshared.blob.core.windows.net/media/2018/02/AD_AppRegistration.png">
<img src="https://msdnshared.blob.core.windows.net/media/2018/02/AD_AppRegistration-1024x569.png" alt="" width="830" height="461" class="wp-image-675 alignnone" /></a>

&nbsp;

That will get us to the below screen. Name your app something descriptive (this is completely cosmetic), choose "Web app / API" for application type and for the Sign-on URL if you have one put it here but f not, put anything here, just needs to be populated. Next click the "Create" button at the bottom.

<a href="https://msdnshared.blob.core.windows.net/media/2018/02/AppConfig0.png"><img src="https://msdnshared.blob.core.windows.net/media/2018/02/AppConfig0.png" alt="" width="609" height="307" class="wp-image-685 alignnone" /></a>

&nbsp;

Now that will put you on the Registered app blade and you will need two things here, copy the ApplicationId (also known as the ClientId) and to create an access key. The first one is right there for you to copy, for the second (key) click on settings then Keys. Once the Keys blade pops up choose a name for your key (again cosmetic), choose the duration you want the key to last and then click save. Once you do, the key will be visible and you need to copy it right then, if you click off the blade you will no longer be able to copy the key and will need to create another.

<a href="https://msdnshared.blob.core.windows.net/media/2018/02/AppConfig1.png"><img src="https://msdnshared.blob.core.windows.net/media/2018/02/AppConfig1-1024x343.png" alt="" width="1024" height="343" class="size-large wp-image-705 alignnone" /></a>

&nbsp;

You have a app registration and you now have the ApplicationId (ClientId) and a Access Key. Now you just need to give your app permissions to whatever API you want it to be able to work with. In my next blog I am going to show you how to use PowerShell to manipulate Azure Alert Rules so we will give our app access to do that. For Alert rules that is the Windows Azure Service Management API. So once again under settings choose "Required Permissions", next click Add, then 1 Select API, click on the API you want, and last click select.

<a href="https://msdnshared.blob.core.windows.net/media/2018/02/Permissions0.png"><img src="https://msdnshared.blob.core.windows.net/media/2018/02/Permissions0-1024x554.png" alt="" width="750" height="406" class="wp-image-715 alignnone" /></a>

&nbsp;

Final step we need to grant the API the permissions we want it to have. In this case that will be delegated permissions (there can be many permissions depending on the API) so we tick the box and click select at the bottom. <span>That will close the blade for selection and then click Done at the bottom, you will then see the notification that permissions are being added, ta-da you are done.  Well kind of, now you have to go write your code, remember to keep that ApplicationId/ClientId and Key that you copied in this process as you will need it in your app!</span>

<a href="https://msdnshared.blob.core.windows.net/media/2018/02/Permissions1.png"><img src="https://msdnshared.blob.core.windows.net/media/2018/02/Permissions1.png" alt="" width="900" height="320" class="size-full wp-image-725 alignnone" /></a>

&nbsp;

Happy coding!

~Theo

&nbsp;

References:
<ul>
 	<li>Register your application with your Azure Active Directory tenant
<ul>
 	<li><a href="https://docs.microsoft.com/en-us/azure/active-directory/active-directory-app-registration">https://docs.microsoft.com/en-us/azure/active-directory/active-directory-app-registration</a></li>
</ul>
</li>
</ul>]]></content:encoded>
    </item>
    <item>
      <title>Create your own VS Code PowerShell snippet in 3 steps!</title>
      <link>https://docs.microsoft.com/archive/blogs/thbrown/create-your-own-vs-code-powershell-snippet-in-3-steps</link>
      <pubDate>Fri, 03 Nov 2017 05:01:20 GMT</pubDate>
      <dc:creator><![CDATA[Theo Browning]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.technet.microsoft.com/thbrown/?p=585</guid>
      <description><![CDATA[Not that the documentation on VS Code for making snippets isn't simple enough but some people love...]]></description>
      <content:encoded><![CDATA[Not that the documentation on <a href="https://code.visualstudio.com/docs/editor/userdefinedsnippets">VS Code for making snippets</a> isn't simple enough but some people love pictures and just want to get it done! So for those that asked me here you go, write your own VS Code PowerShell snippet in 3 easy steps!

<a href="https://msdnshared.blob.core.windows.net/media/2017/11/S1.png"><img width="695" height="523" class="alignleft size-full wp-image-615" alt="" src="https://msdnshared.blob.core.windows.net/media/2017/11/S1.png" /></a>

&nbsp;

&nbsp;

&nbsp;

&nbsp;

&nbsp;

&nbsp;

&nbsp;

&nbsp;

&nbsp;

&nbsp;

&nbsp;

&nbsp;

&nbsp;

&nbsp;

&nbsp;

<a href="https://msdnshared.blob.core.windows.net/media/2017/11/S2.png"><img width="727" height="615" class="size-full wp-image-625 alignnone" alt="" src="https://msdnshared.blob.core.windows.net/media/2017/11/S2.png" /></a>

<a href="https://msdnshared.blob.core.windows.net/media/2017/11/S3.png"><img width="1024" height="550" class="size-large wp-image-626 alignleft" alt="" src="https://msdnshared.blob.core.windows.net/media/2017/11/S3-1024x550.png" /></a>

&nbsp;

<span>And if you do find yourself curious and want to know the details, then go read the docs : </span><a href="https://code.visualstudio.com/docs/editor/userdefinedsnippets">VS Code User Defined Snippets</a><span>.</span>

&nbsp;

PowerShell on!]]></content:encoded>
    </item>
    <item>
      <title>One small step to enhance PowerShell security using Constrained Endpoints.</title>
      <link>https://docs.microsoft.com/archive/blogs/thbrown/one-small-step-to-enhance-powershell-security-using-constrained-endpoints</link>
      <pubDate>Fri, 12 May 2017 03:19:55 GMT</pubDate>
      <dc:creator><![CDATA[Theo Browning]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.technet.microsoft.com/thbrown/?p=465</guid>
      <description><![CDATA[&nbsp;

There are lots of debates on the innerwebs today about PowerShell being a malware tool or...]]></description>
      <content:encoded><![CDATA[&nbsp;

There are lots of debates on the innerwebs today about PowerShell being a malware tool or it bringing vulnerabilities to the environment and they are not wrong. "Wait what? Not wrong?!!" you say? Well... yes it can be and it does but, no more than any other like Python, C/C++, Java, JavaScript, C# and etc. etc.. The fact is that PowerShell is a very "powerful" scripting language that can leverage objects of all types and many frameworks running on a system. Having this power and it being implemented in such a easy to use syntax does make it useful to not only good gals/guys, but the bad alike.

Just like anything else we need to control what, where and how we allow things to happen. How our information is to be queried, and changes to be made. Just because we implement doors, gates and fences does not mean we can let our guard down. For every locked door, shut gate, and tall fence, there is someone out there is looking to pick it, smash it down and go right through it, or simply go around, under, or over it. We have to proactively monitor and investigate as well as adapt to the changing methods and attacks. So, this is the first in a series of articles that I will discuss and show you how to implement some items to help you in this journey.

In this installment we are going to up our security by configuring what personnel can do on a system. There are quite a few ways to do this, we will start with "Constrained Endpoints" (Other methods coming soon). Endpoints are connection points for PowerShell that allow users and processes to remote to a system and perform tasks. There are several default Endpoints on a given system and we can run the following command to see them <a href="https://msdn.microsoft.com/en-us/powershell/reference/5.1/microsoft.powershell.core/get-pssessionconfiguration">Get-PSSessionConfiguration</a> (must being running elevated).

You will see output like the following:

<img width="1024" height="479" class="size-large wp-image-495 alignnone" alt="get_pssessionconfiguration_noted0" src="https://msdnshared.blob.core.windows.net/media/2017/05/Get_PSSessionConfiguration_Noted0-1024x479.png" />

&nbsp;

Endpoint capability can be limited to Commands, Permissions, Language, and RunAs which allows us a lot of flexibility in implementation. So let's get into the commands we are going to use here, PSSessionConfiguration is going to be our main noun. We will use that noun with the following verbs: Get/Set, Register/Unregister, and Enable/Disable. The other noun we will use here is PSSessionConfigurationFile, this noun will allow us to create and test our configuration with the New/Test verbs added.

Let's start with <a href="https://msdn.microsoft.com/en-us/powershell/reference/5.1/microsoft.powershell.core/new-pssessionconfigurationfile">New-PSSessionConfigurationFile</a> as it is needed first. The simple command I am going to use to demonstrate is as follows:

&nbsp;

<a href="https://msdnshared.blob.core.windows.net/media/2017/05/New_PSSessionConfigurationFile1.png"><img width="1024" height="583" class="size-large wp-image-575 alignnone" alt="new_pssessionconfigurationfile" src="https://msdnshared.blob.core.windows.net/media/2017/05/New_PSSessionConfigurationFile1-1024x583.png" /></a>

&nbsp;

The command above created my file which I then opened with <a href="https://code.visualstudio.com/">Visual Studio Code</a> for you to see. Breaking this down, here is what we created: the <a href="https://msdn.microsoft.com/en-us/powershell/reference/5.1/microsoft.powershell.core/new-pssessionconfigurationfile">New-PSSessionConfigurationFile </a>command itself defines and creates the .pssc file we need to create and register the new Endpoint.  The first parameter I passed is -SessionType and there are 3 values for it: Default, Empty, and RestrictedRemoteServer with the last being the recommended value as it only includes a limited set of proxy functions. The next parameter is the -VisibleCmdlets, these are the cmdlets that you are allowing the session to have, they can be edited in the file as well so as not to have to pass them through the command. I gave access to only the Get-Date cmdlet. Then I set the -LanguageMode with my value choice being ConstrainedLanguage, this does not allow commands that contain scripts to be evaluated and restricts access to .Net types, objects and methods. Lastly I gave the -Path parameter that points to where and filename .pssc to be created. There are lots of options here that you can explore and you will need to determine what access your Endpoint needs for whom it is going to be used by.

Next step, now that we have our configuration file of settings, we need to associate it to the Endpoint that we want to create. This is done with the <a href="https://msdn.microsoft.com/en-us/powershell/reference/5.1/microsoft.powershell.core/register-pssessionconfiguration">Register-PSSessionConfiguration</a> command, we simply pass it the path to the file we created in the last step through the -Path parameter and give it a -Name &lt;Cosmetic Name&gt;.

&nbsp;

<a href="https://msdnshared.blob.core.windows.net/media/2017/05/Register_PSSessionConfiguration1.png"><img width="1024" height="307" class="size-large wp-image-527 alignnone" alt="register_pssessionconfiguration1" src="https://msdnshared.blob.core.windows.net/media/2017/05/Register_PSSessionConfiguration1-1024x307.png" /></a>

&nbsp;

Almost there, the endpoint is active and available but... We need to setup who can use it and what permissions they have. Lets take a look at the session configuration before we do so we can ensure the endpoint was created:

&nbsp;

<a href="https://msdnshared.blob.core.windows.net/media/2017/05/Get_PSSessionConfigurationNewEndpoint.png"><img width="1024" height="457" class="size-large wp-image-546 alignnone" alt="get_pssessionconfigurationnewendpoint" src="https://msdnshared.blob.core.windows.net/media/2017/05/Get_PSSessionConfigurationNewEndpoint-1024x457.png" /></a>

&nbsp;

We now have an endpoint named T1HelpDesk. Ok, lets get those permissions set and test. To do this we will use the <a href="https://msdn.microsoft.com/en-us/powershell/reference/4.0/microsoft.powershell.core/set-pssessionconfiguration">Set-PSSessionConfiguration </a>cmdlet and adding the -ShowSecurityDescriptorUI switch parameter will give us the UI to add users/groups and set permissions for them. I am adding both Read(Get,Enumerate,Subscribe) and Execute(Invoke) so that my user can run the commands he has access to. You will need to understand what permissions do what to ensure you are giving just the ones to do the job at hand. You may also be prompted after clicking on to restart WinRM which is required for the changes to take affect.

&nbsp;

<a href="https://msdnshared.blob.core.windows.net/media/2017/05/SecurityUI1.png"><img width="1024" height="466" class="size-large wp-image-555 alignnone" alt="securityui" src="https://msdnshared.blob.core.windows.net/media/2017/05/SecurityUI1-1024x466.png" /></a>

Time of truth, let's test and see what we get!

<a href="https://msdnshared.blob.core.windows.net/media/2017/05/Final.png"><img width="1024" height="485" class="size-large wp-image-566 alignnone" alt="final" src="https://msdnshared.blob.core.windows.net/media/2017/05/Final-1024x485.png" />
</a>

&nbsp;

I tried to remote in from my SumPiGi account &lt;alter ego math wiz..&gt; and as you see above, I cannot enter a interactive session directly. I must first pass the -ConfigurationName that I have been granted access to, "T1HelpDesk" in this case. Then once I am in, I run a Get-Command to see what I can do. The only cmdlet I get access to at this point is Get-Date which is the only one I defined in the -VisibleCmdlets for the New-PSSessionConfigurationFile. I also get a few others by default due to the LanguageMode I choose to allow Exit-PSSession, Get-Help, etc..

There will be more to come on other methods and practices to help secure your environment. Everyone's approach and configuration will always be different, you have to sit down and make a plan, understand what privileges your admins/users need to do their jobs. Environments change as well, what works today may not be what you need tomorrow so adaptation is very important. Monitoring and understanding your environment is an continually ongoing evolution.

Happy Scripting!

&nbsp;

&nbsp;]]></content:encoded>
    </item>
    <item>
      <title>OneDrive SDK, OAuth, Client Authentication, in Consumer space with C# in a UWP application.</title>
      <link>https://docs.microsoft.com/archive/blogs/thbrown/onedrive-sdk-oauth-client-authentication-in-consumer-space-with-c-in-a-uwp-application</link>
      <pubDate>Tue, 14 Jun 2016 02:05:45 GMT</pubDate>
      <dc:creator><![CDATA[Theo Browning]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.technet.microsoft.com/thbrown/?p=325</guid>
      <description><![CDATA[I set out on this example technically to get OneNote access which in turn requires OneDrive access...]]></description>
      <content:encoded><![CDATA[I set out on this example technically to get OneNote access which in turn requires OneDrive access as that is where OneNote documents live. I quickly found myself in a forest surrounded by old documentation and about 95% of it leads to using the deprecated Microsoft Live SDK. There are now <a href="https://dev.onedrive.com/SDKs.htm" target="_blank">OneDrive SDK</a>'s for several platforms that employ a new way to connect and authenticate to OneDrive. I will be focusing on C# inside a UWP app as there is little documentation out there on this with almost no code examples for the OneDrive Consumer side for implementation. There are a few on OneDrive for Business and registering your app through Azure Active Directory and they can be found here: <a href="https://github.com/OneDrive/onedrive-sdk-csharp" target="_blank">OneDrive SDK for CSharp</a>.

Now, I am not going to get into explaining how OAuth works, if you want that then read here: <a href="https://oauth.net/2/" target="_blank">https://oauth.net/2/</a>. This is going to be a straight forward step by step example to get you setup and ready to code your app. So, with that said let's get started.

1. The first thing we need to do is pick a name for our app and then register it to get a clientId, that is done at the <a href="https://apps.dev.microsoft.com/#/appList" target="_blank">Application Registration Portal</a>.

You'll need to click "Add an app" in the Live SDK applications section.

<a href="https://msdnshared.blob.core.windows.net/media/2016/06/step1a.png"><img class="alignnone size-large wp-image-365" src="https://msdnshared.blob.core.windows.net/media/2016/06/step1a-1024x232.png" alt="step1a" width="1024" height="232" /></a>

&nbsp;

When this completes it will take you to the client application screen where you will see information like your Client Id and Client Secret.

2. Next click "Add Platform" for UWP we are going to choose the "Mobile Application" platform.

Once this is done, you should be viewing a screen like below:

<a href="https://msdnshared.blob.core.windows.net/media/2016/06/step2.png"><img class="alignnone size-large wp-image-355" src="https://msdnshared.blob.core.windows.net/media/2016/06/step2-1024x358.png" alt="step2" width="1024" height="358" /></a>

3. Now make note of the Client Id and the Redirect URI as you will need those once we start writing code, for mobile the URI will be: https://login.live.com/oauth20_desktop.srf

&nbsp;

4. Now, create your UWP application in Visual Studio and name it as you did on the registration page.

<a href="https://msdnshared.blob.core.windows.net/media/2016/06/step3.png"><img class="alignnone size-large wp-image-396" src="https://msdnshared.blob.core.windows.net/media/2016/06/step3-1024x711.png" alt="step3" width="1024" height="711" /></a>

&nbsp;

5. Next open the NuGet package manager or go to GitHub and install the <a href="https://github.com/OneDrive/onedrive-sdk-csharp">Microsoft.OneDriveSDK</a>.

<a href="https://msdnshared.blob.core.windows.net/media/2016/06/step4.png"><img class="alignnone size-full wp-image-406" src="https://msdnshared.blob.core.windows.net/media/2016/06/step4.png" alt="step4" width="697" height="343" /></a>

&nbsp;

6. Ok, time for some code!

Here is the simple xaml I am using for the demo, 2 buttons and a textbox (keep it simple and learn).

&nbsp;

<!-- HTML generated using hilite.me -->
<div style="background: #f8f8f8;overflow: auto;width: auto;border: solid gray;border-width: .1em .1em .1em .8em;padding: .2em .6em">
<pre style="margin: 0;line-height: 125%"><span style="color: #008000;font-weight: bold">&lt;Grid&gt;</span>
        <span style="color: #008000;font-weight: bold">&lt;Button</span> <span style="color: #7d9029">x:Name=</span><span style="color: #ba2121">"btn_Login"</span> <span style="color: #7d9029">Content=</span><span style="color: #ba2121">"Sign In"</span> <span style="color: #7d9029">Background=</span><span style="color: #ba2121">"AliceBlue"</span>  
                <span style="color: #7d9029">Foreground=</span><span style="color: #ba2121">"DarkBlue"</span> <span style="color: #7d9029">FontSize=</span><span style="color: #ba2121">"12"</span> <span style="color: #7d9029">FontWeight=</span><span style="color: #ba2121">"Bold"</span> <span style="color: #7d9029">Click=</span><span style="color: #ba2121">"btn_Login_Click"</span>  
                <span style="color: #7d9029">VerticalAlignment=</span><span style="color: #ba2121">"Top"</span> <span style="color: #7d9029">Margin=</span><span style="color: #ba2121">"29,19,0,0"</span> <span style="color: #008000;font-weight: bold">/&gt;</span>
        
        <span style="color: #008000;font-weight: bold">&lt;Button</span> <span style="color: #7d9029">x:Name=</span><span style="color: #ba2121">"btn_GetDriveId"</span> <span style="color: #7d9029">Content=</span><span style="color: #ba2121">"Get Drive Id"</span> <span style="color: #7d9029">Background=</span><span style="color: #ba2121">"AliceBlue"</span> 
                <span style="color: #7d9029">Foreground=</span><span style="color: #ba2121">"DarkBlue"</span> <span style="color: #7d9029">FontSize=</span><span style="color: #ba2121">"12"</span> <span style="color: #7d9029">FontWeight=</span><span style="color: #ba2121">"Bold"</span> <span style="color: #7d9029">Click=</span><span style="color: #ba2121">"btn_GetDriveId_Click"</span>  
                <span style="color: #7d9029">VerticalAlignment=</span><span style="color: #ba2121">"Top"</span> <span style="color: #7d9029">HorizontalAlignment=</span><span style="color: #ba2121">"Right"</span> <span style="color: #7d9029">Margin=</span><span style="color: #ba2121">"0,19,29,0"</span> <span style="color: #7d9029">Visibility=</span><span style="color: #ba2121">"Collapsed"</span><span style="color: #008000;font-weight: bold">/&gt;</span>
        
        <span style="color: #008000;font-weight: bold">&lt;TextBox</span> <span style="color: #7d9029">x:Name=</span><span style="color: #ba2121">"txtBox_Response"</span> <span style="color: #7d9029">Height=</span><span style="color: #ba2121">"500"</span> <span style="color: #7d9029">Width=</span><span style="color: #ba2121">"300"</span> <span style="color: #7d9029">FontSize=</span><span style="color: #ba2121">"12"</span><span style="color: #008000;font-weight: bold">/&gt;</span>
    <span style="color: #008000;font-weight: bold">&lt;/Grid&gt;</span>
</pre>
</div>
&nbsp;

And here is the C#, again this example is to simply show authentication.

&nbsp;

<!-- HTML generated using hilite.me -->
<div style="background: #f8f8f8;overflow: auto;width: auto;border: solid gray;border-width: .1em .1em .1em .8em;padding: .2em .6em">
<pre style="margin: 0;line-height: 125%"><span style="color: #008000;font-weight: bold">using</span> <span style="color: #0000ff;font-weight: bold">Microsoft.OneDrive.Sdk</span>;
<span style="color: #008000;font-weight: bold">using</span> <span style="color: #0000ff;font-weight: bold">System</span>;
<span style="color: #008000;font-weight: bold">using</span> <span style="color: #0000ff;font-weight: bold">System.Collections.Generic</span>;
<span style="color: #008000;font-weight: bold">using</span> <span style="color: #0000ff;font-weight: bold">System.IO</span>;
<span style="color: #008000;font-weight: bold">using</span> <span style="color: #0000ff;font-weight: bold">System.Linq</span>;
<span style="color: #008000;font-weight: bold">using</span> <span style="color: #0000ff;font-weight: bold">System.Runtime.InteropServices.WindowsRuntime</span>;
<span style="color: #008000;font-weight: bold">using</span> <span style="color: #0000ff;font-weight: bold">System.Text</span>;
<span style="color: #008000;font-weight: bold">using</span> <span style="color: #0000ff;font-weight: bold">Windows.Foundation</span>;
<span style="color: #008000;font-weight: bold">using</span> <span style="color: #0000ff;font-weight: bold">Windows.Foundation.Collections</span>;
<span style="color: #008000;font-weight: bold">using</span> <span style="color: #0000ff;font-weight: bold">Windows.UI.Xaml</span>;
<span style="color: #008000;font-weight: bold">using</span> <span style="color: #0000ff;font-weight: bold">Windows.UI.Xaml.Controls</span>;
<span style="color: #008000;font-weight: bold">using</span> <span style="color: #0000ff;font-weight: bold">Windows.UI.Xaml.Controls.Primitives</span>;
<span style="color: #008000;font-weight: bold">using</span> <span style="color: #0000ff;font-weight: bold">Windows.UI.Xaml.Data</span>;
<span style="color: #008000;font-weight: bold">using</span> <span style="color: #0000ff;font-weight: bold">Windows.UI.Xaml.Input</span>;
<span style="color: #008000;font-weight: bold">using</span> <span style="color: #0000ff;font-weight: bold">Windows.UI.Xaml.Media</span>;
<span style="color: #008000;font-weight: bold">using</span> <span style="color: #0000ff;font-weight: bold">Windows.UI.Xaml.Navigation</span>;

<span style="color: #408080;font-style: italic">// The Blank Page item template is documented at https://go.microsoft.com/fwlink/?LinkId=402352&amp;clcid=0x409</span>

<span style="color: #008000;font-weight: bold">namespace</span> <span style="color: #0000ff;font-weight: bold">OneDriveConnectSample</span>
{
    <span style="color: #408080;font-style: italic">/// &lt;summary&gt;</span>
    <span style="color: #408080;font-style: italic">/// An empty page that can be used on its own or navigated to within a Frame.</span>
    <span style="color: #408080;font-style: italic">/// &lt;/summary&gt;</span>
    <span style="color: #008000;font-weight: bold">public</span> <span style="color: #008000;font-weight: bold">sealed</span> <span style="color: #008000;font-weight: bold">partial</span> <span style="color: #008000;font-weight: bold">class</span> <span style="color: #0000ff;font-weight: bold">MainPage</span> : Page
    {
        <span style="color: #408080;font-style: italic">// Client Apication Id.</span>
        <span style="color: #008000;font-weight: bold">private</span> <span style="color: #b00040">string</span> clientId = <span style="color: #ba2121">"YourClientIdHere"</span>;

        <span style="color: #408080;font-style: italic">// Return url.</span>
        <span style="color: #008000;font-weight: bold">private</span> <span style="color: #b00040">string</span> returnUrl = <span style="color: #ba2121">"https://login.live.com/oauth20_desktop.srf"</span>;

        <span style="color: #408080;font-style: italic">// Define the permission scopes.</span>
        <span style="color: #008000;font-weight: bold">private</span> <span style="color: #008000;font-weight: bold">static</span> <span style="color: #008000;font-weight: bold">readonly</span> <span style="color: #b00040">string</span>[] scopes = <span style="color: #008000;font-weight: bold">new</span> <span style="color: #b00040">string</span>[] {
            <span style="color: #ba2121">"onedrive.readwrite"</span>, <span style="color: #ba2121">"offline_access"</span>, <span style="color: #ba2121">"wl.signin"</span>, <span style="color: #ba2121">"wl.basic"</span> };

        <span style="color: #408080;font-style: italic">// Create the OneDriveClient interface.</span>
        <span style="color: #008000;font-weight: bold">private</span> IOneDriveClient oneDriveClient { <span style="color: #008000;font-weight: bold">get</span>; <span style="color: #008000;font-weight: bold">set</span>; }

        <span style="color: #008000;font-weight: bold">public</span> <span style="color: #0000ff">MainPage</span>()
        {
            <span style="color: #008000;font-weight: bold">this</span>.InitializeComponent();
        }

        <span style="color: #008000;font-weight: bold">private</span> <span style="color: #008000;font-weight: bold">async</span> <span style="color: #008000;font-weight: bold">void</span> <span style="color: #0000ff">btn_Login_Click</span>(<span style="color: #b00040">object</span> sender, RoutedEventArgs e)
        {
            <span style="color: #008000;font-weight: bold">if</span> (<span style="color: #008000;font-weight: bold">this</span>.oneDriveClient == <span style="color: #008000;font-weight: bold">null</span>)
            {
                <span style="color: #008000;font-weight: bold">try</span>
                {
                    <span style="color: #408080;font-style: italic">// Setting up the client here, passing in our Client Id, Return Url, </span>
                    <span style="color: #408080;font-style: italic">// Scopes that we want permission to, and building a Web Broker to </span>
                    <span style="color: #408080;font-style: italic">// go do our authentication. </span>
                    <span style="color: #008000;font-weight: bold">this</span>.oneDriveClient = <span style="color: #008000;font-weight: bold">await</span> OneDriveClient.GetAuthenticatedMicrosoftAccountClient(
                        clientId,
                        returnUrl,
                        scopes,
                        webAuthenticationUi: <span style="color: #008000;font-weight: bold">new</span> WebAuthenticationBrokerWebAuthenticationUi());

                    <span style="color: #408080;font-style: italic">// Show in text box that we are connected.</span>
                    txtBox_Response.Text = <span style="color: #ba2121">"We are now connected."</span>;

                    <span style="color: #408080;font-style: italic">// We are either just autheticated and connected or we already connected, </span>
                    <span style="color: #408080;font-style: italic">// either way we need the drive button now.</span>
                    btn_GetDriveId.Visibility = Visibility.Visible;
                }
                <span style="color: #008000;font-weight: bold">catch</span> (OneDriveException exception)
                {
                    <span style="color: #408080;font-style: italic">// Eating the authentication cancelled exceptions and resetting our client. </span>
                    <span style="color: #008000;font-weight: bold">if</span> (!exception.IsMatch(OneDriveErrorCode.AuthenticationCancelled.ToString()))
                    {
                        <span style="color: #008000;font-weight: bold">if</span> (exception.IsMatch(OneDriveErrorCode.AuthenticationFailure.ToString()))
                        {
                            txtBox_Response.Text = <span style="color: #ba2121">"Authentication failed/cancelled, disposing of the client..."</span>;

                            ((OneDriveClient)<span style="color: #008000;font-weight: bold">this</span>.oneDriveClient).Dispose();
                            <span style="color: #008000;font-weight: bold">this</span>.oneDriveClient = <span style="color: #008000;font-weight: bold">null</span>;
                        }
                        <span style="color: #008000;font-weight: bold">else</span>
                        {
                            <span style="color: #408080;font-style: italic">// Or we failed due to someother reason, let get that exception printed out.</span>
                            txtBox_Response.Text = exception.Error.ToString();
                        }
                    }
                    <span style="color: #008000;font-weight: bold">else</span>
                    {
                        ((OneDriveClient)<span style="color: #008000;font-weight: bold">this</span>.oneDriveClient).Dispose();
                        <span style="color: #008000;font-weight: bold">this</span>.oneDriveClient = <span style="color: #008000;font-weight: bold">null</span>;
                    }
                }
            }
        }

        <span style="color: #008000;font-weight: bold">private</span> <span style="color: #008000;font-weight: bold">async</span> <span style="color: #008000;font-weight: bold">void</span> <span style="color: #0000ff">btn_GetDriveId_Click</span>(<span style="color: #b00040">object</span> sender, RoutedEventArgs e)
        {
            <span style="color: #008000;font-weight: bold">if</span> (<span style="color: #008000;font-weight: bold">this</span>.oneDriveClient != <span style="color: #008000;font-weight: bold">null</span> &amp;&amp; <span style="color: #008000;font-weight: bold">this</span>.oneDriveClient.IsAuthenticated == <span style="color: #008000;font-weight: bold">true</span>)
            {
                <span style="color: #b00040">var</span> drive = <span style="color: #008000;font-weight: bold">await</span> <span style="color: #008000;font-weight: bold">this</span>.oneDriveClient.Drive.Request().GetAsync();
                txtBox_Response.Text = drive.Id.ToString();
            }
            <span style="color: #008000;font-weight: bold">else</span>
            {
                txtBox_Response.Text = <span style="color: #ba2121">"We should never get here..."</span>;
            }
            
        }
    }
}
</pre>
</div>
Once you have the code the app will work just like below:

<a href="https://msdnshared.blob.core.windows.net/media/2016/06/Start1.png"><img class="alignnone wp-image-435 " src="https://msdnshared.blob.core.windows.net/media/2016/06/Start1-170x300.png" alt="Start1" width="162" height="286" /></a> <a href="https://msdnshared.blob.core.windows.net/media/2016/06/Auth11.png"><img class="alignnone wp-image-415 " src="https://msdnshared.blob.core.windows.net/media/2016/06/Auth11-169x300.png" alt="Auth1" width="161" height="285" /></a> <a href="https://msdnshared.blob.core.windows.net/media/2016/06/Auth21.png"><img class="alignnone wp-image-425 " src="https://msdnshared.blob.core.windows.net/media/2016/06/Auth21-168x300.png" alt="Auth2" width="160" height="286" /></a> <a href="https://msdnshared.blob.core.windows.net/media/2016/06/Start2.png"><img class="alignnone  wp-image-445" src="https://msdnshared.blob.core.windows.net/media/2016/06/Start2-170x300.png" alt="Start2" width="162" height="286" /></a> <a href="https://msdnshared.blob.core.windows.net/media/2016/06/Start3.png"><img class="alignnone  wp-image-455" src="https://msdnshared.blob.core.windows.net/media/2016/06/Start3-168x300.png" alt="Start3" width="160" height="286" /></a>

&nbsp;

&nbsp;

The project is available at GitHub DevPFE / OneDriveConnectSample:

<a href="https://github.com/DevPFE/OneDriveConnectSample#onedriveconnectsample">https://github.com/DevPFE/OneDriveConnectSample#onedriveconnectsample</a>

&nbsp;

Here is reference and good information in this area that are relevant reads:

&nbsp;

SDKs for OneDrive integration:

<a href="https://dev.onedrive.com/SDKs.htm">https://dev.onedrive.com/SDKs.htm</a>

&nbsp;

Develop with the OneDrive API:

<a href="https://dev.onedrive.com/README.htm">https://dev.onedrive.com/README.htm</a>

&nbsp;

OneDrive authentication and sign-in:

<a href="https://dev.onedrive.com/auth/msa_oauth.htm">https://dev.onedrive.com/auth/msa_oauth.htm</a>

&nbsp;

OneDrive SDK for CSharp on GitHub:

<a href="https://github.com/OneDrive/onedrive-sdk-csharp">https://github.com/OneDrive/onedrive-sdk-csharp</a>

&nbsp;

WebAuthenticationBroker class:

<a href="https://msdn.microsoft.com/en-us/library/windows/apps/windows.security.authentication.web.webauthenticationbroker.aspx">https://msdn.microsoft.com/en-us/library/windows/apps/windows.security.authentication.web.webauthenticationbroker.aspx</a>

&nbsp;

Happy coding!

&nbsp;]]></content:encoded>
    </item>
    <item>
      <title>Netduino Servo Control in NETMF 4.2 / 4.3.x</title>
      <link>https://docs.microsoft.com/archive/blogs/thbrown/netduino-servo-control-in-netmf-4-2-4-3-x</link>
      <pubDate>Tue, 16 Feb 2016 21:24:40 GMT</pubDate>
      <dc:creator><![CDATA[Theo Browning]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.technet.microsoft.com/thbrown/2016/02/16/netduino-servo-control-in-netmf-4-2-4-3-x/</guid>
      <description><![CDATA[So you been looking for some code that actually works with the Netduino 4.3.x&nbsp;&amp; up&nbsp;to...]]></description>
      <content:encoded><![CDATA[<p>So you been looking for some code that actually works with the Netduino 4.3.x&nbsp;&amp; up&nbsp;to control a servo, well now you have found it. I credit&nbsp;most of the code here&nbsp;thanks to Chris Seto from back in 2010 posted&nbsp;on the <a href="https://forums.netduino.com/index.php?/topic/160-netduino-servo-class/" target="_blank">Netduino forum</a>&nbsp;and it worked great on the 4.0-4.1 framework! However, a lot has changed since then like PMW.SetPulse doesn&#039;t exist&nbsp;and now when instantiating a new PMW it requires a PMWChannel and not a Pin as an argument plus a few more required parameters. So, I took what Chris wrote and modified it to fit the current framework and implemented those changes. I do not get into the nitty gritty of explaining the changes here, this is just a implementation and share post. If you want a deeper dive just ask in the comments and maybe if there are enough I will come back to that. For the rest that want to consume, here&nbsp;you go, enjoy:</p>
<pre style="color:#565656"><span style="color:#57a64a">/*
 * Servo NETMF Driver
 *	Coded by Chris Seto August 2010
 *	&lt;chris@chrisseto.com&gt; 
 *	
 * Use this code for whatever you want. Modify it, redistribute it, I don&#039;t care.
 * I do ask that you please keep this header intact, however.
 * If you modify the driver, please include your contribution below:
 * 
 * Chris Seto: Initial release (1.0)
 * Chris Seto: Netduino port (1.0 -&gt; Netduino branch)
 * Chris Seto: bool pin state fix (1.1 -&gt; Netduino branch)
 * 
 * Theo Browning: Release (2.0) modified to work with current framework.
 * 
 * */</span><span style="color:#569cd6">

using</span> System;
<span style="color:#569cd6">using</span> Microsoft<span style="color:#575757">.</span>SPOT;
<span style="color:#569cd6">using</span> Microsoft<span style="color:#575757">.</span>SPOT<span style="color:#575757">.</span>Hardware;
<span style="color:#569cd6">using</span> SecretLabs<span style="color:#575757">.</span>NETMF<span style="color:#575757">.</span>Hardware;
<span style="color:#569cd6">using</span> SecretLabs<span style="color:#575757">.</span>NETMF<span style="color:#575757">.</span>Hardware<span style="color:#575757">.</span>Netduino;


<span style="color:#569cd6">namespace</span> NetduinoApplication1
{
    <span style="color:#569cd6">public class</span><span style="color:#4ec9b0"> ServoController</span> : <span style="color:#b8d7a3">IDisposable</span>
    {
        <span style="color:#57a64a">/// &lt;summary&gt;
        /// PWM handle
        /// &lt;/summary&gt;</span><span style="color:#569cd6">
        private</span><span style="color:#4ec9b0"> PWM</span> servo;

        <span style="color:#57a64a">/// &lt;summary&gt;
        /// Timings range
        /// &lt;/summary&gt;      </span><span style="color:#569cd6">
        private int</span>[] range <span style="color:#575757">=</span><span style="color:#569cd6"> new int</span>[<span style="color:#555555">2</span>];

        <span style="color:#57a64a">/// &lt;summary&gt;
        /// Set servo inversion
        /// &lt;/summary&gt;    </span><span style="color:#569cd6">
        public bool</span> inverted <span style="color:#575757">=</span><span style="color:#569cd6"> false</span>;

        <span style="color:#57a64a">/// &lt;summary&gt;
        /// Create the PWM Channel, set it low and configure timings
        /// Changes here PWM Channel requires Channel, Period, Duration, 
        /// Scale and Inversion on instantiation.
        /// &lt;/summary&gt;
        /// &lt;param name=</span><span style="color:#c8c8c8">&quot;pwmChannel&quot;</span><span style="color:#57a64a">&gt;&lt;/param&gt;</span><span style="color:#569cd6">
        public</span> ServoController()
        {
            <span style="color:#57a64a">// Initialize the PWM Channel, set to pin 5 as default.            </span>
            servo <span style="color:#575757">=</span><span style="color:#569cd6"> new</span><span style="color:#4ec9b0"> PWM</span>(
                <span style="color:#4ec9b0">PWMChannels</span><span style="color:#575757">.</span>PWM_PIN_D5, 
                <span style="color:#555555">20000</span>, 
                <span style="color:#555555">1500</span>, 
                Microsoft<span style="color:#575757">.</span>SPOT<span style="color:#575757">.</span>Hardware<span style="color:#575757">.</span><span style="color:#4ec9b0">PWM</span><span style="color:#575757">.</span><span style="color:#b8d7a3">ScaleFactor</span><span style="color:#575757">.</span>Microseconds, 
                <span style="color:#569cd6">false</span>);

            <span style="color:#57a64a">// Full range for FS90 servo is 0 - 3000.
            // For safety limits I set the default just above/below that.</span>
            range[<span style="color:#555555">0</span>] <span style="color:#575757">=</span><span style="color:#555555"> 600</span>;
            range[<span style="color:#555555">1</span>] <span style="color:#575757">=</span><span style="color:#555555"> 2400</span>;
        }

        <span style="color:#57a64a">/// &lt;summary&gt;
        /// Allow for consumer to set own range.
        /// &lt;/summary&gt;
        /// &lt;param name=</span><span style="color:#c8c8c8">&quot;leftStop&quot;</span><span style="color:#57a64a">, </span><span style="color:#c8c8c8">&quot;rightStop&quot;</span><span style="color:#57a64a">&gt;&lt;/param&gt;</span><span style="color:#569cd6">
        public void</span> SetRange(<span style="color:#569cd6">int</span> leftStop, <span style="color:#569cd6">int</span> rightStop)
        {
            range[<span style="color:#555555">1</span>] <span style="color:#575757">=</span> leftStop;
            range[<span style="color:#555555">0</span>] <span style="color:#575757">=</span> rightStop;
        }

        <span style="color:#57a64a">/// &lt;summary&gt;
        /// Dispose implementation.
        /// &lt;/summary&gt;</span><span style="color:#569cd6">
        public void</span> Dispose()
        {
            Disengage();
            servo<span style="color:#575757">.</span>Dispose();
        }

        <span style="color:#57a64a">/// &lt;summary&gt;
        /// Disengage the servo. 
        /// The servo motor will stop, and try to maintain an angle
        /// &lt;/summary&gt;</span><span style="color:#569cd6">
        public void</span> Disengage()
        {            
            servo<span style="color:#575757">.</span>DutyCycle <span style="color:#575757">=</span><span style="color:#555555"> 0</span>; <span style="color:#57a64a">//SetDutyCycle(0);</span>
        }


        <span style="color:#57a64a">/// &lt;summary&gt;
        /// Set the servo degree
        /// &lt;/summary&gt;</span><span style="color:#569cd6">
        public double</span> Degree
        {
            <span style="color:#569cd6">set</span>
            {
                <span style="color:#57a64a">/// Range checks</span><span style="color:#569cd6">
                if</span> (<span style="color:#569cd6">value</span><span style="color:#575757"> &gt;</span><span style="color:#555555"> 180</span>)
                    <span style="color:#569cd6">value</span><span style="color:#575757"> =</span><span style="color:#555555"> 180</span>;

                <span style="color:#569cd6">if</span> (<span style="color:#569cd6">value</span><span style="color:#575757"> &lt;</span><span style="color:#555555"> 0</span>)
                    <span style="color:#569cd6">value</span><span style="color:#575757"> =</span><span style="color:#555555"> 0</span>;

                <span style="color:#57a64a">// Are we inverted?</span><span style="color:#569cd6">
                if</span> (inverted)
                    <span style="color:#569cd6">value</span><span style="color:#575757"> =</span><span style="color:#555555"> 180</span><span style="color:#575757"> -</span><span style="color:#569cd6"> value</span>;

                <span style="color:#57a64a">// Set duration &quot;pulse&quot; and start the servo. <br />                // Changes here are PWM.Duration and PWM.Start() instead of PWM.SetPulse().                </span>
                servo<span style="color:#575757">.</span>Duration <span style="color:#575757">=</span> (<span style="color:#569cd6">uint</span>)map((<span style="color:#569cd6">long</span>)<span style="color:#569cd6">value</span>, <span style="color:#555555">0</span>, <span style="color:#555555">180</span>, range[<span style="color:#555555">0</span>], range[<span style="color:#555555">1</span>]);
                servo<span style="color:#575757">.</span>Start();
            }
        }

        <span style="color:#57a64a">/// &lt;summary&gt;
        /// Used internally to map a value of one scale to another
        /// &lt;/summary&gt;
        /// &lt;param name=</span><span style="color:#c8c8c8">&quot;x&quot;</span><span style="color:#57a64a">&gt;&lt;/param&gt;
        /// &lt;param name=</span><span style="color:#c8c8c8">&quot;in_min&quot;</span><span style="color:#57a64a">&gt;&lt;/param&gt;
        /// &lt;param name=</span><span style="color:#c8c8c8">&quot;in_max&quot;</span><span style="color:#57a64a">&gt;&lt;/param&gt;
        /// &lt;param name=</span><span style="color:#c8c8c8">&quot;out_min&quot;</span><span style="color:#57a64a">&gt;&lt;/param&gt;
        /// &lt;param name=</span><span style="color:#c8c8c8">&quot;out_max&quot;</span><span style="color:#57a64a">&gt;&lt;/param&gt;
        /// &lt;returns&gt;&lt;/returns&gt;</span><span style="color:#569cd6">

        private long</span> map(<span style="color:#569cd6">long</span> x, <span style="color:#569cd6">long</span> in_min, <span style="color:#569cd6">long</span> in_max, <span style="color:#569cd6">long</span> out_min, <span style="color:#569cd6">long</span> out_max)
        {
            <span style="color:#569cd6">return</span> (x <span style="color:#575757">-</span> in_min) <span style="color:#575757">*</span> (out_max <span style="color:#575757">-</span> out_min) <span style="color:#575757">/</span> (in_max <span style="color:#575757">-</span> in_min) <span style="color:#575757">+</span> out_min;
        }
    }
}</pre>
<p></p>
<p>That&#039;s the class, now here is just a simple example of implementation, the following will infinite loop a servo to full left/right motion. Get past the infinite loop and the sleep as well as this is for simplicity, I would implement a timer and a condition if this were for&nbsp;real application.&nbsp;We can come back and talk about timers in NETMF another time as they are a whole different animal than timers in the full .Net Framework (post in comments if you would like to see more on timers).</p>
<p></p>
<pre style="color:#565656"><span style="color:#569cd6"> public static void</span> Main()
        {   
            <span style="color:#4ec9b0">ServoController</span> servo <span style="color:#575757">=</span><span style="color:#569cd6"> new</span><span style="color:#4ec9b0"> ServoController</span>();

            servo<span style="color:#575757">.</span>SetRange(<span style="color:#555555">500</span>, <span style="color:#555555">2400</span>);

            <span style="color:#569cd6">bool</span> runForever <span style="color:#575757">=</span><span style="color:#569cd6"> true</span>;

            <span style="color:#569cd6">while</span> (runForever)
            {
                <span style="color:#569cd6">for</span> (<span style="color:#569cd6">int</span> i <span style="color:#575757">=</span><span style="color:#555555"> 1</span>; i <span style="color:#575757">&lt;</span><span style="color:#555555"> 179</span>; i<span style="color:#575757">++</span>)
                {
                    servo<span style="color:#575757">.</span>Degree <span style="color:#575757">=</span> i;
                    <span style="color:#4ec9b0">Thread</span><span style="color:#575757">.</span>Sleep(<span style="color:#555555">25</span>);
                }

                <span style="color:#569cd6">for</span> (<span style="color:#569cd6">int</span> i <span style="color:#575757">=</span><span style="color:#555555"> 179</span>; i <span style="color:#575757">&gt;</span><span style="color:#555555"> 1</span>; i<span style="color:#575757">--</span>)
                {
                    servo<span style="color:#575757">.</span>Degree <span style="color:#575757">=</span> i;
                    <span style="color:#4ec9b0">Thread</span><span style="color:#575757">.</span>Sleep(<span style="color:#555555">25</span>);
                }
            }

            servo<span style="color:#575757">.</span>Dispose();
        }</pre>
<p>Enjoy and I hope this saves you some time!</p>]]></content:encoded>
    </item>
    <item>
      <title>Azure Blob now has append!!!</title>
      <link>https://docs.microsoft.com/archive/blogs/thbrown/azure-blob-now-has-append</link>
      <pubDate>Wed, 26 Aug 2015 07:34:00 GMT</pubDate>
      <dc:creator><![CDATA[Theo Browning]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.technet.microsoft.com/thbrown/2015/08/26/azure-blob-now-has-append/</guid>
      <description><![CDATA[So just a&nbsp;couple of weeks ago we introduced&nbsp;the new&nbsp;&quot;Append Blob&quot; into the...]]></description>
      <content:encoded><![CDATA[<p>So just a&nbsp;couple of weeks ago we introduced&nbsp;the new&nbsp;&quot;Append Blob&quot; into the mix in the Windows.AzureStorage&nbsp;.Net client library in version 5. If you read the <a title="MSDN Understanding Block Blobs, Append Blobs, and Page Blobs" href="https://msdn.microsoft.com/en-us/library/azure/ee691964.aspx" target="_blank">MSDN</a>&nbsp;page on it, it states the following:</p>
<p>[</p>
<p>An append blob is comprised of blocks and is optimized for append operations. When you modify an append blob, blocks are added to the end of the blob only, via the <a href="https://msdn.microsoft.com/en-us/library/azure/mt427365.aspx">Append Block</a> operation. Updating or deleting of existing blocks is not supported. Unlike a block blob, an append blob does not expose its block IDs.</p>
<p>Each block in an append blob can be a different size, up to a maximum of 4 MB, and an append blob can include up to 50,000 blocks. The maximum size of an append blob is therefore slightly more than 195 GB (4 MB X 50,000 blocks).</p>
<p>]</p>
<p>So what does that mean to us as developers, what can we do with this new found awesomeness called an AppendBlob???&nbsp; Let&#039;s say you had a blob that was a text file and you were writing events to it (logging). &nbsp;When you wanted to&nbsp;add something&nbsp;to&nbsp;that blob you had to download it, read it into a stream or something,&nbsp;add to it, and then upload it to overwrite the old blob. With&nbsp;AppendBlob all this work is now done for you and there&nbsp;is even some other checking and functionality added as well. Let&#039;s write some code and take a look.&nbsp;&nbsp;&nbsp;</p>
<p></p>
<pre style="background:white;color:black;font-family:Consolas;font-size:13px"><span style="color:blue"><span style="color:#339966">// Using statements for our libraries.</span><br />using</span>&nbsp;Microsoft.WindowsAzure.Storage;
<span style="color:blue">using</span>&nbsp;Microsoft.WindowsAzure.Storage.Auth;
<span style="color:blue">using</span>&nbsp;Microsoft.WindowsAzure.Storage.Blob;
<span style="color:blue">using</span>&nbsp;System;
<span style="color:blue">using</span>&nbsp;System.Collections.Generic;
<span style="color:blue">using</span>&nbsp;System.Configuration;
 
<span style="color:blue">namespace</span>&nbsp;AzureAppendBlobSample
{
&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:blue">class</span>&nbsp;<span style="color:#2b91af">Program</span>
&nbsp;&nbsp;&nbsp;&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:blue">static</span>&nbsp;<span style="color:blue">void</span>&nbsp;Main(<span style="color:blue">string</span>[]&nbsp;args)
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:green">//&nbsp;Let&#039;s&nbsp;set&nbsp;up&nbsp;our&nbsp;connection&nbsp;for&nbsp;the&nbsp;account&nbsp;and&nbsp;store&nbsp;the&nbsp;name&nbsp;and&nbsp;key&nbsp;in&nbsp;app.config.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:blue">string</span>&nbsp;accName&nbsp;=&nbsp;<span style="color:#2b91af">ConfigurationManager</span>.AppSettings[<span style="color:#a31515">&quot;StrAccName&quot;</span>];
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:blue">string</span>&nbsp;accKey&nbsp;=&nbsp;<span style="color:#2b91af">ConfigurationManager</span>.AppSettings[<span style="color:#a31515">&quot;StrAccKey&quot;</span>];
 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:green">//&nbsp;Implement&nbsp;the&nbsp;accout,&nbsp;set&nbsp;true&nbsp;for&nbsp;https&nbsp;for&nbsp;SSL.</span>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#2b91af">StorageCredentials</span>&nbsp;creds&nbsp;=&nbsp;<span style="color:blue">new</span>&nbsp;<span style="color:#2b91af">StorageCredentials</span>(accName,&nbsp;accKey);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#2b91af">CloudStorageAccount</span>&nbsp;strAcc&nbsp;=&nbsp;<span style="color:blue">new</span>&nbsp;<span style="color:#2b91af">CloudStorageAccount</span>(creds,&nbsp;<span style="color:blue">true</span>);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#2b91af">CloudBlobClient</span>&nbsp;blobClient&nbsp;=&nbsp;strAcc.CreateCloudBlobClient();
 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:green">//Setup&nbsp;our&nbsp;container&nbsp;we&nbsp;are&nbsp;going&nbsp;to&nbsp;use&nbsp;and&nbsp;create&nbsp;it.</span>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#2b91af">CloudBlobContainer</span>&nbsp;container&nbsp;=&nbsp;blobClient.GetContainerReference(<span style="color:#a31515">&quot;logs&quot;</span>);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;container.CreateIfNotExistsAsync();
 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:green">//&nbsp;Build&nbsp;my&nbsp;typical&nbsp;log&nbsp;file&nbsp;name.</span>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#2b91af">DateTime</span>&nbsp;date&nbsp;=&nbsp;<span style="color:#2b91af">DateTime</span>.Today;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#2b91af">DateTime</span>&nbsp;dateLogEntry&nbsp;=&nbsp;<span style="color:#2b91af">DateTime</span>.Now;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:green">//&nbsp;This&nbsp;creates&nbsp;a&nbsp;reference&nbsp;to&nbsp;the&nbsp;append&nbsp;blob&nbsp;we&nbsp;are&nbsp;going&nbsp;to&nbsp;use.</span>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#2b91af">CloudAppendBlob</span>&nbsp;appBlob&nbsp;=&nbsp;container.GetAppendBlobReference(
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:blue">string</span>.Format(<span style="color:#a31515">&quot;{0}{1}&quot;</span>,&nbsp;date.ToString(<span style="color:#a31515">&quot;yyyyMMdd&quot;</span>),&nbsp;<span style="color:#a31515">&quot;.log&quot;</span>));
 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:green">//&nbsp;Now&nbsp;we&nbsp;are&nbsp;going&nbsp;to&nbsp;check&nbsp;if&nbsp;todays&nbsp;file&nbsp;exists&nbsp;and&nbsp;if&nbsp;it&nbsp;doesn&#039;t&nbsp;we&nbsp;create&nbsp;it.</span>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:blue">if</span>&nbsp;(!appBlob.Exists())
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;appBlob.CreateOrReplace();
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}
 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:green">//&nbsp;Add&nbsp;the&nbsp;entry&nbsp;to&nbsp;our&nbsp;log.</span>
 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;appBlob.AppendText(
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:blue">string</span>.Format(
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#a31515">&quot;{0}&nbsp;|&nbsp;Error:&nbsp;Something&nbsp;went&nbsp;wrong&nbsp;and&nbsp;we&nbsp;had&nbsp;to&nbsp;write&nbsp;to&nbsp;the&nbsp;log!!!\r\n&quot;</span>,
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;dateLogEntry.ToString(<span style="color:#a31515">&quot;o&quot;</span>)));
 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:green">//&nbsp;Now&nbsp;lets&nbsp;pull&nbsp;down&nbsp;our&nbsp;file&nbsp;and&nbsp;see&nbsp;what&nbsp;it&nbsp;looks&nbsp;like.</span>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#2b91af">Console</span>.WriteLine(appBlob.DownloadText());
 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:green">//&nbsp;Hold&nbsp;the&nbsp;console&nbsp;open.</span>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#2b91af">Console</span>.WriteLine(<span style="color:#a31515">&quot;Press&nbsp;any&nbsp;key&nbsp;to&nbsp;continue&quot;</span>);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#2b91af">Console</span>.ReadKey();
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}
&nbsp;&nbsp;&nbsp;&nbsp;}
}
</pre>
<p></p>
<p>And here is the output of running the above code on the 6th run. As you can see there are entries time stamped over about 1 minute duration. This is great for logging of many kinds and tons of other applications to be able to just update the blob just like you would a text file on disk. However, if I were logging many&nbsp;events per/sec per/min or I wanted to search quick and easy,&nbsp;then I would look at using something else like Table storage instead (blog coming soon).</p>
<p><a href="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/prod.evol.blogs.technet.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/00/74/80/ConsoleOutput.PNG"><img alt=" " src="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/prod.evol.blogs.technet.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/00/74/80/ConsoleOutput.PNG" border="0" /></a></p>
<p></p>
<p>Keys to remember about an append blob:</p>
<p>You cannot edit, modify, change, update (whatever word you want to use) the existing blocks of the blob. You can ONLY append to the end of the blob.</p>
<p>Max entries to an append blob &quot;from my testing&quot;, are about&nbsp;5-6 per second. I have tested this several times&nbsp;with a&nbsp;max entries loop (50,0000) to a single append blob. The best ways to handle this limitation would be to queue up the messages and then append them to the blob in chunks instead of singular appends.&nbsp;</p>
<p>With that said, an append blob has a max of 50,000 blocks at a max of 4mb each.</p>
<p>Here are some of the append methods:</p>
<p><a href="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/prod.evol.blogs.technet.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/00/74/80/Code03.PNG"><img alt=" " src="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/prod.evol.blogs.technet.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/00/74/80/Code03.PNG" border="0" /></a></p>
<p></p>
<p>And last but not least, here is the referencing documentation:</p>
<p></p>
<p>CloudStorageAccount Class</p>
<p><a href="https://msdn.microsoft.com/en-us/library/azure/microsoft.windowsazure.storage.cloudstorageaccount.aspx">https://msdn.microsoft.com/en-us/library/azure/microsoft.windowsazure.storage.cloudstorageaccount.aspx</a></p>
<p></p>
<p>StorageCredentials Class</p>
<p><a href="https://msdn.microsoft.com/en-us/library/azure/microsoft.windowsazure.storage.auth.storagecredentials.aspx">https://msdn.microsoft.com/en-us/library/azure/microsoft.windowsazure.storage.auth.storagecredentials.aspx</a></p>
<p></p>
<p>CloudBlobClient Class</p>
<p><a href="https://msdn.microsoft.com/en-us/library/azure/microsoft.windowsazure.storage.blob.cloudblobclient.aspx">https://msdn.microsoft.com/en-us/library/azure/microsoft.windowsazure.storage.blob.cloudblobclient.aspx</a></p>
<p></p>
<p>CloudBlobContainer Class</p>
<p><a href="https://msdn.microsoft.com/en-us/library/azure/microsoft.windowsazure.storage.blob.cloudblobcontainer.aspx">https://msdn.microsoft.com/en-us/library/azure/microsoft.windowsazure.storage.blob.cloudblobcontainer.aspx</a></p>
<p></p>
<p>CloudAppendBlob Class</p>
<p>&quot;Coming Soon&quot; but the constructors should look like:</p>
<p></p>
<table id="idConstructors">
<tbody>
<tr><th class="iconColumn"></th><th class="nameColumn">Name</th><th class="descriptionColumn">Description</th></tr>
<tr>
<td><span><img title="System_CAPS_pubmethod" id="s-e6f6a65cf14f462597b64ac058dbe1d0-system-media-system-caps-pubmethod" alt="System_CAPS_pubmethod" src="https://i-msdn.sec.s-msft.com/dynimg/IC91302.jpeg" /></span></td>
<td>CloudAppendBlob<span>(Uri)</span></td>
<td>
<div class="section">
<p>Initializes a new instance of the CloudAppendBlob<span></span> class using an absolute URI to the blob.</p>
</div>
</td>
</tr>
<tr>
<td><span><img title="System_CAPS_pubmethod" id="s-e6f6a65cf14f462597b64ac058dbe1d0-system-media-system-caps-pubmethod" alt="System_CAPS_pubmethod" src="https://i-msdn.sec.s-msft.com/dynimg/IC91302.jpeg" /></span></td>
<td>CloudAppendBlob<span>(Uri, StorageCredentials)</span></td>
<td>
<div class="section">
<p>Initializes a new instance of the CloudAppendBlob<span></span> class using an absolute URI to the blob.</p>
</div>
</td>
</tr>
<tr>
<td><span><img title="System_CAPS_pubmethod" id="s-e6f6a65cf14f462597b64ac058dbe1d0-system-media-system-caps-pubmethod" alt="System_CAPS_pubmethod" src="https://i-msdn.sec.s-msft.com/dynimg/IC91302.jpeg" /></span></td>
<td>CloudAppendBlob<span>(Uri,&nbsp;Nullable&lt;DateTimeOffset&gt;,&nbsp;StorageCredentials)</span></td>
<td>
<div class="section">
<p>Initializes a new instance of the CloudAppendBlob<span></span> class using an absolute URI to the blob.</p>
</div>
</td>
</tr>
<tr>
<td><span><img title="System_CAPS_pubmethod" id="s-e6f6a65cf14f462597b64ac058dbe1d0-system-media-system-caps-pubmethod" alt="System_CAPS_pubmethod" src="https://i-msdn.sec.s-msft.com/dynimg/IC91302.jpeg" /></span></td>
<td>CloudAppendBlob<span>(StorageUri,&nbsp;Nullable&lt;DateTimeOffset&gt;,&nbsp;StorageCredentials)</span></td>
<td>
<div class="section">
<p>Initializes a new instance of the CloudAppendBlob<span></span> class using an absolute URI to the blob.</p>
</div>
</td>
</tr>
</tbody>
</table>
<p></p>
<p></p>
<p>Happy Coding!</p>]]></content:encoded>
    </item>
    <item>
      <title>Properties and backing fields over public member variables.</title>
      <link>https://docs.microsoft.com/archive/blogs/thbrown/properties-and-backing-fields-over-public-member-variables</link>
      <pubDate>Mon, 22 Jun 2015 00:44:07 GMT</pubDate>
      <dc:creator><![CDATA[Theo Browning]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.technet.microsoft.com/thbrown/2015/06/22/properties-and-backing-fields-over-public-member-variables/</guid>
      <description><![CDATA[As we start our journeys&nbsp;to&nbsp;understanding&nbsp;the basics of programming&nbsp;and...]]></description>
      <content:encoded><![CDATA[<p>As we start our journeys&nbsp;to&nbsp;understanding&nbsp;the basics of programming&nbsp;and development, one of the things we learn about are variables. A variable is simply the declaration of various&nbsp;data types that define and point to a&nbsp;storage area. We use variables&nbsp;in various places in our code, for reference, manipulation, and other operations. One of those places are in classes. Classes give us a format or a blueprint to use as the design for the objects we create. As we are creating these blueprints we define our data types and methods or operations this object will have. Theses are our member definitions and what brings use to topic of the day.</p>
<p>Lets take a look at some code:</p>
<p><a href="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/prod.evol.blogs.technet.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/00/74/80/4861.Class1.PNG" original-url="https://blogs.technet.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-74-80/4861.Class1.PNG"><img alt=" " src="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/prod.evol.blogs.technet.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/00/74/80/4861.Class1.PNG" original-url="https://blogs.technet.com/resized-image.ashx/__size/550x401/__key/communityserver-blogs-components-weblogfiles/00-00-00-74-80/4861.Class1.PNG" border="0" /></a></p>
<p></p>
<p>We first define a class named Person, within it some member definitions.&nbsp;The first of those definitions are member variables, we declare a string and int called &quot;name&quot; and &quot;age&quot; respectively. Next, we create a override to the default&nbsp;constructor,&nbsp;it&nbsp;requires a string and int as arguments and it uses those to set the public member variables to the&nbsp;supplied values.&nbsp;Lastly we create a&nbsp;member method that writes a string to the console with our person&#39;s name and age injected.</p>
<p>This all works&nbsp;fine and well however, let&#39;s take a peak at what could happen if someone was consuming our code. Keep in mind this is the simplest of examples meant to show a point.</p>
<p><a href="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/prod.evol.blogs.technet.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/00/74/80/3426.Program1.PNG" original-url="https://blogs.technet.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-74-80/3426.Program1.PNG"><img alt=" " src="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/prod.evol.blogs.technet.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/00/74/80/3426.Program1.PNG" original-url="https://blogs.technet.com/resized-image.ashx/__size/550x401/__key/communityserver-blogs-components-weblogfiles/00-00-00-74-80/3426.Program1.PNG" border="0" /></a></p>
<p></p>
<p>First we create a new object of the Person class type and we pass Suzy for the name and 23 for the age. Added to our constructor, is the first call to Talk() so we do not have to call it, as you can see in the command prompt console it displays with Suzy and 23&nbsp;correctly. Next&nbsp;we&nbsp;access the &quot;name&quot; member variable off of p1&nbsp;and change it to Joe. We can do this because we defined it&nbsp;as public&nbsp;which sets it&#39;s access level to full throughout the program or a consumer. You can see&nbsp;it show up on intelliSense as well:</p>
<p><a href="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/prod.evol.blogs.technet.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/00/74/80/Program2.PNG" original-url="https://blogs.technet.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-74-80/Program2.PNG"><img width="229" height="175" style="border-color:currentColor;" alt=" " src="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/prod.evol.blogs.technet.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/00/74/80/Program2.PNG" original-url="https://blogs.technet.com/resized-image.ashx/__size/306x234/__key/communityserver-blogs-components-weblogfiles/00-00-00-74-80/Program2.PNG" /></a></p>
<p></p>
<p><span style="color:black;font-family:&#39;Arial&#39;,sans-serif;font-size:9pt;">Using Properties and Backing Fields, referred to as &quot;Getters and Setters&quot;&nbsp;is the way around this and the proper way to control / encapsulate your variables. Using encapsulation (Getters &amp; Setters) you can restrict access,&nbsp;perform various checks, or many other operations on the data as your class requires before allowing or denying the modification. There are a several ways to do this, let&#39;s discuss the automagic way. Auto-Implemented, when we use this method the compiler uses some syntactic sugar for us and creates&nbsp;a backing field (private variable) so it saves us a bit of typing. The Getter &amp; Setter control the access to those backing fields and is up to us to define that. In the example below, I left the Getter to public (default) and I set the Setter to private so that it can only be accessed through the class. Take note the default here is opposite of what you get when you define variables and methods, the default for those are private unless defined otherwise.</span></p>
<p><span style="color:black;font-family:&#39;Arial&#39;,sans-serif;font-size:9pt;">&nbsp;</span></p>
<p><span style="color:black;font-family:&#39;Arial&#39;,sans-serif;font-size:9pt;"><a href="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/prod.evol.blogs.technet.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/00/74/80/Class2.PNG" original-url="https://blogs.technet.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-74-80/Class2.PNG"><img alt=" " src="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/prod.evol.blogs.technet.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/00/74/80/Class2.PNG" original-url="https://blogs.technet.com/resized-image.ashx/__size/550x487/__key/communityserver-blogs-components-weblogfiles/00-00-00-74-80/Class2.PNG" border="0" /></a><br /></span></p>
<p></p>
<p>We can also create a method in our class that modifies&nbsp;the values if we like, but again, we are controlling when and where these values are able to be accessed and modified.</p>
<p><a href="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/prod.evol.blogs.technet.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/00/74/80/Method1.PNG" original-url="https://blogs.technet.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-74-80/Method1.PNG"><img alt=" " src="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/prod.evol.blogs.technet.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/00/74/80/Method1.PNG" original-url="https://blogs.technet.com/resized-image.ashx/__size/357x120/__key/communityserver-blogs-components-weblogfiles/00-00-00-74-80/Method1.PNG" border="0" /></a></p>
<p></p>
<p>Or we could create a Factory method to do it all for us.</p>
<p><a href="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/prod.evol.blogs.technet.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/00/74/80/Factory1.PNG" original-url="https://blogs.technet.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-74-80/Factory1.PNG"><img alt=" " src="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/prod.evol.blogs.technet.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/00/74/80/Factory1.PNG" original-url="https://blogs.technet.com/resized-image.ashx/__size/531x150/__key/communityserver-blogs-components-weblogfiles/00-00-00-74-80/Factory1.PNG" border="0" /></a></p>
<p>So you see, we have much more control over our variables this way and can perform many other operations in a controlled manner. If we don&#39;t&nbsp;want them accessed at all we simply only implement a&nbsp;Getter and no we code&nbsp;without the worry of something getting changed in our class that would have an undesired effect (BUG!).</p>
<p></p>
<p>Happy coding!</p>]]></content:encoded>
    </item>
  </channel>
</rss>