<?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>normand - my spot on technet</title>
    <atom:link
      href="https://docs.microsoft.com/archive/blogs/normand/feed.xml"
      rel="self"
      type="application/rss+xml" />
    <link>https://docs.microsoft.com/archive/blogs/normand/feed.xml</link>
    <description>$AutomateThisAndThat and other interesting stuff</description>
    <lastBuildDate>Wed, 17 Apr 2019 03:30:04 GMT</lastBuildDate>
    <language>en-US</language>
    <sy:updatePeriod>hourly</sy:updatePeriod>
    <sy:updateFrequency>1</sy:updateFrequency>
    <item>
      <title>Consuming the POST request data from EMIE for Internet Explorer 11</title>
      <link>https://docs.microsoft.com/archive/blogs/normand/consuming-the-post-request-data-from-emie-for-internet-explorer-11</link>
      <pubDate>Tue, 02 Dec 2014 11:09:03 GMT</pubDate>
      <dc:creator><![CDATA[Norman Drews]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.technet.microsoft.com/normand/2014/12/02/consuming-the-post-request-data-from-emie-for-internet-explorer-11/</guid>
      <description><![CDATA[&nbsp; Everyone should know by now that come January 12, 2016 Microsoft will provide limited support...]]></description>
      <content:encoded><![CDATA[<p>&nbsp;</p> <p>Everyone should know by now that come January 12, 2016 Microsoft will provide <a href="https://blogs.msdn.com/b/ie/archive/2014/08/07/stay-up-to-date-with-internet-explorer.aspx" target="_blank">limited support</a> for browser versions earlier than 11. That means Enterprise customers should <font color="#ff0000" size="3"><u><strong>really</strong></u></font><font color="#000000"> </font>consider upgrading to version 11. The above link will show you the support versions. </p> <p>I&#39;m assuming you are well on your way to setting up your group policy objects to push out the following policies:</p> <h6><a href="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/prod.evol.blogs.technet.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/00/92/21/metablogapi/GPO_766CB031.png" original-url="https://blogs.technet.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-92-21-metablogapi/GPO_5F00_766CB031.png"><img title="GPO" style="border-left-width:0px;border-right-width:0px;background-image:none;border-bottom-width:0px;padding-top:0px;padding-left:0px;display:inline;padding-right:0px;border-top-width:0px;" border="0" alt="GPO" src="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/prod.evol.blogs.technet.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/00/92/21/metablogapi/GPO_thumb_1F774F2E.png" original-url="https://blogs.technet.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-92-21-metablogapi/GPO_5F00_thumb_5F00_1F774F2E.png" width="795" height="350" /></a></h6> <h6>&nbsp;</h6> <p> <hr />  <p>This post will focus on how to better consume what goes in text box below…. It is the policy above. If you don&#39;t see any of these options make sure you&#39;ve installed the latest Internet Explorer onto the server or retrieve the templates from <a href="https://www.microsoft.com/en-us/download/details.aspx?id=40905" target="_blank">here</a>.</p> <p><a href="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/prod.evol.blogs.technet.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/00/92/21/metablogapi/Policy_59F4DFB3.png" original-url="https://blogs.technet.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-92-21-metablogapi/Policy_5F00_59F4DFB3.png"><img title="Policy" style="border-left-width:0px;border-right-width:0px;background-image:none;border-bottom-width:0px;padding-top:0px;padding-left:0px;display:inline;padding-right:0px;border-top-width:0px;" border="0" alt="Policy" src="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/prod.evol.blogs.technet.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/00/92/21/metablogapi/Policy_thumb_2E4415B7.png" original-url="https://blogs.technet.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-92-21-metablogapi/Policy_5F00_thumb_5F00_2E4415B7.png" width="792" height="579" /></a></p> <p>&nbsp;</p> <p>Enterprise Mode for Internet Explorer will send a POST request to pretty much anything that can accept it. Most examples show a simple POST and reference to a web server. In this case you just need to look up the entry in the IIS log file and voila there you have it. </p> <p>My problem is that, even with a handy tool such as the old-school Log Parser, while you can get the results, it isn&#39;t a nice format. I&#39;d rather store the data inside of a database. </p> <p>&nbsp;<br />Follow these steps in any order you want… It is the end result that really matters….</p> <h4>Step One – Configure SQL Server</h4> <p>I&#39;m using SQL Server 2012, but any recent one should work without a problem. You should ask your DBA if you are uncertain as to managing your SQL Server. We need to create a database, table, and stored procedure</p> <h6>Database Creation Script</h6><pre class="csharpcode"><font size="1"><span class="kwrd">USE</span> [master]
<span class="kwrd">GO</span>

/****** <span class="kwrd">Object</span>:  <span class="kwrd">Database</span> [EMReporting]    Script <span class="kwrd">Date</span>: 11/26/2014 2:54:09 PM ******/
<span class="kwrd">CREATE</span> <span class="kwrd">DATABASE</span> [EMReporting]
 CONTAINMENT = <span class="kwrd">NONE</span>
 <span class="kwrd">ON</span>  <span class="kwrd">PRIMARY</span> 
( NAME = N<span class="str">&#39;EMReporting&#39;</span>, <br />FILENAME = N<span class="str">&#39;C:\Program Files\Microsoft SQL Server\MSSQL11.MSSQLSERVER\MSSQL\DATA\EMReporting.mdf&#39;</span> , <br /><span class="kwrd">SIZE</span> = 4096KB , MAXSIZE = UNLIMITED, FILEGROWTH = 1024KB )
 LOG <span class="kwrd">ON</span> 
( NAME = N<span class="str">&#39;EMReporting_log&#39;</span>, <br />FILENAME = N<span class="str">&#39;C:\Program Files\Microsoft SQL Server\MSSQL11.MSSQLSERVER\MSSQL\DATA\EMReporting_log.ldf&#39;</span> , <br /><span class="kwrd">SIZE</span> = 1024KB , MAXSIZE = 2048GB , FILEGROWTH = 10%)
<span class="kwrd">GO</span>

<span class="kwrd">ALTER</span> <span class="kwrd">DATABASE</span> [EMReporting] <span class="kwrd">SET</span> COMPATIBILITY_LEVEL = 110
<span class="kwrd">GO</span>

<span class="kwrd">IF</span> (1 = FULLTEXTSERVICEPROPERTY(<span class="str">&#39;IsFullTextInstalled&#39;</span>))
<span class="kwrd">begin</span>
<span class="kwrd">EXEC</span> [EMReporting].[dbo].[sp_fulltext_database] @<span class="kwrd">action</span> = <span class="str">&#39;enable&#39;</span>
<span class="kwrd">end</span>
<span class="kwrd">GO</span>

<span class="kwrd">ALTER</span> <span class="kwrd">DATABASE</span> [EMReporting] <span class="kwrd">SET</span> ANSI_NULL_DEFAULT <span class="kwrd">OFF</span> 
<span class="kwrd">GO</span>

<span class="kwrd">ALTER</span> <span class="kwrd">DATABASE</span> [EMReporting] <span class="kwrd">SET</span> ANSI_NULLS <span class="kwrd">OFF</span> 
<span class="kwrd">GO</span>

<span class="kwrd">ALTER</span> <span class="kwrd">DATABASE</span> [EMReporting] <span class="kwrd">SET</span> ANSI_PADDING <span class="kwrd">OFF</span> 
<span class="kwrd">GO</span>

<span class="kwrd">ALTER</span> <span class="kwrd">DATABASE</span> [EMReporting] <span class="kwrd">SET</span> ANSI_WARNINGS <span class="kwrd">OFF</span> 
<span class="kwrd">GO</span>

<span class="kwrd">ALTER</span> <span class="kwrd">DATABASE</span> [EMReporting] <span class="kwrd">SET</span> ARITHABORT <span class="kwrd">OFF</span> 
<span class="kwrd">GO</span>

<span class="kwrd">ALTER</span> <span class="kwrd">DATABASE</span> [EMReporting] <span class="kwrd">SET</span> AUTO_CLOSE <span class="kwrd">OFF</span> 
<span class="kwrd">GO</span>

<span class="kwrd">ALTER</span> <span class="kwrd">DATABASE</span> [EMReporting] <span class="kwrd">SET</span> AUTO_CREATE_STATISTICS <span class="kwrd">ON</span> 
<span class="kwrd">GO</span>

<span class="kwrd">ALTER</span> <span class="kwrd">DATABASE</span> [EMReporting] <span class="kwrd">SET</span> AUTO_SHRINK <span class="kwrd">OFF</span> 
<span class="kwrd">GO</span>

<span class="kwrd">ALTER</span> <span class="kwrd">DATABASE</span> [EMReporting] <span class="kwrd">SET</span> AUTO_UPDATE_STATISTICS <span class="kwrd">ON</span> 
<span class="kwrd">GO</span>

<span class="kwrd">ALTER</span> <span class="kwrd">DATABASE</span> [EMReporting] <span class="kwrd">SET</span> CURSOR_CLOSE_ON_COMMIT <span class="kwrd">OFF</span> 
<span class="kwrd">GO</span>

<span class="kwrd">ALTER</span> <span class="kwrd">DATABASE</span> [EMReporting] <span class="kwrd">SET</span> CURSOR_DEFAULT  <span class="kwrd">GLOBAL</span> 
<span class="kwrd">GO</span>

<span class="kwrd">ALTER</span> <span class="kwrd">DATABASE</span> [EMReporting] <span class="kwrd">SET</span> CONCAT_NULL_YIELDS_NULL <span class="kwrd">OFF</span> 
<span class="kwrd">GO</span>

<span class="kwrd">ALTER</span> <span class="kwrd">DATABASE</span> [EMReporting] <span class="kwrd">SET</span> NUMERIC_ROUNDABORT <span class="kwrd">OFF</span> 
<span class="kwrd">GO</span>

<span class="kwrd">ALTER</span> <span class="kwrd">DATABASE</span> [EMReporting] <span class="kwrd">SET</span> QUOTED_IDENTIFIER <span class="kwrd">OFF</span> 
<span class="kwrd">GO</span>

<span class="kwrd">ALTER</span> <span class="kwrd">DATABASE</span> [EMReporting] <span class="kwrd">SET</span> RECURSIVE_TRIGGERS <span class="kwrd">OFF</span> 
<span class="kwrd">GO</span>

<span class="kwrd">ALTER</span> <span class="kwrd">DATABASE</span> [EMReporting] <span class="kwrd">SET</span>  DISABLE_BROKER 
<span class="kwrd">GO</span>

<span class="kwrd">ALTER</span> <span class="kwrd">DATABASE</span> [EMReporting] <span class="kwrd">SET</span> AUTO_UPDATE_STATISTICS_ASYNC <span class="kwrd">OFF</span> 
<span class="kwrd">GO</span>

<span class="kwrd">ALTER</span> <span class="kwrd">DATABASE</span> [EMReporting] <span class="kwrd">SET</span> DATE_CORRELATION_OPTIMIZATION <span class="kwrd">OFF</span> 
<span class="kwrd">GO</span>

<span class="kwrd">ALTER</span> <span class="kwrd">DATABASE</span> [EMReporting] <span class="kwrd">SET</span> TRUSTWORTHY <span class="kwrd">OFF</span> 
<span class="kwrd">GO</span>

<span class="kwrd">ALTER</span> <span class="kwrd">DATABASE</span> [EMReporting] <span class="kwrd">SET</span> ALLOW_SNAPSHOT_ISOLATION <span class="kwrd">OFF</span> 
<span class="kwrd">GO</span>

<span class="kwrd">ALTER</span> <span class="kwrd">DATABASE</span> [EMReporting] <span class="kwrd">SET</span> PARAMETERIZATION SIMPLE 
<span class="kwrd">GO</span>

<span class="kwrd">ALTER</span> <span class="kwrd">DATABASE</span> [EMReporting] <span class="kwrd">SET</span> READ_COMMITTED_SNAPSHOT <span class="kwrd">OFF</span> 
<span class="kwrd">GO</span>

<span class="kwrd">ALTER</span> <span class="kwrd">DATABASE</span> [EMReporting] <span class="kwrd">SET</span> HONOR_BROKER_PRIORITY <span class="kwrd">OFF</span> 
<span class="kwrd">GO</span>

<span class="kwrd">ALTER</span> <span class="kwrd">DATABASE</span> [EMReporting] <span class="kwrd">SET</span> RECOVERY <span class="kwrd">FULL</span> 
<span class="kwrd">GO</span>

<span class="kwrd">ALTER</span> <span class="kwrd">DATABASE</span> [EMReporting] <span class="kwrd">SET</span>  MULTI_USER 
<span class="kwrd">GO</span>

<span class="kwrd">ALTER</span> <span class="kwrd">DATABASE</span> [EMReporting] <span class="kwrd">SET</span> PAGE_VERIFY CHECKSUM  
<span class="kwrd">GO</span>

<span class="kwrd">ALTER</span> <span class="kwrd">DATABASE</span> [EMReporting] <span class="kwrd">SET</span> DB_CHAINING <span class="kwrd">OFF</span> 
<span class="kwrd">GO</span>

<span class="kwrd">ALTER</span> <span class="kwrd">DATABASE</span> [EMReporting] <span class="kwrd">SET</span> FILESTREAM( NON_TRANSACTED_ACCESS = <span class="kwrd">OFF</span> ) 
<span class="kwrd">GO</span>

<span class="kwrd">ALTER</span> <span class="kwrd">DATABASE</span> [EMReporting] <span class="kwrd">SET</span> TARGET_RECOVERY_TIME = 0 SECONDS 
<span class="kwrd">GO</span>

<span class="kwrd">ALTER</span> <span class="kwrd">DATABASE</span> [EMReporting] <span class="kwrd">SET</span>  READ_WRITE 
<span class="kwrd">GO</span></font>
</pre>


<h6>Table Creation Script</h6>
<p><pre class="csharpcode"><font size="1"><span class="kwrd">USE</span> [EMReporting]
<span class="kwrd">GO</span>

/****** <span class="kwrd">Object</span>:  <span class="kwrd">Table</span> [dbo].[EMIntervention]    Script <span class="kwrd">Date</span>: 11/26/2014 2:54:52 PM ******/
<span class="kwrd">SET</span> ANSI_NULLS <span class="kwrd">ON</span>
<span class="kwrd">GO</span>

<span class="kwrd">SET</span> QUOTED_IDENTIFIER <span class="kwrd">ON</span>
<span class="kwrd">GO</span>

<span class="kwrd">CREATE</span> <span class="kwrd">TABLE</span> [dbo].[EMIntervention](
    [Id] [<span class="kwrd">int</span>] <span class="kwrd">IDENTITY</span>(1,1) <span class="kwrd">NOT</span> <span class="kwrd">NULL</span>,
    [status] [<span class="kwrd">nchar</span>](3) <span class="kwrd">NULL</span>,
    [referrer] [nvarchar](<span class="kwrd">max</span>) <span class="kwrd">NULL</span>,
    [username] [nvarchar](50) <span class="kwrd">NULL</span>,
    [ipaddress] [nvarchar](50) <span class="kwrd">NULL</span>,
    [<span class="kwrd">timestamp</span>] [datetime] <span class="kwrd">NULL</span>,
 <span class="kwrd">CONSTRAINT</span> [PK_EMIntervention] <span class="kwrd">PRIMARY</span> <span class="kwrd">KEY</span> <span class="kwrd">CLUSTERED</span> 
(
    [Id] <span class="kwrd">ASC</span>
)<span class="kwrd">WITH</span> (PAD_INDEX = <span class="kwrd">OFF</span>, STATISTICS_NORECOMPUTE = <span class="kwrd">OFF</span>, IGNORE_DUP_KEY = <span class="kwrd">OFF</span>, ALLOW_ROW_LOCKS = <span class="kwrd">ON</span>, ALLOW_PAGE_LOCKS = <span class="kwrd">ON</span>) <br /><span class="kwrd">ON</span> [<span class="kwrd">PRIMARY</span>]
) <span class="kwrd">ON</span> [<span class="kwrd">PRIMARY</span>] TEXTIMAGE_ON [<span class="kwrd">PRIMARY</span>]

<span class="kwrd">GO</span></font></pre>


<h6>Stored Procedure Creation Script</h6>
<p><pre class="csharpcode"><font size="1"><span class="kwrd">USE</span> [EMReporting]
<span class="kwrd">GO</span>

/****** <span class="kwrd">Object</span>:  StoredProcedure [dbo].[InsertIntoTable]    Script <span class="kwrd">Date</span>: 11/26/2014 2:55:17 PM ******/
<span class="kwrd">SET</span> ANSI_NULLS <span class="kwrd">ON</span>
<span class="kwrd">GO</span>

<span class="kwrd">SET</span> QUOTED_IDENTIFIER <span class="kwrd">ON</span>
<span class="kwrd">GO</span>


<span class="kwrd">CREATE</span> <span class="kwrd">PROCEDURE</span> [dbo].[InsertIntoTable]
(
    @status <span class="kwrd">nchar</span>(3) = <span class="kwrd">NULL</span>,
    @referrer nvarchar(<span class="kwrd">MAX</span>) = <span class="kwrd">NULL</span>,
    @username nvarchar(50) = <span class="kwrd">NULL</span>,
    @ipaddress nvarchar(50) = <span class="kwrd">NULL</span>,
    @<span class="kwrd">timestamp</span> datetime
)
<span class="kwrd">AS</span>
    <span class="kwrd">SET</span> NOCOUNT <span class="kwrd">OFF</span>;
<span class="kwrd">INSERT INTO</span> [EMIntervention] ([status], [referrer], [username], [ipaddress], [timestamp]) </font><font size="1"><br /><span class="kwrd">VALUES</span> (@status, @referrer, @username, @ipaddress, @timestamp);
<span class="kwrd">GO</span></font>

</pre>

<br />
<h4>Step Two – Configure IIS and push below code to web server</h4>
<h6>IIS Configuration</h6>
<p>You should be able to get away with using mostly default settings when you create a new web site. Just ensure these key three things:</p>
<p>1) Disable all authentication (Features View of the site) except for Windows Authentication. Keep it enabled.</p>
<p>2) Ensure the application pool supports the 4. NET Framework. </p>
<p>3) Create firewall exception if you are using a non-default port in the binding. Above I&#39;m pointing to port 8088. </p>
<p>&nbsp;</p>
<h6>Web Application</h6>
<p>The below was written with Visual Studio 2012 (Update 4). </p>
<p>1) Create an empty ASP.Net Web application. </p>
<p>2) Add a new WebForm (mine is called Post.aspx). In the code behind, this is what I wrote inside of the partial class…</p>
<div class="csharpcode"><pre class="alt"><font size="1"><span class="lnum">   1:  </span><span class="kwrd">public</span> <span class="kwrd">struct</span> DataBlock</font></pre><pre><font size="1"><span class="lnum">   2:  </span>{</font></pre><pre class="alt"><font size="1"><span class="lnum">   3:  </span>    <span class="kwrd">public</span> DateTime timestamp { get; set; }</font></pre><pre><font size="1"><span class="lnum">   4:  </span>    <span class="kwrd">public</span> <span class="kwrd">string</span> referrer { get; set; }</font></pre><pre class="alt"><font size="1"><span class="lnum">   5:  </span>    <span class="kwrd">public</span> <span class="kwrd">string</span> user { get; set; }</font></pre><pre><font size="1"><span class="lnum">   6:  </span>    <span class="kwrd">public</span> <span class="kwrd">string</span> ipaddress { get; set; }</font></pre><pre class="alt"><font size="1"><span class="lnum">   7:  </span>    <span class="kwrd">public</span> <span class="kwrd">string</span> status { get; set; }</font></pre><pre><font size="1"><span class="lnum">   8:  </span>}</font></pre><pre class="alt"><font size="1"><span class="lnum">   9:  </span>&nbsp;</font></pre><pre><font size="1"><span class="lnum">  10:  </span><span class="kwrd">protected</span> <span class="kwrd">string</span> GetIPAddress()</font></pre><pre class="alt"><font size="1"><span class="lnum">  11:  </span>{</font></pre><pre><font size="1"><span class="lnum">  12:  </span>    System.Web.HttpContext context = System.Web.HttpContext.Current;</font></pre><pre class="alt"><font size="1"><span class="lnum">  13:  </span>    <span class="kwrd">string</span> ipAddress = context.Request.ServerVariables[<span class="str">&quot;HTTP_X_FORWARDED_FOR&quot;</span>];</font></pre><pre><font size="1"><span class="lnum">  14:  </span>&nbsp;</font></pre><pre class="alt"><font size="1"><span class="lnum">  15:  </span>    <span class="kwrd">if</span> (!<span class="kwrd">string</span>.IsNullOrEmpty(ipAddress))</font></pre><pre><font size="1"><span class="lnum">  16:  </span>    {</font></pre><pre class="alt"><font size="1"><span class="lnum">  17:  </span>        <span class="kwrd">string</span>[] addresses = ipAddress.Split(<span class="str">&#39;,&#39;</span>);</font></pre><pre><font size="1"><span class="lnum">  18:  </span>        <span class="kwrd">if</span> (addresses.Length != 0)</font></pre><pre class="alt"><font size="1"><span class="lnum">  19:  </span>        {</font></pre><pre><font size="1"><span class="lnum">  20:  </span>            <span class="kwrd">return</span> addresses[0];</font></pre><pre class="alt"><font size="1"><span class="lnum">  21:  </span>        }</font></pre><pre><font size="1"><span class="lnum">  22:  </span>    }</font></pre><pre class="alt"><font size="1"><span class="lnum">  23:  </span>&nbsp;</font></pre><pre><font size="1"><span class="lnum">  24:  </span>    <span class="kwrd">return</span> context.Request.ServerVariables[<span class="str">&quot;REMOTE_ADDR&quot;</span>];</font></pre><pre class="alt"><font size="1"><span class="lnum">  25:  </span>}</font></pre><pre><font size="1"><span class="lnum">  26:  </span>&nbsp;</font></pre><pre class="alt"><font size="1"><span class="lnum">  27:  </span>&nbsp;</font></pre><pre><font size="1"><span class="lnum">  28:  </span><span class="kwrd">protected</span> <span class="kwrd">void</span> Page_Load(<span class="kwrd">object</span> sender, EventArgs e)</font></pre><pre class="alt"><font size="1"><span class="lnum">  29:  </span>{</font></pre><pre><font size="1"><span class="lnum">  30:  </span>    DataBlock datablock = <span class="kwrd">new</span> DataBlock();</font></pre><pre class="alt"><font size="1"><span class="lnum">  31:  </span>&nbsp;</font></pre><pre><font size="1"><span class="lnum">  32:  </span>    datablock.timestamp = HttpContext.Current.Timestamp;</font></pre><pre class="alt"><font size="1"><span class="lnum">  33:  </span>    datablock.referrer = Request.Form[<span class="str">&quot;URL&quot;</span>];</font></pre><pre><font size="1"><span class="lnum">  34:  </span>    datablock.status = Request.Form[<span class="str">&quot;EnterpriseMode&quot;</span>];</font></pre><pre class="alt"><font size="1"><span class="lnum">  35:  </span>    datablock.user = Request.LogonUserIdentity.Name;</font></pre><pre><font size="1"><span class="lnum">  36:  </span>    datablock.ipaddress = GetIPAddress();</font></pre><pre class="alt"><font size="1"><span class="lnum">  37:  </span>&nbsp;</font></pre><pre><font size="1"><span class="lnum">  38:  </span>    WriteToSqlServer(datablock);</font></pre><pre class="alt"><font size="1"><span class="lnum">  39:  </span>}</font></pre><pre><font size="1"><span class="lnum">  40:  </span>&nbsp;</font></pre><pre class="alt"><font size="1"><span class="lnum">  41:  </span><span class="kwrd">private</span> <span class="kwrd">void</span> WriteToSqlServer(DataBlock datablock)</font></pre><pre><font size="1"><span class="lnum">  42:  </span>{</font></pre><pre class="alt"><font size="1"><span class="lnum">  43:  </span>    <span class="kwrd">string</span> strConnection = ConfigurationManager.ConnectionStrings[<span class="str">&quot;EMReportingConnectionString&quot;</span>].ConnectionString;</font></pre><pre><font size="1"><span class="lnum">  44:  </span>    <span class="kwrd">using</span> (SqlConnection connection = <span class="kwrd">new</span> SqlConnection(strConnection))</font></pre><pre class="alt"><font size="1"><span class="lnum">  45:  </span>    {</font></pre><pre><font size="1"><span class="lnum">  46:  </span>        connection.Open();</font></pre><pre class="alt"><font size="1"><span class="lnum">  47:  </span>        <span class="kwrd">using</span> (SqlCommand command = <span class="kwrd">new</span> SqlCommand())</font></pre><pre><font size="1"><span class="lnum">  48:  </span>        {</font></pre><pre class="alt"><font size="1"><span class="lnum">  49:  </span>            command.Connection = connection;</font></pre><pre><font size="1"><span class="lnum">  50:  </span>            command.CommandType = CommandType.StoredProcedure;</font></pre><pre class="alt"><font size="1"><span class="lnum">  51:  </span>            command.CommandText = <span class="str">&quot;dbo.InsertIntoTable&quot;</span>;</font></pre><pre><font size="1"><span class="lnum">  52:  </span>            command.Parameters.AddWithValue(<span class="str">&quot;@status&quot;</span>, datablock.status);</font></pre><pre class="alt"><font size="1"><span class="lnum">  53:  </span>            command.Parameters.AddWithValue(<span class="str">&quot;@referrer&quot;</span>, datablock.referrer);</font></pre><pre><font size="1"><span class="lnum">  54:  </span>            command.Parameters.AddWithValue(<span class="str">&quot;@username&quot;</span>, datablock.user);</font></pre><pre class="alt"><font size="1"><span class="lnum">  55:  </span>            command.Parameters.AddWithValue(<span class="str">&quot;@ipaddress&quot;</span>, datablock.ipaddress);</font></pre><pre><font size="1"><span class="lnum">  56:  </span>            command.Parameters.AddWithValue(<span class="str">&quot;@timestamp&quot;</span>, datablock.timestamp);</font></pre><pre class="alt"><font size="1"><span class="lnum">  57:  </span>            command.ExecuteNonQuery();</font></pre><pre><font size="1"><span class="lnum">  58:  </span>        }</font></pre><pre class="alt"><font size="1"><span class="lnum">  59:  </span>    }</font></pre><pre><font size="1"><span class="lnum">  60:  </span>}</font></pre></div>




<p>Here&#39;s a breakdown:</p>
<p><strong>Lines 1-8: </strong>I&#39;m defining a structure for easier usage when passing as a parameter. </p>
<p><strong>Line 10-25: </strong>It is a helper function that returns the client IP. You may want to modify it as you see fit. I&#39;m not using a load balancer in my testing. </p>
<p><strong>Lines 28-39: </strong>It is retrieving information about the request such as IP Address, timestamp, the user name (this is why we have windows authentication enabled) and two interesting ones: <strong><font color="#ff0000">URL</font></strong> and <strong><font color="#ff0000">EnterpriseMode</font></strong>. You can see these two items in the POST body. Below is a screenshot of a Fiddler Inspector called &quot;TextView&quot; from when a user turns off Enterprise Mode for a given site.</p>
<p><a href="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/prod.evol.blogs.technet.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/00/92/21/metablogapi/fiddler_2874EA7E.png" original-url="https://blogs.technet.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-92-21-metablogapi/fiddler_5F00_2874EA7E.png"><img title="fiddler" style="border-left-width:0px;border-right-width:0px;background-image:none;border-bottom-width:0px;padding-top:0px;padding-left:0px;display:inline;padding-right:0px;border-top-width:0px;" border="0" alt="fiddler" src="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/prod.evol.blogs.technet.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/00/92/21/metablogapi/fiddler_thumb_75A4E409.png" original-url="https://blogs.technet.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-92-21-metablogapi/fiddler_5F00_thumb_5F00_75A4E409.png" width="834" height="246" /></a></p>
<p>This information is really useful because the IT Admin can keep track of what sites individual users enabled/disabled (On/Off) Enterprise Mode against. The idea is to ultimately consolidate these findings into the Enterprise Mode Site List. That second policy definition further up in this post (<a href="https://SERVER01:8088/sites.xml">https://SERVER01:8088/sites.xml</a>) OR fix the sites you missed during the initial inventory process. </p>
<p><strong>Lines 41-60:</strong> This code calls a stored procedure that writes the data neatly to a table… It assumes you have a stored procedure called &quot;dbo.Insert&quot;. See Step One – Configure SQL Server. </p>
<p>3) Make sure that your project&#39;s web.config is pointing to the database. I&#39;m using SQL Authentication since I defined a user that has access to the particular database/table. Here is what I am using inside of my web.config file.</p>
<div class="csharpcode"><pre class="alt"><span class="lnum">   1:  </span>&lt;configuration&gt;</pre><pre><span class="lnum">   2:  </span>    &lt;connectionStrings&gt;</pre><pre class="alt"><span class="lnum">   3:  </span>        &lt;add name=<span class="str">&quot;EMReportingConnectionString&quot;</span> connectionString=<span class="str">&quot;Data Source=sqlserver01;Initial Catalog=EMReporting;user id=EMUser;Password=[EnterPasswordHere]&quot;</span></pre><pre><span class="lnum">   4:  </span>            providerName=<span class="str">&quot;System.Data.SqlClient&quot;</span> /&gt;</pre><pre class="alt"><span class="lnum">   5:  </span>    &lt;/connectionStrings&gt;</pre><pre><span class="lnum">   6:  </span>    &lt;system.web&gt;</pre><pre class="alt"><span class="lnum">   7:  </span>      &lt;compilation debug=<span class="str">&quot;true&quot;</span> targetFramework=<span class="str">&quot;4.5&quot;</span> /&gt;</pre><pre><span class="lnum">   8:  </span>      &lt;httpRuntime targetFramework=<span class="str">&quot;4.5&quot;</span> /&gt;</pre><pre class="alt"><span class="lnum">   9:  </span>    &lt;/system.web&gt;</pre><pre><span class="lnum">  10:  </span>&nbsp;</pre><pre class="alt"><span class="lnum">  11:  </span>&lt;/configuration&gt;</pre></div>


<h1>&nbsp;</h1>
<p>4. Deploy the application. I used the built in &quot;Publish&quot; mechanism from within Visual Studio. You just need to make sure the development and target machines have at least <a href="https://www.microsoft.com/en-us/download/details.aspx?id=39277" target="_blank">Web Deploy 3.5</a> installed. </p>
<h1>End Result</h1>
<p>If the code (Step Two) compiled and was deployed properly <strong>AND</strong> you&#39;ve successfully created the database, table, and stored procedure (Step One) <strong>AND</strong> there is a group policy defining where to POST the end user action, you can now focus on the client. </p>
<p>When a client goes to a site and say it looks bad and decided to enable Enterprise Mode via Tools –&gt; Enterprise Mode, EMIE will send a POST to your ASPX page which in turn sends the results via stored procedure into a SQL Table. </p>
<p>You go to the SQL Server and take a look and this is what you get:</p>
<p><a href="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/prod.evol.blogs.technet.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/00/92/21/metablogapi/SQL_05B3B2C1.png" original-url="https://blogs.technet.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-92-21-metablogapi/SQL_5F00_05B3B2C1.png"><img title="SQL" style="border-left-width:0px;border-right-width:0px;background-image:none;border-bottom-width:0px;padding-top:0px;padding-left:0px;display:inline;padding-right:0px;border-top-width:0px;" border="0" alt="SQL" src="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/prod.evol.blogs.technet.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/00/92/21/metablogapi/SQL_thumb_20EC0BC2.png" original-url="https://blogs.technet.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-92-21-metablogapi/SQL_5F00_thumb_5F00_20EC0BC2.png" width="827" height="385" /></a></p>
<p>The sample project and SQL scripts can be downloaded from <a href="https://gallery.technet.microsoft.com/Consuming-the-POST-request-f3abfd40" target="_blank">here</a>.</p></p></p></p>]]></content:encoded>
    </item>
    <item>
      <title>Where art thou my windows user???</title>
      <link>https://docs.microsoft.com/archive/blogs/normand/where-art-thou-my-windows-user</link>
      <pubDate>Wed, 05 Feb 2014 20:31:00 GMT</pubDate>
      <dc:creator><![CDATA[Norman Drews]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.technet.microsoft.com/normand/2014/02/05/where-art-thou-my-windows-user/</guid>
      <description><![CDATA[&nbsp; Scenario Let&#39;s say you are a user logged into a bunch of machines and you suddenly get...]]></description>
      <content:encoded><![CDATA[<p>&nbsp;</p> <h2>Scenario</h2> <p>Let&#39;s say you are a user logged into a bunch of machines and you suddenly get locked out? The problem is you don&#39;t remember all the machines where you are currently logged in! So you call into your company support line and there are a couple things you need them to:</p> <ol> <li>Unlock your AD Account  </li><li>Figure out what machines you are logged into</li></ol> <p>During this session, we are going to show a script example that the support personnel can use to find where you are. I began to think of approaches we could use. Some options include:</p> <ul> <li>Combination of Win32_LogonSession and Win32_LoggedOnUser  </li><li>Look for an explorer.exe process and grab the owner</li></ul> <h2>&nbsp;</h2> <h2>The Idea</h2> <p>I want to keep the script as simple as possible and this isn&#39;t the only approach, but here is an example that will essentially enumerate thru a list of reachable (online) computers in ActiveDirectory and check process ownership of explorer.exe. The output is returned to the screen. Then, if we want, we can log the user out on their behalf.  <h2>&nbsp; </h2> <h2>The final script</h2> <p> <div class="csharpcode"><pre><span class="lnum">   1:  </span>Import-Module -Name ActiveDirectory</pre><pre><span class="lnum">   2:  </span>&nbsp;</pre><pre><span class="lnum">   3:  </span>$computers = Get-ADComputer -Filter * | </pre><pre><span class="lnum">   4:  </span>    Select-Object -ExpandProperty Name</pre><pre><span class="lnum">   5:  </span>&nbsp;</pre><pre><span class="lnum">   6:  </span>$username = <span class="str">&quot;Administrator&quot;</span> </pre><pre><span class="lnum">   7:  </span>&nbsp;</pre><pre><span class="lnum">   8:  </span><span class="rem"># This will return only reacheable machines and store</span></pre><pre><span class="lnum">   9:  </span><span class="rem"># just the destination address</span></pre><pre><span class="lnum">  10:  </span>&nbsp;</pre><pre><span class="lnum">  11:  </span>$params = @{</pre><pre><span class="lnum">  12:  </span>    ComputerName = $computers</pre><pre><span class="lnum">  13:  </span>    Count = 1</pre><pre><span class="lnum">  14:  </span>    ErrorAction = <span class="str">&quot;SilentlyContinue&quot;</span></pre><pre><span class="lnum">  15:  </span>}</pre><pre><span class="lnum">  16:  </span>&nbsp;</pre><pre><span class="lnum">  17:  </span>$reacheable = Test-Connection @params | </pre><pre><span class="lnum">  18:  </span>                Select-Object -ExpandProperty Address</pre><pre><span class="lnum">  19:  </span>&nbsp;</pre><pre><span class="lnum">  20:  </span>$params = @{</pre><pre><span class="lnum">  21:  </span>    Class = <span class="str">&quot;Win32_Process&quot;</span></pre><pre><span class="lnum">  22:  </span>    ComputerName = $reacheable</pre><pre><span class="lnum">  23:  </span>    Filter = <span class="str">&quot;name = &#39;explorer.exe&#39;&quot;</span></pre><pre><span class="lnum">  24:  </span>    Property = <span class="str">&quot;Handle&quot;</span>, <span class="str">&quot;CSName&quot;</span></pre><pre><span class="lnum">  25:  </span>}</pre><pre><span class="lnum">  26:  </span>&nbsp;</pre><pre><span class="lnum">  27:  </span><span class="rem"># Potentially time-consuming as there is no direct</span></pre><pre><span class="lnum">  28:  </span><span class="rem"># property to return a process owner so we&#39;re limited</span></pre><pre><span class="lnum">  29:  </span><span class="rem"># to local Where-Object filtering</span></pre><pre><span class="lnum">  30:  </span>&nbsp;</pre><pre><span class="lnum">  31:  </span>$userIsPresent = Get-WmiObject @params | </pre><pre><span class="lnum">  32:  </span>                    Where-Object { $_.GetOwner().User <span class="preproc">-eq</span> $username } |</pre><pre><span class="lnum">  33:  </span>                        Select-Object -ExpandProperty csname</pre><pre><span class="lnum">  34:  </span>&nbsp;</pre><pre><span class="lnum">  35:  </span><span class="str">&quot;{0} is present on {1}&quot;</span> -f $username, $($userIsPresent -join <span class="str">&quot;, &quot;</span>)</pre></div>


<h2>&nbsp;</h2>
<h2>Let&#39;s break this out into pieces… </h2>
<p><strong>Lines 1-4</strong>: We load the ActiveDirectory module for our lone AD Query (Get-ADComputer). The module you can get via the RSAT tools. Click <a href="https://www.bing.com/search?q=rsat+download+site%3Amicrosoft.com&amp;qs=n&amp;form=QBRE&amp;pq=rsat+download+site%3Amicrosoft.com&amp;sc=8-32&amp;sp=-1&amp;sk=&amp;cvid=bc75b22896e34447996a663089eb8b88">here</a> for where to find them. If you don&#39;t like having a dependency on the AD Module for Windows PowerShell, you can use instead the <a href="https://msdn.microsoft.com/en-us/library/System.DirectoryServices.DirectorySearcher(v=vs.110).aspx">System.DirectoryServices.DirectorySearcher</a> .NET class to do our search for us. </p>
<p><strong>Line 6</strong>: We specify a $username value for purposes of the script. To make it more useable, you can instead get the name from the user using the Read-Host cmdlet. </p>
<p><strong>Line 11-18</strong>: We first check if the machines are online. The quickest way I can see is to use Test-Connection and have it return just the reachable machines. Now, if the machine is offline or unreachable (aka the plug pulled from the network) then there isn&#39;t much we can do about that. The online machines are then stored into a variable called $reacheable.</p>
<p><strong>Line 20-33: </strong>This is the heavy lifting and potentially time-consuming component. We set up our parameters and pass it into the Get-WmiObject using a technique called splatting. Line 24 contains the bare minimum property list that we need for this to work. We could have returned all parameters but this is a tad more friendly on the network. </p>
<p>It basically makes it easier to read especially if we have a large number of parameters we are using. We check the result against our $username variable. There isn&#39;t a built-in property called Owner so what we do is call the GetOwner() method and that returned object has a User property. That is the property we compare against. We then send it further thru the pipeline where we return an array of the computer names we searched and evaluated to true in the Where-Object cmdlet. </p>
<p><strong>Line 35:</strong>&nbsp; We wrap it up by outputting to the user what machines he/she is currently on. </p>
<h2>Hope you find this useful…</h2></p></p>
<p><a href="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/prod.evol.blogs.technet.com/telligent.evolution.components.attachments/01/9221/00/00/03/62/22/02/FindTheUser.zip" original-url="https://blogs.technet.com/cfs-filesystemfile.ashx/__key/telligent-evolution-components-attachments/01-9221-00-00-03-62-22-02/FindTheUser.zip">FindTheUser.zip</a></p>]]></content:encoded>
    </item>
    <item>
      <title>Using FindExecutable - Finding the registered executable given a file path</title>
      <link>https://docs.microsoft.com/archive/blogs/normand/using-findexecutable-finding-the-registered-executable-given-a-file-path</link>
      <pubDate>Fri, 22 Feb 2013 08:23:21 GMT</pubDate>
      <dc:creator><![CDATA[Norman Drews]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.technet.microsoft.com/normand/2013/02/22/using-findexecutable-finding-the-registered-executable-given-a-file-path/</guid>
      <description><![CDATA[&#160;  I had a need to find the registered executable for a particular file extension. Now, it is...]]></description>
      <content:encoded><![CDATA[<p>&#160;</p>  <p>I had a need to find the registered executable for a particular file extension. Now, it is possible to determine this via the registry. You could figure it out by looking into HKEY_CLASSES_ROOT but that is sometimes a tedious exercise if you've multiple potential applications that can handle the file type. The route I chose was to make use of a native function called FindExecutable exposed by shell32.dll.</p>  <p>&#160;</p>  <p>FindExecutable function (Windows)</p>  <p><a title="https://msdn.microsoft.com/en-us/library/windows/desktop/bb776419(v=vs.85).aspx" href="https://msdn.microsoft.com/en-us/library/windows/desktop/bb776419(v=vs.85).aspx">https://msdn.microsoft.com/en-us/library/windows/desktop/bb776419(v=vs.85).aspx</a></p>  <p>&#160;</p>  <p><a href="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/prod.evol.blogs.technet.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/00/92/21/metablogapi/8877.image_419D9113.png" original-url="https://blogs.technet.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-92-21-metablogapi/8877.image_5F00_419D9113.png"><img title="image" style="border-width: 0px; padding-top: 0px; padding-right: 0px; padding-left: 0px; display: inline; background-image: none;" border="0" alt="image" src="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/prod.evol.blogs.technet.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/00/92/21/metablogapi/6242.image_thumb_24483949.png" original-url="https://blogs.technet.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-92-21-metablogapi/6242.image_5F00_thumb_5F00_24483949.png" width="731" height="719" /></a></p>  <p>&#160;</p>  <h3><em>Looks fun, right? </em></h3>  <h3><em>How do I incorporate this inside of my Windows PowerShell script? </em></h3>  <p>&#160;</p>  <p>It isn't too bad. Most people know that Windows PowerShell is built on top of the .NET Framework. Well, with the .NET Framework comes the ability to reference native or unmanaged code (above) using the Add-Type cmdlet. This is probably an under-utilized feature of Windows PowerShell because there are cmdlets for almost everything now. So all your C# and C++ code isn't completely useless! It can be re-used. </p>  <p>&#160;</p>  <h2><font style="font-weight: bold;">Add-Type cmdlet</font></h2>  <p>Per the documentation, the Add-Type cmdlet lets you define a .NET Framework class in your Windows PowerShell session. You can then instantiate objects (by using the New-Object cmdlet) and use the objects, just as you would use any .NET Framework object.&#160; If you add an Add-Type command to your Windows PowerShell profile, the class will be available in all Windows PowerShell sessions.</p>  <p>You can specify the type by specifying an existing assembly or source code files, or you can specify the source code inline or saved in a variable. You can even specify only a method and Add-Type will define and generate the class. You can use this feature to make Platform Invoke (P/Invoke) calls to unmanaged functions in Windows PowerShell. If you specify source code, Add-Type compiles the specified source code and generates an in-memory assembly that contains the new .NET Framework types.</p>  <p>You can use the parameters of Add-Type to specify an alternate language and compiler (CSharp is the default), compiler options, assembly dependencies, the class namespace, the names of the type, and the resulting assembly.    <br /></p>  <p>&#160;</p>  <h2><font style="font-weight: bold;">The Code</font></h2>  <pre class="csharpcode">&#160;</pre>

<pre class="csharpcode">$Source = <span class="str">@&quot;

using System;
using System.Text;
using System.Runtime.InteropServices;
public class Win32API
    {
        [DllImport(&quot;</span>shell32.dll<span class="str">&quot;, EntryPoint=&quot;</span>FindExecutable<span class="str">&quot;)] 

        public static extern long FindExecutableA(string lpFile, string lpDirectory, StringBuilder lpResult);

        public static string FindExecutable(string pv_strFilename)
        {
            StringBuilder objResultBuffer = new StringBuilder(1024);
            long lngResult = 0;

            lngResult = FindExecutableA(pv_strFilename, string.Empty, objResultBuffer);

            if(lngResult &gt;= 32)
            {
                return objResultBuffer.ToString();
            }

            return string.Format(&quot;</span>Error: ({0})<span class="str">&quot;, lngResult);
        }
    }

&quot;</span>@

Add-Type -TypeDefinition $Source -ErrorAction SilentlyContinue

Get-ChildItem -Path D:\MyFolder | 
    Where-Object { -not $_.PSIsContainer } | 
            ForEach-Object {
                $FullName = $_.FullName
                $Executable = [Win32API]::FindExecutable($FullName)
                $OutputString = <span class="str">&quot;`nFile: {0}`nExecutable: {1}&quot;</span> -f $FullName, $Executable
                Write-Host -Object $OutputString
  
            } </pre>]]></content:encoded>
    </item>
    <item>
      <title>Disabling/Enabling Network Connection by Name</title>
      <link>https://docs.microsoft.com/archive/blogs/normand/disablingenabling-network-connection-by-name</link>
      <pubDate>Tue, 17 Jan 2012 11:29:04 GMT</pubDate>
      <dc:creator><![CDATA[Norman Drews]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.technet.microsoft.com/normand/2012/01/17/disablingenabling-network-connection-by-name/</guid>
      <description><![CDATA[&#160;  I was playing around with Windows PowerShell today and wanted to demonstrate a way to...]]></description>
      <content:encoded><![CDATA[<p>&#160;</p>  <p>I was playing around with Windows PowerShell today and wanted to demonstrate a way to disable a network connection by the name or any other property for that matter. This entry will be limited to filtering on the name. First the network connections I care about I have below on my local machine.</p>  <p><a href="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/prod.evol.blogs.technet.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/00/92/21/metablogapi/8231.image_2.png" original-url="https://blogs.technet.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-92-21-metablogapi/8231.image_5F00_2.png"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/prod.evol.blogs.technet.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/00/92/21/metablogapi/5001.image_thumb.png" original-url="https://blogs.technet.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-92-21-metablogapi/5001.image_5F00_thumb.png" width="611" height="224" /></a></p>  <p>To get this listing we need to use the WMI class called <a href="https://msdn.microsoft.com/en-us/library/windows/desktop/aa394216(v=vs.85).aspx" target="_blank">Win32_NetworkAdapter</a>. Without going into too much detail, that class represents a network adapter of a computer. The link gives more detail if you want to show IPv6 data. This is currently limited to IPv4 information.</p>  <p>Anyhow, to get a listing, I run this command: </p>  <div id="codeSnippetWrapper">   <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px" id="codeSnippet">Get-WmiObject -Class Win32_NetworkAdapter `<br />    -Filter <span style="color: #006080">&quot;NetConnectionID IS NOT NULL&quot;</span> | <br />   Format-Table -Property NetConnectionID, NetEnabled, InterfaceIndex `<br />    –AutoSize </pre>

  <br /></div>

<p>After running that command I will get the following output for my box.</p>

<p><font size="2" face="Courier New">NetConnectionID&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; NetEnabled InterfaceIndex 
    <br />---------------&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; ---------- -------------- 

    <br />Local Area Connection&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; False&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; 10 

    <br />Wireless Network Connection 6&#160;&#160;&#160;&#160;&#160;&#160; True&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; 25 

    <br />Wireless Network Connection 7&#160;&#160;&#160;&#160;&#160; False&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; 26</font> 

  <br /></p>

<p>Your output probably differs. We are closer to achieving our goal. That WMI class gives us a few method to play with:</p>

<div id="codeSnippetWrapper">
  <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px" id="codeSnippet">Get-WmiObject -Class Win32_NetworkAdapter | <br />    Get-Member -MemberType Method | <br />        Format-Table -Property Name</pre>

  <br /></div>

<p><font size="2" face="Courier New">TypeName: System.Management.ManagementObject#root\cimv2\Win32_NetworkAdapter</font></p>

<p><font size="2" face="Courier New">Name 
    <br />---- 

    <br />Disable 

    <br />Enable 

    <br />Reset 

    <br />SetPowerState</font></p>

<p>The WMI Class provides us with 4 methods that are usable if we run this script elevated. Remember, the act of modifying a network adapter requires elevated privileges. </p>

<p>To ENABLE a network adapter</p>

<div id="codeSnippetWrapper">
  <div id="codeSnippetWrapper">
    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px" id="codeSnippet">$networkAdapterName = <span style="color: #006080">&quot;Wireless Network Connection 7&quot;</span><br />Get-WmiObject -Class Win32_NetworkAdapter `<br />    -Filter <span style="color: #006080">&quot;NetConnectionID = '$($networkAdapterName)'&quot;</span> | <br />        ForEach-Object { $_.Enable() }</pre>

    <br /></div>

  <br /></div>

<p>To DISABLE a network adapter</p>

<div id="codeSnippetWrapper">
  <div id="codeSnippetWrapper">
    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px" id="codeSnippet">$networkAdapterName = <span style="color: #006080">&quot;Wireless Network Connection 7&quot;</span><br />Get-WmiObject -Class Win32_NetworkAdapter `<br />    -Filter <span style="color: #006080">&quot;NetConnectionID = '$($networkAdapterName)'&quot;</span> | <br />        ForEach-Object { $_.Disable() }</pre>

    <br /></div>

  <br /></div>]]></content:encoded>
    </item>
    <item>
      <title>Removing leaf objects from Active Directory</title>
      <link>https://docs.microsoft.com/archive/blogs/normand/removing-leaf-objects-from-active-directory</link>
      <pubDate>Thu, 12 Jan 2012 07:58:36 GMT</pubDate>
      <dc:creator><![CDATA[Norman Drews]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.technet.microsoft.com/normand/2012/01/12/removing-leaf-objects-from-active-directory/</guid>
      <description><![CDATA[&#160;  Not recently I had a customer whose migration , one way or another, was being blocked due to...]]></description>
      <content:encoded><![CDATA[<p>&#160;</p>  <p>Not recently I had a customer whose migration , one way or another, was being blocked due to leaf objects existing under an AD User entry. They said they couldn't find any script online through Google or Bing that they could &quot;borrow&quot;. I'm not really an Active Directory guy but I like scripting so I took a stab at it. </p>  <p>In these scripts the usual suspects you may want to modify include but aren't limited to:</p>  <ul>   <li>Search Root </li>    <li>(LDAP)Filters in case you don't want to remove the leaf objects underneath all users </li>    <li>User Output </li> </ul>  <p>&#160;</p>  <h3>The Script using AD Cmdlets</h3>  <div>   <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px" id="codeSnippet"><p><span style="color: #0000ff">param</span><br />(<br />    $root = <span style="color: #006080">&quot;ou=myTestOU,dc=contoso,dc=com&quot;</span><br />)</p><p><span style="color: #008000"># Import the AD Module</span><br />Import-Module ActiveDirectory<br /></p><p><span style="color: #008000"># Get all users using a provided searchbase.</span><br />$users = Get-ADUser -Filter * -SearchBase $root<br /></p><p><span style="color: #008000"># Loop through the users</span><br /><span style="color: #0000ff">foreach</span>($user <span style="color: #0000ff">in</span> $users)<br />{<br />    <span style="color: #008000"># Find all AD objects one level below the user</span><br />    $objs = Get-ADObject -Filter * -SearchScope `<br />    oneLevel -SearchBase $user.DistinguishedName<br />    <br />    <span style="color: #008000"># Performance a recursive delete to remove those leaf objects</span><br />    <span style="color: #0000ff">if</span>($objs)<br />    {<br />        Write-Host <span style="color: #006080">&quot;Removing leaf objects...&quot;</span>        <br />        $objs | Remove-ADObject -Recursive<br />    } <br />}</p></pre>
</div>

<div>&#160;</div>

<h3>&#160;</h3>

<h3>The Script using direct .NET Framework access</h3>

<div id="codeSnippetWrapper">
  <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px" id="codeSnippet"><p><span style="color: #0000ff">param</span><br />(<br />    $root = <span style="color: #006080">&quot;LDAP://ou=MyTestOU,dc=contoso,dc=com&quot;</span>,<br />    $scope = <span style="color: #006080">&quot;subtree&quot;</span>,<br />    $LDAPFilter = <span style="color: #006080">&quot;(&amp;(objectcategory=User))&quot;</span><br />)</p><p><span style="color: #008000"># Set up the DirectorySearcher object</span><br />$s = New-Object -TypeName System.DirectoryServices.DirectorySearcher<br />$s.SearchRoot = [adsi]$root<br />$s.SearchScope = $scope<br />$s.Filter = $LDAPFilter<br /></p><p><span style="color: #008000"># Find all matches</span><br />$result = $s.FindAll()<br /></p><p><span style="color: #008000"># Enumerate through all matches</span><br /><span style="color: #0000ff">foreach</span> ($item <span style="color: #0000ff">in</span> $result)<br />{<br />    $entry = $item.GetDirectoryEntry()</p><span style="color: #008000">    </span><br /><span style="color: #008000">    # Enumerate through the children and delete them</span><br />    <span style="color: #0000ff">foreach</span>($obj <span style="color: #0000ff">in</span> $entry.children)<br />    {<br />        <span style="color: #006080">&quot;Deleting $($obj.DistinguishedName)&quot;</span><br />        $leaf = [adsi]<span style="color: #006080">&quot;LDAP://$($obj.DistinguishedName)&quot;</span><br />        $leaf.psbase.DeleteTree()<br />    }<br />}</pre>

  <br /></div>

<div></div>

<div></div>

<div></div>]]></content:encoded>
    </item>
    <item>
      <title>What’s the member delta between my two AD Groups</title>
      <link>https://docs.microsoft.com/archive/blogs/normand/whats-the-member-delta-between-my-two-ad-groups</link>
      <pubDate>Tue, 10 Jan 2012 14:15:00 GMT</pubDate>
      <dc:creator><![CDATA[Norman Drews]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.technet.microsoft.com/normand/2012/01/10/whats-the-member-delta-between-my-two-ad-groups/</guid>
      <description><![CDATA[&nbsp;
Today I am going to refresh your memory on how we can use the Compare-Object cmdlet to do...]]></description>
      <content:encoded><![CDATA[<p>&nbsp;</p>
<h3>Today I am going to refresh your memory on how we can use the <a href="https://technet.microsoft.com/en-us/library/dd347568.aspx">Compare-Object</a> cmdlet to do well exactly what it says &hellip;. compare two different objects.</h3>
<p>So how do I determine which Active Directory group members are in one group and not in another? And&hellip; I want those missing (delta-ed) members put into an entirely new one.</p>
<p>Sure, there are many ways to do this including nested loops but the <a href="https://technet.microsoft.com/en-us/library/dd347568.aspx">Compare-Object</a> cmdlet makes it easy. The <a href="https://technet.microsoft.com/en-us/library/dd347568.aspx">Compare-Object</a> cmdlet compares two sets of objects. One set of objects is the Reference set, and the other set is the Difference set.</p>
<p>The result of the comparison indicates whether a property value appeared only in the object from the Reference set (indicated by the &lt;= symbol), only in the object from the Difference set (indicated by the =&gt; symbol) or, if the IncludeEqual parameter is specified, in both objects (indicated by the == symbol).</p>
<h3>Code Snippet</h3>
<p>param <br />( <br />&nbsp;&nbsp;&nbsp; $ReferenceGroupDN = "cn=ReferenceGroup,ou=MyTestOU,dc=contoso,dc=com", <br />&nbsp;&nbsp;&nbsp; $DifferenceGroupDN = "cn=DifferenceGroup,ou=MyTestOU,dc=contoso,dc=com", <br />&nbsp;&nbsp;&nbsp; $TargetGroupDN = "cn=TargetGroup,ou=MyTestOU,dc=contoso,dc=com" <br />)</p>
<p># Import the AD module <br />Import-Module -Name ActiveDirectory</p>
<p># Declare Variables <br />$ReferenceUsers = Get-ADGroupMember -Identity $ReferenceGroupDN <br />$DifferenceUsers = Get-ADGroupMember -Identity $DifferenceGroupDN</p>
<p># See what distinguished names are present in DifferenceUsers but not in ReferenceUsers <br />$userDifferenceArray = Compare-Object -ReferenceObject $ReferenceUsers ` <br />&nbsp;&nbsp;&nbsp; -DifferenceObject $DifferenceUsers -Property DistinguishedName -IncludeEqual -PassThru | ` <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Where-Object { $_.SideIndicator -eq "=&gt;" } <br />&nbsp;&nbsp;&nbsp; <br /># Add to the Target Group - $TargetGroupDN <br />Add-ADGroupMember -Identity $TargetGroupDN -Members $userDifferenceArray</p>
<p></p>
<h3>Explanation</h3>
<p>In my test case, ReferenceGroup has the users Test2, Test4, and Test5. DifferenceGroup has the users Test1, Test2, Test3. All are within the MyTestOU OU of my virtual contoso.com domain.</p>
<h6>ReferenceGroup Members</h6>
<table style="width: 400px;" border="0" cellspacing="0" cellpadding="2">
<tbody>
<tr>
<td valign="top" width="398"><a href="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/prod.evol.blogs.technet.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/00/92/21/metablogapi/4657.ReferenceGroup_532565D7.png" original-url="https://blogs.technet.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-92-21-metablogapi/4657.ReferenceGroup_5F00_532565D7.png"><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border-width: 0px;" title="ReferenceGroup" border="0" alt="ReferenceGroup" src="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/prod.evol.blogs.technet.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/00/92/21/metablogapi/1512.ReferenceGroup_thumb_30ED5A51.png" original-url="https://blogs.technet.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-92-21-metablogapi/1512.ReferenceGroup_5F00_thumb_5F00_30ED5A51.png" width="353" height="336" /></a></td>
</tr>
</tbody>
</table>
<h6>DifferenceGroup Members</h6>
<table style="width: 400px;" border="0" cellspacing="0" cellpadding="2">
<tbody>
<tr>
<td valign="top" width="400"><a href="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/prod.evol.blogs.technet.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/00/92/21/metablogapi/8030.DifferenceGroup_06517974.png" original-url="https://blogs.technet.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-92-21-metablogapi/8030.DifferenceGroup_5F00_06517974.png"><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border-width: 0px;" title="DifferenceGroup" border="0" alt="DifferenceGroup" src="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/prod.evol.blogs.technet.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/00/92/21/metablogapi/0116.DifferenceGroup_thumb_5CFA3175.png" original-url="https://blogs.technet.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-92-21-metablogapi/0116.DifferenceGroup_5F00_thumb_5F00_5CFA3175.png" width="353" height="341" /></a></td>
</tr>
</tbody>
</table>
<p>We are here to show <a href="https://technet.microsoft.com/en-us/library/dd347568.aspx">Compare-Object</a> so lets use it to compare the two AD objects based on the DistinguishedName attribute. All we need to do is run these lines:</p>
<p>This block just gives us the top-level members:</p>
<hr />
<p># Declare Variables <br />$ReferenceUsers = Get-ADGroupMember -Identity $ReferenceGroupDN <br />$DifferenceUsers = Get-ADGroupMember -Identity $DifferenceGroupDN</p>
<p># See what distinguished names are present in DifferenceUsers but not in ReferenceUsers <br />Compare-Object -ReferenceObject $ReferenceUsers ` <br />-DifferenceObject $DifferenceUsers -Property DistinguishedName -IncludeEqual</p>
<hr />
<p>Executing the above line will give us this output:</p>
<p><a href="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/prod.evol.blogs.technet.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/00/92/21/metablogapi/6874.compare-object_60B7D645.png" original-url="https://blogs.technet.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-92-21-metablogapi/6874.compare_2D00_object_5F00_60B7D645.png"><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border-width: 0px;" title="compare-object" border="0" alt="compare-object" src="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/prod.evol.blogs.technet.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/00/92/21/metablogapi/4718.compare-object_thumb_2D7B9CDC.png" original-url="https://blogs.technet.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-92-21-metablogapi/4718.compare_2D00_object_5F00_thumb_5F00_2D7B9CDC.png" width="509" height="118" /></a></p>
<p>We read it by using the SideIndicator property. As the documentation states, the &ldquo;==&rdquo; means the DistinguishedName was present in both the ReferenceObject and DifferenceObject. The &ldquo;=&gt;&rdquo; means it was present only in the DifferenceObject. The &ldquo;&lt;=&rdquo; means the property was only present in the ReferenceObject.</p>
<p>So if all I care about are those in the DifferenceObject that are not present in the ReferenceObject then we filter on the &ldquo;=&gt;&rdquo; using a Where-Object.</p>
<hr />
<p><span class="kwrd"># See what distinguished names are present in DifferenceUsers but not in ReferenceUsers <br />$userDifferenceArray = Compare-Object -ReferenceObject $ReferenceUsers ` <br />-DifferenceObject $DifferenceUsers -Property DistinguishedName -IncludeEqual -PassThru | ` <br />Where-Object { $_.SideIndicator -eq "=&gt;" } </span></p>
<p># Add to the Target Group - $TargetGroupDN <br />Add-ADGroupMember -Identity $TargetGroupDN -Members $userDifferenceArray </p>
<hr />
<p>You might have noticed that I also used the parameter &ldquo;PassThru&rdquo;. It allows me to keep the original type name which was Microsoft.ActiveDirectory.Management.ADPrincipal. If I don&rsquo;t use the parameter "PassThru" the typename is System.Management.Automation.PSCustomObject.</p>
<p>Add-ADGroupMember&rsquo;s parameter &ldquo;Members&rdquo; supports the ADPrincipal type so all is good. It does not support a PSCustomObject type.</p>
<p>The end result:</p>
<table style="width: 400px;" border="0" cellspacing="0" cellpadding="2">
<tbody>
<tr>
<td valign="top" width="400"><a href="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/prod.evol.blogs.technet.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/00/92/21/metablogapi/7357.TargetGroup_75E5DBED.png" original-url="https://blogs.technet.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-92-21-metablogapi/7357.TargetGroup_5F00_75E5DBED.png"><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border-width: 0px;" title="TargetGroup" border="0" alt="TargetGroup" src="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/prod.evol.blogs.technet.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/00/92/21/metablogapi/5857.TargetGroup_thumb_1B03265A.png" original-url="https://blogs.technet.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-92-21-metablogapi/5857.TargetGroup_5F00_thumb_5F00_1B03265A.png" width="361" height="380" /></a></td>
</tr>
</tbody>
</table>]]></content:encoded>
    </item>
  </channel>
</rss>