<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:blogger='http://schemas.google.com/blogger/2008' xmlns:georss='http://www.georss.org/georss' xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-175557281513638</id><updated>2025-06-04T19:49:50.771-06:00</updated><category term="IIS cloning sysprep machineGUID"/><category term="Powershell FTP"/><category term="Powershell MSI Installer Function Win32_Product WMI"/><category term="Powershell Security Windows"/><category term="powershell MSMQ Active Directory IIS Server"/><category term="powershell Windows Server"/><category term="vCAC java odata4j"/><category term="vbscript IIS monitoring"/><category term="vbscript logging IIS Windows Powershell"/><title type='text'>Tech Notes</title><subtitle type='html'>Notes from my adventures</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://rcampi.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/175557281513638/posts/default?redirect=false'/><link rel='alternate' type='text/html' href='http://rcampi.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>-campi</name><uri>http://www.blogger.com/profile/09146913336110357201</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='30' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhQ-2U2NkBT2A1ClHJhcSFh8G5s72Aoqi4JhS1vLNGmHiNT24OG24a46V4WoUfYFiOOZqcR_LZR6eeozjEnLJNiBdKIJZjE_icFodW7WGprayD-XW9cTt5GLcG6ZeBJRgw/s220/avatar.jpg'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>19</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-175557281513638.post-4943423148107581296</id><published>2018-10-03T15:12:00.000-06:00</published><updated>2018-10-03T15:15:01.577-06:00</updated><title type='text'>port proxy</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
netsh interface portproxy add v4tov4 listenport=22 connectport=22 connectaddress=192.168.110.51&lt;br /&gt;
&lt;br /&gt;
netsh interface portproxy show v4tov4&lt;br /&gt;
&lt;br /&gt;
netstat -ano&lt;br /&gt;
&lt;br /&gt;
PS C:\Users\localuser&amp;gt;&amp;nbsp; netstat -an | sls &quot;22&quot;&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; TCP &amp;nbsp; &amp;nbsp;0.0.0.0:22 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0.0.0.0:0 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;LISTENING&lt;br /&gt;
&amp;nbsp; TCP &amp;nbsp; &amp;nbsp;192.168.109.50:22 &amp;nbsp; &amp;nbsp; &amp;nbsp;12.36.9.2:24773 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;ESTABLISHED&lt;br /&gt;
&amp;nbsp; TCP &amp;nbsp; &amp;nbsp;192.168.109.50:51554 &amp;nbsp; 192.168.110.51:22 &amp;nbsp; &amp;nbsp; &amp;nbsp;ESTABLISHED&lt;br /&gt;
&lt;br /&gt;
see connections&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://rcampi.blogspot.com/feeds/4943423148107581296/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://rcampi.blogspot.com/2018/10/port-proxy.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/175557281513638/posts/default/4943423148107581296'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/175557281513638/posts/default/4943423148107581296'/><link rel='alternate' type='text/html' href='http://rcampi.blogspot.com/2018/10/port-proxy.html' title='port proxy'/><author><name>-campi</name><uri>http://www.blogger.com/profile/09146913336110357201</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='30' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhQ-2U2NkBT2A1ClHJhcSFh8G5s72Aoqi4JhS1vLNGmHiNT24OG24a46V4WoUfYFiOOZqcR_LZR6eeozjEnLJNiBdKIJZjE_icFodW7WGprayD-XW9cTt5GLcG6ZeBJRgw/s220/avatar.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-175557281513638.post-2116494998783031918</id><published>2018-10-03T15:10:00.001-06:00</published><updated>2021-04-28T11:46:39.568-06:00</updated><title type='text'>Microsoft Servers (2008R2/2012R2) Not Negotiating to TLS 1.0</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
Testing a package that will run using .Net 4.0 or above.&amp;nbsp; The software uses SSL to encrypt traffic between the nodes.&amp;nbsp; &lt;br /&gt;
&lt;br /&gt;
Certificates generated signed with a SHA 512 bit key.&amp;nbsp; &lt;br /&gt;
&lt;br /&gt;
As long as .Net 4.0 is installed, will attempt connection with TLS 1.2, does not find a matching cipher and steps down and connects using TSL 1.0.&amp;nbsp; After .Net 4.5.1 is installed, it no longer steps down to TLS 1.0.&amp;nbsp; In trace, you will see that there is a ClientHello followed by the server sending a TCP RST.&amp;nbsp; At no time does it attempt to step down to TLS 1.0.&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;programlisting&quot; style=&quot;background-color: #fefefe; font-size: 13.6px; hyphens: none; margin-bottom: 10px; margin-left: 20px; margin-top: 10px; white-space: pre-wrap;&quot;&gt;Get-ChildItem -Filter *.txt -Recurse&lt;/pre&gt;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://rcampi.blogspot.com/feeds/2116494998783031918/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://rcampi.blogspot.com/2018/10/microsoft-servers-2008r22012r2-not.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/175557281513638/posts/default/2116494998783031918'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/175557281513638/posts/default/2116494998783031918'/><link rel='alternate' type='text/html' href='http://rcampi.blogspot.com/2018/10/microsoft-servers-2008r22012r2-not.html' title='Microsoft Servers (2008R2/2012R2) Not Negotiating to TLS 1.0'/><author><name>-campi</name><uri>http://www.blogger.com/profile/09146913336110357201</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='30' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhQ-2U2NkBT2A1ClHJhcSFh8G5s72Aoqi4JhS1vLNGmHiNT24OG24a46V4WoUfYFiOOZqcR_LZR6eeozjEnLJNiBdKIJZjE_icFodW7WGprayD-XW9cTt5GLcG6ZeBJRgw/s220/avatar.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-175557281513638.post-4645887176431840568</id><published>2018-10-03T15:09:00.000-06:00</published><updated>2018-10-03T15:09:59.235-06:00</updated><title type='text'>Multiple Versions of SQL Server Installed - Path to SqlPS module</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
Issue with a powershell script that enabled the Always-On High Availability setting in SQL 2014.&amp;nbsp; The server also had SQL 2012 (may have been upgraded) and so it had multiple versions of the same module installed in different directories.&amp;nbsp; Import-module SqlPS loads the SQL 2012 version of the module.&amp;nbsp; &lt;br /&gt;
&lt;br /&gt;
You have to explicitly load the correct module by doing an import-module with the path to the module that you want.&lt;br /&gt;
&lt;br /&gt;
Enable-SqlAlwaysOn would fail with cannot find SQLSERVER exception.&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;Find duplicate modules:&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
get-module -listAvailable -name SqlPs | format-table -property name, moduletype, path -group by name -auto&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://rcampi.blogspot.com/feeds/4645887176431840568/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://rcampi.blogspot.com/2018/10/multiple-versions-of-sql-server.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/175557281513638/posts/default/4645887176431840568'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/175557281513638/posts/default/4645887176431840568'/><link rel='alternate' type='text/html' href='http://rcampi.blogspot.com/2018/10/multiple-versions-of-sql-server.html' title='Multiple Versions of SQL Server Installed - Path to SqlPS module'/><author><name>-campi</name><uri>http://www.blogger.com/profile/09146913336110357201</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='30' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhQ-2U2NkBT2A1ClHJhcSFh8G5s72Aoqi4JhS1vLNGmHiNT24OG24a46V4WoUfYFiOOZqcR_LZR6eeozjEnLJNiBdKIJZjE_icFodW7WGprayD-XW9cTt5GLcG6ZeBJRgw/s220/avatar.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-175557281513638.post-990226361266085389</id><published>2014-05-15T16:40:00.001-06:00</published><updated>2018-10-03T15:11:30.320-06:00</updated><title type='text'>Launch Script or Process When a Computer Object is Created in Active Directory</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
Good for firing off a script or process when a computer is added to a domain.&amp;nbsp; Just fire off the script and let it run at start time.&amp;nbsp; This is not done but just a start for others interested in doing something similar.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;code&gt;
$timespan = New-Object System.TimeSpan(0, 0, 1)&lt;br /&gt;$scope = New-Object System.Management.ManagementScope(&#39;\\domainname\root\directory\LDAP&#39;)&lt;br /&gt;$query = New-Object System.Management.WQLEventQuery `&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; (&quot;__InstanceCreationEvent&quot;,$timespan, &quot;TargetInstance ISA &#39;ds_computer&#39;&quot; )&lt;br /&gt;$watcher = New-Object System.Management.ManagementEventWatcher($scope,$query)&lt;br /&gt;&lt;br /&gt;$b = $watcher.WaitForNextEvent()&lt;/code&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;code&gt;#view information about the computer object that was created. &lt;/code&gt;&lt;br /&gt;
&lt;code&gt;$b.TargetInstance.DS_Name&lt;br /&gt;$b.TargetInstance.DS_Samaccountname&lt;br /&gt;$b.TargetInstance.DS_distinguishedName&lt;br /&gt;$b.TargetInstance.DS_cn&lt;/code&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;code&gt;#fire off powershell or script here using the information about the computer account.&lt;/code&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;code&gt;#if you want to restart after running process just add in a while loop like this&lt;/code&gt;&lt;br /&gt;
&lt;code&gt;&lt;br /&gt;&lt;/code&gt;
&lt;code&gt;do &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/code&gt;&lt;code&gt;&lt;code&gt;$b = $watcher.WaitForNextEvent()&lt;/code&gt;&lt;/code&gt;&lt;br /&gt;
&lt;code&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; #view information about the computer object that was created. &lt;/code&gt;&lt;br /&gt;
&lt;code&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; $b.TargetInstance.DS_Name&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; $b.TargetInstance.DS_Samaccountname&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; $b.TargetInstance.DS_distinguishedName&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; $b.TargetInstance.DS_cn&lt;/code&gt;&lt;br /&gt;
&lt;code&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; #launch script here&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; } &lt;br /&gt;while (0 -eq 0)&lt;/code&gt;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://rcampi.blogspot.com/feeds/990226361266085389/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://rcampi.blogspot.com/2014/05/launch-script-or-process-when-computer.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/175557281513638/posts/default/990226361266085389'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/175557281513638/posts/default/990226361266085389'/><link rel='alternate' type='text/html' href='http://rcampi.blogspot.com/2014/05/launch-script-or-process-when-computer.html' title='Launch Script or Process When a Computer Object is Created in Active Directory'/><author><name>-campi</name><uri>http://www.blogger.com/profile/09146913336110357201</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='30' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhQ-2U2NkBT2A1ClHJhcSFh8G5s72Aoqi4JhS1vLNGmHiNT24OG24a46V4WoUfYFiOOZqcR_LZR6eeozjEnLJNiBdKIJZjE_icFodW7WGprayD-XW9cTt5GLcG6ZeBJRgw/s220/avatar.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-175557281513638.post-9200277034695915472</id><published>2014-04-18T14:20:00.000-06:00</published><updated>2014-04-18T14:20:53.145-06:00</updated><title type='text'>Testing File Write to Remote Share with remote Domain Credential - no trust between local and remote host domains</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;br /&gt;
Add the following class in powershell at top of script or module. This wrapper class needs to be called only once in a script to make the class available to the powershell code.&amp;nbsp; I set the error action preference to stop as I use try catch in scripts and have found it is more predictable behavior of catching non-terminating errors when setting this preference.&amp;nbsp; This is not required .....&lt;br /&gt;
&lt;br /&gt;
&lt;code&gt;$ErrorActionPreference = &quot;Stop&quot;&amp;nbsp;&lt;/code&gt;&lt;br /&gt;
&lt;code&gt;&lt;br /&gt;&lt;/code&gt;
&lt;code&gt;$WNetAddConnection2WrapperSource = @&#39;&lt;br /&gt;using System;&lt;br /&gt;using System.Runtime.InteropServices;&lt;br /&gt;&lt;br /&gt;namespace Win32Api {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; public enum ResourceScope {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; RESOURCE_CONNECTED = 1,&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; RESOURCE_GLOBALNET,&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; RESOURCE_REMEMBERED,&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; RESOURCE_RECENT,&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; RESOURCE_CONTEXT&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; };&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; public enum ResourceType {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; RESOURCETYPE_ANY,&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; RESOURCETYPE_DISK,&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; RESOURCETYPE_PRINT,&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; RESOURCETYPE_RESERVED = 8&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; };&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; [Flags]&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; public enum ResourceUsage {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; RESOURCEUSAGE_CONNECTABLE = 0x00000001,&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; RESOURCEUSAGE_CONTAINER = 0x00000002,&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; RESOURCEUSAGE_NOLOCALDEVICE = 0x00000004,&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; RESOURCEUSAGE_SIBLING = 0x00000008,&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; RESOURCEUSAGE_ATTACHED = 0x00000010,&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; RESOURCEUSAGE_ALL = (RESOURCEUSAGE_CONNECTABLE | &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; RESOURCEUSAGE_CONTAINER | RESOURCEUSAGE_ATTACHED),&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; };&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; public enum ResourceDisplayType {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; RESOURCEDISPLAYTYPE_GENERIC,&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; RESOURCEDISPLAYTYPE_DOMAIN,&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; RESOURCEDISPLAYTYPE_SERVER,&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; RESOURCEDISPLAYTYPE_SHARE,&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; RESOURCEDISPLAYTYPE_FILE,&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; RESOURCEDISPLAYTYPE_GROUP,&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; RESOURCEDISPLAYTYPE_NETWORK,&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; RESOURCEDISPLAYTYPE_ROOT,&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; RESOURCEDISPLAYTYPE_SHAREADMIN,&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; RESOURCEDISPLAYTYPE_DIRECTORY,&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; RESOURCEDISPLAYTYPE_TREE,&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; RESOURCEDISPLAYTYPE_NDSCONTAINER&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; };&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; [StructLayout(LayoutKind.Sequential)]&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; public class NetResource {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; public ResourceScope Scope;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; public ResourceType Type;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; public ResourceDisplayType DisplayType;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; public ResourceUsage Usage;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; public string LocalName;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; public string RemoteName;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; public string Comment;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; public string Provider;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; };&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; [Flags]&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; public enum AddConnectionOptions {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; CONNECT_UPDATE_PROFILE = 0x00000001,&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; CONNECT_UPDATE_RECENT&amp;nbsp; = 0x00000002,&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; CONNECT_TEMPORARY&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; = 0x00000004,&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; CONNECT_INTERACTIVE&amp;nbsp;&amp;nbsp;&amp;nbsp; = 0x00000008,&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; CONNECT_PROMPT&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; = 0x00000010,&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; CONNECT_NEED_DRIVE&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; = 0x00000020,&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; CONNECT_REFCOUNT&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; = 0x00000040,&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; CONNECT_REDIRECT&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; = 0x00000080,&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; CONNECT_LOCALDRIVE&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; = 0x00000100,&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; CONNECT_CURRENT_MEDIA&amp;nbsp; = 0x00000200,&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; CONNECT_DEFERRED&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; = 0x00000400,&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; CONNECT_RESERVED&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; = unchecked((int)0xFF000000),&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; CONNECT_COMMANDLINE&amp;nbsp;&amp;nbsp;&amp;nbsp; = 0x00000800,&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; CONNECT_CMD_SAVECRED&amp;nbsp;&amp;nbsp; = 0x00001000,&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; CONNECT_CRED_RESET&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; = 0x00002000&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;&amp;nbsp; &lt;br /&gt;&amp;nbsp;&amp;nbsp; public static class NativeMethods {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; [DllImport(&quot;mpr.dll&quot;,&amp;nbsp; EntryPoint=&quot;WNetAddConnection2&quot;,CharSet = CharSet.Ansi,SetLastError = true)]&amp;nbsp;&amp;nbsp; &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; public static extern int WNetAddConnection2(&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; NetResource netResource, string password, &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; string username, AddConnectionOptions options);&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;[DllImport(&quot;mpr.dll&quot;, EntryPoint=&quot;WNetCancelConnection2&quot;,CharSet = CharSet.Ansi,SetLastError = true)] &lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;public static extern int WNetCancelConnection2(string name, int flags,&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; bool force);&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;//[DllImport(&quot;Kernel32.dll&quot;)]&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;//public static extern uint GetLastError();&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;}&lt;br /&gt;&#39;@&lt;/code&gt;&lt;br /&gt;
&lt;code&gt;&lt;br /&gt;Add-Type -TypeDefinition $WNetAddConnection2WrapperSource&lt;br /&gt;
$authType = Add-Type -Name authUtils -MemberDefinition @&quot;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // http://msdn.microsoft.com/en-us/library/aa378184.aspx&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; [DllImport(&quot;advapi32.dll&quot;, SetLastError = true)]&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; public static extern bool LogonUser(string lpszUsername, string lpszDomain, string lpszPassword, int dwLogonType, int dwLogonProvider, ref IntPtr phToken);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // http://msdn.microsoft.com/en-us/library/aa379317.aspx&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; [DllImport(&quot;advapi32.dll&quot;, SetLastError=true)]&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; public static extern bool RevertToSelf();&lt;br /&gt;&quot;@ -passthru &lt;/code&gt;&lt;br /&gt;
&lt;br /&gt;
Now that you have the C# class wrapping native Win32 API calls, you can use this to connect to remote share (RPC) as a different credential. &lt;br /&gt;
&lt;br /&gt;
In this case, you cannot impersonate another user locally and connect to the remote share because you are on a server in an untrusted domain.&amp;nbsp; You can use a domain credential in the remote server to connect to the share though, which is how this process works.&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-size: x-small;&quot;&gt;&lt;code&gt;function Check-Folder() {&lt;br /&gt;[CmdletBinding()]&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Param ([Parameter(Position=1,Mandatory=$true, ValueFromPipelineByPropertyName=$true,HelpMessage=&quot;Object with Folder properties to check&quot;)] &lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; [Alias(&quot;u&quot;)] [PSObject]$folderProps)&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;Process {&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;try{&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; $netresource = New-Object Win32Api.NetResource&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;$netresource.Type = [Win32Api.ResourceType]::RESOURCETYPE_DISK&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;$netresource.RemoteName = $([System.IO.Path]::GetPathRoot($folderProps.testFile))&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;#$opts = [Win32Api.AddConnectionOptions]::CONNECT_INTERACTIVE&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;#Use this option will not prompt user for credentials if fails during attempt.&amp;nbsp;&amp;nbsp;&lt;/code&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: x-small;&quot;&gt;&lt;code&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; #If you want to prompt if fails, use INTERACTIVE&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;$opts = [Win32Api.AddConnectionOptions]::CONNECT_TEMPORARY&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;$ret = [Win32Api.NativeMethods]::WNetAddConnection2($netResource,$folderProps.password,$folderProps.Domain + &quot;\&quot; + $folderProps.User, $opts)&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;if($ret)&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;{&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;throw (new-object System.ComponentModel.Win32Exception($ret))&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;}&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;#Open file connection&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;$writer = [System.IO.File]::Open($folderProps.testFile,[System.IO.FileMode]::Create)&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;$writer.Close() &lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;[System.IO.File]::Delete($folderProps.testFile)&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;$ret = [Win32Api.NativeMethods]::WNetCancelConnection2($netresource.RemoteName, $null, $true)&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;if($ret)&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;{&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;throw (new-object System.ComponentModel.Win32Exception($ret))&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;}&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;} catch {&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;throw &quot;Failed accessing share&quot; +&amp;nbsp; $folderProps.testFile + &quot;: Exception: $($_)&quot;&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;}&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;}&lt;br /&gt;}&amp;nbsp;&lt;/code&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
Now you have the function to call, create the object the function expects as input.&lt;br /&gt;
&lt;br /&gt;
$folder = New-Object PSObject -Property @{&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; testFile&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp; =&amp;nbsp;&amp;nbsp;&amp;nbsp; &#39;\\share\folder\path\test\tempfilename.txt&#39; &amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; user&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; =&amp;nbsp;&amp;nbsp;&amp;nbsp; &#39;remote domain user account&#39;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; password&amp;nbsp; =&amp;nbsp;&amp;nbsp;&amp;nbsp; &#39;remote domain user password&#39;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; domain&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp; =&amp;nbsp;&amp;nbsp; &#39;remote domain&#39;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;
&lt;br /&gt;
Now call the function in Powershell:&lt;br /&gt;
&lt;br /&gt;
Check-Folder $folder&lt;br /&gt;
&lt;br /&gt;
The process will map a temporary connection, if it can, with the provided credential and attempt to create a file at the location (you provide a file name using testfile property).&amp;nbsp; The process will not release write file handle, it is written and deleted.&amp;nbsp; If successful you are good, if not, you will get an exception returned.&amp;nbsp; &lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-size: x-small;&quot;&gt;&lt;/span&gt;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://rcampi.blogspot.com/feeds/9200277034695915472/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://rcampi.blogspot.com/2014/04/testing-file-write-to-remote-share-with.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/175557281513638/posts/default/9200277034695915472'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/175557281513638/posts/default/9200277034695915472'/><link rel='alternate' type='text/html' href='http://rcampi.blogspot.com/2014/04/testing-file-write-to-remote-share-with.html' title='Testing File Write to Remote Share with remote Domain Credential - no trust between local and remote host domains'/><author><name>-campi</name><uri>http://www.blogger.com/profile/09146913336110357201</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='30' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhQ-2U2NkBT2A1ClHJhcSFh8G5s72Aoqi4JhS1vLNGmHiNT24OG24a46V4WoUfYFiOOZqcR_LZR6eeozjEnLJNiBdKIJZjE_icFodW7WGprayD-XW9cTt5GLcG6ZeBJRgw/s220/avatar.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-175557281513638.post-408360457769961199</id><published>2013-12-05T16:50:00.000-07:00</published><updated>2013-12-06T10:32:10.769-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="vCAC java odata4j"/><title type='text'>vCAC - Java and odata4j with self-signed cert</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;span style=&quot;font-size: x-small;&quot;&gt;Notes so I can remember how to configure the ClientBehavior to work with self signed certs using the odat4j consumer:&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-size: x-small;&quot;&gt;Builder builder = ODataJerseyConsumer.newBuilder(&quot;https://vcacserver.domain.com/repository/data/ManagementModelEntities.svc/&quot;);&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: x-small;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;builder.setClientBehaviors(AllowSelfSignedCertsBehavior.allowSelfSignedCerts());&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: x-small;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;ODataJerseyConsumer c = builder.build();&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: x-small;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;List&lt;oentity&gt; list = c.getEntities(&quot;VirtualMachineTemplates&quot;).execute().toList();&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;ArrayList&lt;string&gt; listUI = new ArrayList&lt;string&gt;();&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;for(OEntity category : list) {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; listUI.add(String.format(&quot;%s - %s&quot;, category.getProperty(&quot;VirtualMachineTemplateID&quot;).getValue().toString(), category.getProperty(&quot;CPUCount&quot;).getValue().toString()));&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/string&gt;&lt;/string&gt;&lt;/oentity&gt;&lt;/span&gt;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://rcampi.blogspot.com/feeds/408360457769961199/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://rcampi.blogspot.com/2013/12/vcac-java-and-odata4j-with-self-signed.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/175557281513638/posts/default/408360457769961199'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/175557281513638/posts/default/408360457769961199'/><link rel='alternate' type='text/html' href='http://rcampi.blogspot.com/2013/12/vcac-java-and-odata4j-with-self-signed.html' title='vCAC - Java and odata4j with self-signed cert'/><author><name>-campi</name><uri>http://www.blogger.com/profile/09146913336110357201</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='30' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhQ-2U2NkBT2A1ClHJhcSFh8G5s72Aoqi4JhS1vLNGmHiNT24OG24a46V4WoUfYFiOOZqcR_LZR6eeozjEnLJNiBdKIJZjE_icFodW7WGprayD-XW9cTt5GLcG6ZeBJRgw/s220/avatar.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-175557281513638.post-1851667860895947247</id><published>2013-10-24T12:51:00.001-06:00</published><updated>2013-10-25T13:22:29.239-06:00</updated><title type='text'>Powershell - Get Distinct Modulenames for Powershell version 4</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
Just get distinct modules available in the current powershell session (Server 2012 R2).&amp;nbsp; There are a lot more modules available in the PS version 4. &lt;br /&gt;
&lt;br /&gt;
get-command -all | sort-object modulename -unique | Select-object modulename&lt;br /&gt;
get-command | where {$_.modulename -eq &quot;DISM&quot;} | sort-object commandtype,name&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://rcampi.blogspot.com/feeds/1851667860895947247/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://rcampi.blogspot.com/2013/10/just-get-distinct-modules-available-in.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/175557281513638/posts/default/1851667860895947247'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/175557281513638/posts/default/1851667860895947247'/><link rel='alternate' type='text/html' href='http://rcampi.blogspot.com/2013/10/just-get-distinct-modules-available-in.html' title='Powershell - Get Distinct Modulenames for Powershell version 4'/><author><name>-campi</name><uri>http://www.blogger.com/profile/09146913336110357201</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='30' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhQ-2U2NkBT2A1ClHJhcSFh8G5s72Aoqi4JhS1vLNGmHiNT24OG24a46V4WoUfYFiOOZqcR_LZR6eeozjEnLJNiBdKIJZjE_icFodW7WGprayD-XW9cTt5GLcG6ZeBJRgw/s220/avatar.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-175557281513638.post-5930609690485441792</id><published>2012-07-02T18:24:00.001-06:00</published><updated>2012-09-13T10:49:31.036-06:00</updated><title type='text'>Powershell - Compare Files Between Two Servers</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
I know there are a lot of ways to do this, but here is another one. &amp;nbsp;Switch to a directory and run the following command on a working and non working server. &amp;nbsp;As is, this is comparing .dll files. &amp;nbsp;The results can easily be compared using windiff or similar utility to make sure all the versions of the files line up:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;color: #1f497d; font-family: Calibri, sans-serif;&quot;&gt;&lt;span style=&quot;font-size: 15px;&quot;&gt;gci . -filter *.dll -Recurse -force | select FullName,CreationTime,length,{$_.VersionInfo.FileVersion},{$_.VersionInfo.ProductVersion} | sort FullName | export-csv c:\temp\FileVersions.csv&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://rcampi.blogspot.com/feeds/5930609690485441792/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://rcampi.blogspot.com/2012/07/powershell-compare-files-between-two.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/175557281513638/posts/default/5930609690485441792'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/175557281513638/posts/default/5930609690485441792'/><link rel='alternate' type='text/html' href='http://rcampi.blogspot.com/2012/07/powershell-compare-files-between-two.html' title='Powershell - Compare Files Between Two Servers'/><author><name>-campi</name><uri>http://www.blogger.com/profile/09146913336110357201</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='30' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhQ-2U2NkBT2A1ClHJhcSFh8G5s72Aoqi4JhS1vLNGmHiNT24OG24a46V4WoUfYFiOOZqcR_LZR6eeozjEnLJNiBdKIJZjE_icFodW7WGprayD-XW9cTt5GLcG6ZeBJRgw/s220/avatar.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-175557281513638.post-8390835772716135454</id><published>2012-02-24T20:57:00.000-07:00</published><updated>2012-07-17T15:55:59.569-06:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="IIS cloning sysprep machineGUID"/><title type='text'>IIS 7.5 cloning - Machine Keys</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
Ran into an issue on Server 2008 R2 / IIS 7.5. &amp;nbsp;After cloning a server, the IIS Admin service would not start and we were no longer able to set application pool identities to a domain account. &amp;nbsp;You can save a local account as the app pool identity but not a domain account. &amp;nbsp;Turns out to be a well known and discussed issue with how Microsoft secures information in config files with unique machine keys. &amp;nbsp;One of the way the process locates the key is by using the machine GUID. &amp;nbsp;Following sysprep, this GUID changes and you get a new key.&amp;nbsp;&amp;nbsp;&amp;nbsp;If you have anything encrypted with old key, it is no longer accessible. &amp;nbsp;This is most likely why IIS supports sysprep now (IIS version 7.5) but not if you have identities that are encrypted in config files. &amp;nbsp;This method allows you to get around this but is not as secure as every server will have the same key following sysprep. &amp;nbsp;This code &quot;repairs&quot; the machine keys by renaming the old key with the new GUID. This was thrown together quickly, I will clean this up when I get a chance but this works for now.&lt;br /&gt;
&lt;br /&gt;
The application pools or the portion before the underscore is an identifier for the app pool it appears. &amp;nbsp;That portion may change or you may have more than is represented here. &amp;nbsp;You can change that to meet your needs.&lt;br /&gt;
&lt;br /&gt;
&lt;code&gt;&lt;/code&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;code&gt;#Variables&lt;/code&gt;&lt;br /&gt;
&lt;code&gt;$regGUIDPath = &quot;HKLM:\SOFTWARE\Microsoft\Cryptography&quot;&lt;/code&gt;&lt;br /&gt;
&lt;code&gt;$regGuidName = &quot;MachineGuid&quot;&lt;/code&gt;&lt;br /&gt;
&lt;code&gt;$machineKeyFolder = &quot;C:\ProgramData\Microsoft\Crypto\RSA\MachineKeys&quot;&lt;/code&gt;&lt;br /&gt;
&lt;code&gt;$key1 = &quot;c2319c42033a5ca7f44e731bfd3fa2b5_&quot;&lt;/code&gt;&lt;br /&gt;
&lt;code&gt;#$key2 = &quot;7a436fe806e483969f48a894af2fe9a1_&quot;&lt;/code&gt;&lt;br /&gt;
&lt;code&gt;$key2 = &quot;76944fb33636aeddb9590521c2e8815a_&quot;&lt;/code&gt;&lt;br /&gt;
&lt;code&gt;&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;
&lt;code&gt;#Get Current GUID&lt;/code&gt;&lt;br /&gt;
&lt;code&gt;$machGUID = &amp;nbsp;(Get-ItemProperty -Path $regGUIDPath -Name $regGuidName).MachineGuid&lt;/code&gt;&lt;br /&gt;
&lt;code&gt;&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;
&lt;code&gt;#Rename new one if it was created. &amp;nbsp;If IIS starts and there is no key, it will create a new one with new GUID&lt;/code&gt;&lt;br /&gt;
&lt;code&gt;if(test-path $machineKeyFolder\$key1$machGUID){&lt;/code&gt;&lt;br /&gt;
&lt;code&gt;&amp;nbsp; &amp;nbsp; ren &quot;$machineKeyFolder\$key1$machGUID&quot; &quot;$key1$machGUID.OLD&quot;&lt;/code&gt;&lt;br /&gt;
&lt;code&gt;}&lt;/code&gt;&lt;br /&gt;
&lt;code&gt;&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;
&lt;code&gt;if(test-path $machineKeyFolder\$key2$machGUID){&lt;/code&gt;&lt;br /&gt;
&lt;code&gt;&amp;nbsp; &amp;nbsp; ren &quot;$machineKeyFolder\$key2$machGUID&quot; &quot;$key2$machGUID.OLD&quot;&lt;/code&gt;&lt;br /&gt;
&lt;code&gt;}&lt;/code&gt;&lt;br /&gt;
&lt;code&gt;#Now find the oldest key and rename it using the new machine GUID&lt;/code&gt;&lt;br /&gt;
&lt;code&gt;$files = Get-ChildItem (&quot;$machineKeyFolder\*.*&quot;) -include (&quot;$key1*&quot;) | sort-object -property ($_.CreationTime)&lt;/code&gt;&lt;br /&gt;
&lt;code&gt;&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;
&lt;code&gt;foreach ($file in $files)&lt;/code&gt;&lt;br /&gt;
&lt;code&gt;{&lt;/code&gt;&lt;br /&gt;
&lt;code&gt;&amp;nbsp; &amp;nbsp; $fileName = $file.Name&lt;/code&gt;&lt;br /&gt;
&lt;code&gt;&amp;nbsp; &amp;nbsp; if (!$fileName.EndsWith($machGUID))&lt;/code&gt;&lt;br /&gt;
&lt;code&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; {&lt;/code&gt;&lt;br /&gt;
&lt;code&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; cp &quot;$machineKeyFolder\$fileName&quot; &quot;$machineKeyFolder\$fileName.OLD&quot;&lt;/code&gt;&lt;br /&gt;
&lt;code&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ren &quot;$machineKeyFolder\$fileName&quot; &quot;$key1$machGUID&quot;&lt;/code&gt;&lt;br /&gt;
&lt;code&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; break&lt;/code&gt;&lt;br /&gt;
&lt;code&gt;&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;
&lt;code&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/code&gt;&lt;br /&gt;
&lt;code&gt;}&lt;/code&gt;&lt;br /&gt;
&lt;code&gt;&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;
&lt;code&gt;$files = Get-ChildItem (&quot;$machineKeyFolder\*.*&quot;) -include (&quot;$key2*&quot;) | sort-object -property ($_.CreationTime)&lt;/code&gt;&lt;br /&gt;
&lt;code&gt;&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;
&lt;code&gt;foreach ($file in $files)&lt;/code&gt;&lt;br /&gt;
&lt;code&gt;{&lt;/code&gt;&lt;br /&gt;
&lt;code&gt;&amp;nbsp; &amp;nbsp; $fileName = $file.Name&lt;/code&gt;&lt;br /&gt;
&lt;code&gt;&amp;nbsp; &amp;nbsp; if (!$fileName.EndsWith($machGUID))&lt;/code&gt;&lt;br /&gt;
&lt;code&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; {&lt;/code&gt;&lt;br /&gt;
&lt;code&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; cp &quot;$machineKeyFolder\$fileName&quot; &quot;$machineKeyFolder\$fileName.OLD&quot;&lt;/code&gt;&lt;br /&gt;
&lt;code&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ren &quot;$machineKeyFolder\$fileName&quot; &quot;$key2$machGUID&quot;&lt;/code&gt;&lt;br /&gt;
&lt;code&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; break&lt;/code&gt;&lt;br /&gt;
&lt;code&gt;&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;
&lt;code&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/code&gt;&lt;br /&gt;
&lt;code&gt;}&lt;/code&gt;&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://rcampi.blogspot.com/feeds/8390835772716135454/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://rcampi.blogspot.com/2012/02/iis-75-cloning-machine-keys.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/175557281513638/posts/default/8390835772716135454'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/175557281513638/posts/default/8390835772716135454'/><link rel='alternate' type='text/html' href='http://rcampi.blogspot.com/2012/02/iis-75-cloning-machine-keys.html' title='IIS 7.5 cloning - Machine Keys'/><author><name>-campi</name><uri>http://www.blogger.com/profile/09146913336110357201</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='30' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhQ-2U2NkBT2A1ClHJhcSFh8G5s72Aoqi4JhS1vLNGmHiNT24OG24a46V4WoUfYFiOOZqcR_LZR6eeozjEnLJNiBdKIJZjE_icFodW7WGprayD-XW9cTt5GLcG6ZeBJRgw/s220/avatar.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-175557281513638.post-863029830483960276</id><published>2012-02-17T22:02:00.002-07:00</published><updated>2012-05-16T15:20:50.079-06:00</updated><title type='text'>Restart-Computer - Do Not Have Privilege Exception</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
Running Powershell version 2 on Server 2008 R2. &amp;nbsp;Simply run Restart-Computer and get an exception stating that the user does not have enough privilege to execute command. &amp;nbsp;Turns out Powershell is running in .Net 4 runtime. &amp;nbsp;Run the following command:&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;x_MsoNormal&quot; style=&quot;font-family: Calibri, sans-serif; font-size: 11pt; margin-bottom: 0.0001pt; margin-left: 0in; margin-right: 0in; margin-top: 0in; text-align: -webkit-auto;&quot;&gt;
[Runtime.InteropServices.RuntimeEnvironment]::GetRuntimeDirectory()&lt;/div&gt;
&lt;div class=&quot;x_MsoNormal&quot; style=&quot;font-family: Calibri, sans-serif; font-size: 11pt; margin-bottom: 0.0001pt; margin-left: 0in; margin-right: 0in; margin-top: 0in; text-align: -webkit-auto;&quot;&gt;
&amp;nbsp;&lt;span style=&quot;font-size: 11pt;&quot;&gt;C:\Windows\Microsoft.NET\Framework64\v2.0.50727\&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;x_MsoNormal&quot; style=&quot;font-family: Calibri, sans-serif; font-size: 11pt; margin-bottom: 0.0001pt; margin-left: 0in; margin-right: 0in; margin-top: 0in; text-align: -webkit-auto;&quot;&gt;
&lt;span style=&quot;font-size: 11pt;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;x_MsoNormal&quot; style=&quot;font-family: Calibri, sans-serif; font-size: 11pt; margin-bottom: 0.0001pt; margin-left: 0in; margin-right: 0in; margin-top: 0in; text-align: -webkit-auto;&quot;&gt;
&lt;span style=&quot;font-size: 11pt;&quot;&gt;If the version is not v2 &amp;nbsp;but v4. &amp;nbsp;Create a powershell.exe.config file in the powershell directory and add the following text:&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;x_MsoNormal&quot; style=&quot;font-family: Calibri, sans-serif; font-size: 11pt; margin-bottom: 0.0001pt; margin-left: 0in; margin-right: 0in; margin-top: 0in; text-align: -webkit-auto;&quot;&gt;
&lt;span style=&quot;font-size: 11pt;&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;div class=&quot;x_MsoNormal&quot; style=&quot;font-size: 11pt; margin-bottom: 0.0001pt; margin-left: 0in; margin-right: 0in; margin-top: 0in;&quot;&gt;
&lt;span style=&quot;font-size: 11pt;&quot;&gt;&lt;code&gt;&lt;/code&gt;&lt;/span&gt;&lt;br /&gt;
&lt;code&gt;&lt;span style=&quot;font-size: 11pt;&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;
&lt;div class=&quot;x_MsoNormal&quot; style=&quot;font-size: 11pt; margin-bottom: 0.0001pt; margin-left: 0in; margin-right: 0in; margin-top: 0in;&quot;&gt;
&lt;code&gt;&lt;span style=&quot;font-size: 11pt;&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/div&gt;
&lt;div class=&quot;x_MsoNormal&quot; style=&quot;font-size: 11pt; margin-bottom: 0.0001pt; margin-left: 0in; margin-right: 0in; margin-top: 0in;&quot;&gt;
&lt;code&gt;&lt;span style=&quot;font-size: 11pt;&quot;&gt;&lt;configuration&gt;&lt;/configuration&gt;&lt;/span&gt;&lt;/code&gt;&lt;/div&gt;
&lt;div class=&quot;x_MsoNormal&quot; style=&quot;font-size: 11pt; margin-bottom: 0.0001pt; margin-left: 0in; margin-right: 0in; margin-top: 0in;&quot;&gt;
&lt;code&gt;&lt;span style=&quot;font-size: 11pt;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;startup uselegacyv2runtimeactivationpolicy=&quot;true&quot;&gt;&lt;/startup&gt;&lt;/span&gt;&lt;/code&gt;&lt;/div&gt;
&lt;div class=&quot;x_MsoNormal&quot; style=&quot;font-size: 11pt; margin-bottom: 0.0001pt; margin-left: 0in; margin-right: 0in; margin-top: 0in;&quot;&gt;
&lt;span style=&quot;font-size: 11pt;&quot;&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;x_MsoNormal&quot; style=&quot;font-size: 11pt; margin-bottom: 0.0001pt; margin-left: 0in; margin-right: 0in; margin-top: 0in;&quot;&gt;
Restart powershell and it should work. Now to figure out why that happened in the first place.&lt;br /&gt;
&lt;br /&gt;
UPDATE: &amp;nbsp;Turns out a software vendor had set an environment variable called COMPLUS_Version in the installer. If this is set, it overrides normal assembly binding logic and forces all .net applications to run in that version of .net. &amp;nbsp;This should only be used for development or testing, not production environments.&lt;br /&gt;
&lt;span style=&quot;background-color: #616161; color: white; font-family: Consolas, &#39;Courier New&#39;, Fixed, monospace; font-size: x-small; line-height: 22px; text-align: -webkit-auto;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: #616161; color: white; font-family: Consolas, &#39;Courier New&#39;, Fixed, monospace; font-size: x-small; line-height: 22px; text-align: -webkit-auto;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: #616161; color: white; font-family: Consolas, &#39;Courier New&#39;, Fixed, monospace; font-size: x-small; line-height: 22px; text-align: -webkit-auto;&quot;&gt;set COMPLUS_Version = v3.5&lt;/span&gt;&lt;/div&gt;
&lt;br /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://rcampi.blogspot.com/feeds/863029830483960276/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://rcampi.blogspot.com/2012/02/restart-computer-do-not-have-privilege.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/175557281513638/posts/default/863029830483960276'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/175557281513638/posts/default/863029830483960276'/><link rel='alternate' type='text/html' href='http://rcampi.blogspot.com/2012/02/restart-computer-do-not-have-privilege.html' title='Restart-Computer - Do Not Have Privilege Exception'/><author><name>-campi</name><uri>http://www.blogger.com/profile/09146913336110357201</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='30' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhQ-2U2NkBT2A1ClHJhcSFh8G5s72Aoqi4JhS1vLNGmHiNT24OG24a46V4WoUfYFiOOZqcR_LZR6eeozjEnLJNiBdKIJZjE_icFodW7WGprayD-XW9cTt5GLcG6ZeBJRgw/s220/avatar.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-175557281513638.post-6979346904364275397</id><published>2011-12-20T09:34:00.003-07:00</published><updated>2012-02-24T21:11:26.622-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Powershell MSI Installer Function Win32_Product WMI"/><title type='text'>Powershell Uninstall Software Function</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;code&gt;Simple function to uninstall an application on a Windows Server. &amp;nbsp;This has been tested on Server 2008 R2. &amp;nbsp;You can pass the name of the application and it will attempt to uninstall as the user you are logged on as. &amp;nbsp;You can pass in credentials and it will attempt to use those to uninstall the application. &amp;nbsp;If it cannot find the application it will not throw an exception. &amp;nbsp;If something fails, it will throw an exception back to the calling code.&lt;/code&gt;&lt;br /&gt;
&lt;code&gt;&lt;br /&gt;
&lt;/code&gt;&lt;br /&gt;
&lt;code&gt;I wrote this after initially using the Win32_Product WMI class and the installer function. &amp;nbsp;However, that class is slow which I could live with. &amp;nbsp;The fact that it checks every installed application and potentially attempts to reconfigure the applications seemed like a bad idea. &amp;nbsp;This obviously does not use that class.&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt; Function uninstall-application(){&lt;br /&gt;
[CmdletBinding()]&lt;br /&gt;
Param ([Parameter(Position=1,Mandatory=$true, ValueFromPipelineByPropertyName=$true,HelpMessage=&quot;Application Name to be uninstalled&quot;)] [Alias(&quot;a&quot;)] [string]$appName,&lt;br /&gt;
[Parameter(Position=2,Mandatory=$false, ValueFromPipelineByPropertyName=$true,HelpMessage=&quot;If run as different user, pass a user name into the script&quot;)] [Alias(&quot;u&quot;)] [string]$userid,&lt;br /&gt;
[Parameter(Position=3,Mandatory=$false, ValueFromPipelineByPropertyName=$true,HelpMessage=&quot;The password for the user.&quot;)] [Alias(&quot;p&quot;)] [string]$pwd)&lt;br /&gt;
Process {&lt;br /&gt;
$Error.Clear()&lt;br /&gt;
try {&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
#expecting to be run in PS x64&lt;br /&gt;
$86 = &quot;HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall&quot;&lt;br /&gt;
$64 = &quot;HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall&quot;&lt;br /&gt;
[int]$ExitCode&lt;br /&gt;
&lt;br /&gt;
#Check for 32 bit version of the app&lt;br /&gt;
$appKey = Get-ChildItem -Path $86 | Where-Object -FilterScript { $_.GetValue(&quot;DisplayName&quot;) -ieq &quot;$appName&quot; -And $_.GetValue(&quot;UninstallString&quot;) -ne $null }&lt;br /&gt;
&lt;br /&gt;
#didn&#39;t find 32 bit version - check for 64 bit version&lt;br /&gt;
if ($appKey -isnot [Microsoft.Win32.RegistryKey])&lt;br /&gt;
{  &lt;br /&gt;
$appKey = Get-ChildItem -Path $64 | Where-Object -FilterScript { $_.GetValue(&quot;DisplayName&quot;) -ieq &quot;$appName&quot; -And $_.GetValue(&quot;UninstallString&quot;) -ne $null}&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
#Write-Host $appKey.gettype()&lt;br /&gt;
if ($appKey -is [Microsoft.Win32.RegistryKey]) # If it is a system.object or something else this will fail.&lt;br /&gt;
{&lt;br /&gt;
#Write-Host $appKey.gettype()&lt;br /&gt;
$UninstallString = $appKey.GetValue(&quot;UninstallString&quot;)&lt;br /&gt;
#Write-Host $UninstallString&lt;br /&gt;
} else { #The application was not found.&lt;br /&gt;
Write-Host &quot;The application $appName was not found so no uninstallation was performed.&quot;&lt;br /&gt;
}&lt;br /&gt;
#check to make sure this is an MSI based application so we don&#39;t get unexpected behavior&lt;br /&gt;
if ($UninstallString.StartsWith(&quot;msiexec.exe&quot;,&quot;CurrentCultureIgnoreCase&quot;))&lt;br /&gt;
{&lt;br /&gt;
$Arguments = @()&lt;br /&gt;
$Arguments += &quot;/Q&quot;&lt;br /&gt;
$Arguments += &quot;/X&quot;&lt;br /&gt;
$Arguments += $UninstallString.substring($UninstallString.indexof(&quot;{&quot;),$UninstallString.Length - $UninstallString.indexof(&quot;{&quot;))&lt;br /&gt;
if ($userid -and $pwd){&lt;br /&gt;
$secpasswd = ConvertTo-SecureString $pwd -AsPlainText -Force&lt;br /&gt;
$credential = New-Object System.Management.Automation.PsCredential($userid,$secpasswd)         &lt;br /&gt;
$ExitCode = (Start-Process -FilePath &quot;msiexec.exe&quot; -ArgumentList $Arguments -Credential $credential -Wait -Passthru).ExitCode&lt;br /&gt;
}&lt;br /&gt;
$ExitCode = (Start-Process -FilePath &quot;msiexec.exe&quot; -ArgumentList $Arguments -Wait -Passthru).ExitCode&lt;br /&gt;
if ($ExitCode -ne 0)&lt;br /&gt;
{&lt;br /&gt;
throw &quot;The MSI failed to get uninstalled.  MSIEXEC.exe returned an exit code of $ExitCode.&quot;&lt;br /&gt;
} &lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
}catch [Exception] {&lt;br /&gt;
$EMsg = Write-Host&amp;nbsp;&lt;/i&gt;
&lt;i&gt;&quot;Failed in WinUtils::uninstall-application : &quot; + $_.Exception&lt;/i&gt;&amp;nbsp;&lt;i&gt;&lt;br /&gt;
throw&lt;br /&gt;
}&lt;br /&gt;
}&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
measure-command {uninstall-application -a &quot;simp&lt;/i&gt;leInstall&quot;}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;/code&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://rcampi.blogspot.com/feeds/6979346904364275397/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://rcampi.blogspot.com/2011/12/powershell-uninstall-software-function.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/175557281513638/posts/default/6979346904364275397'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/175557281513638/posts/default/6979346904364275397'/><link rel='alternate' type='text/html' href='http://rcampi.blogspot.com/2011/12/powershell-uninstall-software-function.html' title='Powershell Uninstall Software Function'/><author><name>-campi</name><uri>http://www.blogger.com/profile/09146913336110357201</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='30' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhQ-2U2NkBT2A1ClHJhcSFh8G5s72Aoqi4JhS1vLNGmHiNT24OG24a46V4WoUfYFiOOZqcR_LZR6eeozjEnLJNiBdKIJZjE_icFodW7WGprayD-XW9cTt5GLcG6ZeBJRgw/s220/avatar.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-175557281513638.post-5598149048593494235</id><published>2011-10-23T20:33:00.001-06:00</published><updated>2011-10-24T09:25:39.746-06:00</updated><title type='text'>Powershell Remoting using SSL</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;Quick and dirty guide to using ssl to create remote powershell session.&amp;nbsp; First you need a certificate and private key to secure session with. Run the following command to create a certificate.&amp;nbsp; Bing makecert.exe utility which is part of the Windows SDK.&amp;nbsp; It is easier for a newbie to create certs using this than openssl tools.&amp;nbsp; This will create a cert and private key and put it in the store Local Machine -&amp;gt; Personal.&amp;nbsp; Search online on the command for more details.&amp;nbsp; The key/cert is that it will work as a server certificate.&lt;br /&gt;
&lt;br /&gt;
makecert -r -pe -n &quot;CN=computer.company.com&quot; -e &quot;12/31/2020&quot; -eku 1.3.6.1.5.5.7.3.1 -ss my -sr localmachine -sky exchange -sp &quot;Microsoft RSA SChannel Cryptographic Provider&quot; -sy 12&lt;br /&gt;
&lt;br /&gt;
Now you have a certificate and private key.&amp;nbsp; Run the following command to create an https listener for Windows Powershell.&amp;nbsp; You can get the thumbprint by looking at the properties of the cert.&lt;br /&gt;
&lt;br /&gt;
winrm create winrm/config/Listener?Address=*+Transport=HTTPS @{Hostname=&quot;computer.company.com&quot;;CertificateThumbprint=&quot;e5b45f100166fdfedab674ed6fb887dbafd99391&quot;}&lt;br /&gt;
&lt;br /&gt;
Now connect and start the automation from a remote system:&lt;br /&gt;
$pso = new-pssessionoption -SkipCNCheck -SkipCACheck&lt;br /&gt;
$sess = new-pssession -ConnectionUri &lt;a href=&quot;https://computer.company.com:5986/&quot;&gt;https://computer.company.com:5986&lt;/a&gt; -SessionOption $pso -credential company\awesomeAdmin&lt;br /&gt;
Enter-PSSEssion $sess&lt;br /&gt;
&lt;br /&gt;
#Run Commands to fully automate what I do . . . . .&lt;br /&gt;
&lt;br /&gt;
Remove-PSSession *&lt;br /&gt;
&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://rcampi.blogspot.com/feeds/5598149048593494235/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://rcampi.blogspot.com/2011/10/powershell-remoting-using-ssl.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/175557281513638/posts/default/5598149048593494235'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/175557281513638/posts/default/5598149048593494235'/><link rel='alternate' type='text/html' href='http://rcampi.blogspot.com/2011/10/powershell-remoting-using-ssl.html' title='Powershell Remoting using SSL'/><author><name>-campi</name><uri>http://www.blogger.com/profile/09146913336110357201</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='30' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhQ-2U2NkBT2A1ClHJhcSFh8G5s72Aoqi4JhS1vLNGmHiNT24OG24a46V4WoUfYFiOOZqcR_LZR6eeozjEnLJNiBdKIJZjE_icFodW7WGprayD-XW9cTt5GLcG6ZeBJRgw/s220/avatar.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-175557281513638.post-8176205176638567002</id><published>2011-08-26T21:39:00.000-06:00</published><updated>2011-08-26T21:39:53.686-06:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="powershell MSMQ Active Directory IIS Server"/><title type='text'>Server 2008 R2 MSMQ Issues</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;MSMQ has changed a little when using with Active Directory in Server 2008 R2.&amp;nbsp; When you install the Active Directory feature, the service installs using the network service account and attempts to use the computer account in AD to create the objects in sites and services of AD for public queues. &amp;nbsp; Default security does not allow that account to create those objects.&amp;nbsp; You can assign domain computers the create/delete/read to Servers folder in Sites and Services OR create a group, assign permissions to that group and add that computer account to that group prior to installing the feature.&amp;nbsp; You can run the following script to view permissions on that folder if you know the site the server is in prior to installing or just view permissions in sites and services.&amp;nbsp; We use this script to validate permissions prior to automating our MSMQ installations.&amp;nbsp; If permissions, install, else alert.&lt;br /&gt;
&lt;br /&gt;
&lt;code&gt;&lt;/code&gt;&lt;br /&gt;
&lt;code&gt;&amp;nbsp;[string] $OU = &quot;cn=Servers,cn=AlabamaSite,cn=Sites&quot;&lt;br /&gt;
$ConfigurationNC = ([ADSI]&quot;LDAP://RootDSE&quot;).configurationNamingContext&lt;br /&gt;
$LDAP = &quot;LDAP://&quot; + $OU&lt;br /&gt;
$SiteDN = ([ADSI]&quot;$LDAP,$ConfigurationNC&quot;)&lt;br /&gt;
$sd = $SiteDN.psbase.get_objectSecurity().getAccessRules($true,$false,[System.Security.Principal.NTAccount])&lt;br /&gt;
$sd&lt;/code&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://rcampi.blogspot.com/feeds/8176205176638567002/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://rcampi.blogspot.com/2011/08/server-2008-r2-msmq-issues.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/175557281513638/posts/default/8176205176638567002'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/175557281513638/posts/default/8176205176638567002'/><link rel='alternate' type='text/html' href='http://rcampi.blogspot.com/2011/08/server-2008-r2-msmq-issues.html' title='Server 2008 R2 MSMQ Issues'/><author><name>-campi</name><uri>http://www.blogger.com/profile/09146913336110357201</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='30' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhQ-2U2NkBT2A1ClHJhcSFh8G5s72Aoqi4JhS1vLNGmHiNT24OG24a46V4WoUfYFiOOZqcR_LZR6eeozjEnLJNiBdKIJZjE_icFodW7WGprayD-XW9cTt5GLcG6ZeBJRgw/s220/avatar.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-175557281513638.post-2966368489343940043</id><published>2011-08-22T20:31:00.000-06:00</published><updated>2012-02-24T21:13:40.373-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Powershell Security Windows"/><title type='text'>Powershell - Not so elegant way to output Privileges via Powershell</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
Ghetto way to output privileges using Powershell.&amp;nbsp; Useful when troubleshooting things like group policy, scripts or any other sources that may change privileges from what they should be. May generate a hash from this and automate a quick hash difference to monitor changes to privileges on systems.&lt;br /&gt;
&lt;br /&gt;
&lt;code&gt; &lt;/code&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: monospace;&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: monospace;&quot;&gt;#Variables&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: monospace;&quot;&gt;$computername= $env:COMPUTERNAME&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: monospace;&quot;&gt;$tempdir = &quot;c:\temp&quot;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: monospace;&quot;&gt;$file = &quot;$tempdir\privs.txt&quot;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: monospace;&quot;&gt;[string] $readableNames&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: monospace;&quot;&gt;$outHash = @{}&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: monospace;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: monospace;&quot;&gt;##### Generate report with just USER_RIGHTS ######&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: monospace;&quot;&gt;$process = [diagnostics.process]::Start(&quot;secedit.exe&quot;, &quot;/export /areas USER_RIGHTS /cfg $file&quot;)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: monospace;&quot;&gt;$process.WaitForExit()&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: monospace;&quot;&gt;$in = get-content $file&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: monospace;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: monospace;&quot;&gt;# start check of local userrights&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: monospace;&quot;&gt;foreach ($line in $in) {&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;if ($line.StartsWith(&quot;Se&quot;)) {&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;$privilege = $line.substring(0,$line.IndexOf(&quot;=&quot;) - 1)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;$sids = $line.substring($line.IndexOf(&quot;=&quot;) + 1,$line.Length - ($line.IndexOf(&quot;=&quot;) + 1))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;$sids = &amp;nbsp;$sids.Trim() -split &quot;,&quot;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;$readableNames = &quot;&quot;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;foreach ($str in $sids){&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; Write-Host $str&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; if ($str.StartsWith(&quot;*S-&quot;)) {&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; $str = $str.substring(1) # For some reason, secedit appends a * to the SID like *S-1-5-32-544, this just strips the first character&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; $sid = new-object System.Security.Principal.SecurityIdentifier($str)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; $readableName = $sid.Translate([System.Security.Principal.NTAccount])&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; $readableNames = $readableNames + $readableName.Value + &quot;,&quot;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; } else {&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; $readableName = $str&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; $readableNames = $readableNames + $readableName + &quot;,&quot;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; }&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp; }&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;$outHash.Add($privilege,$readableNames.substring(0,($readableNames.Length - 1))) #output edited version&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;}&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: monospace;&quot;&gt;}&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: monospace;&quot;&gt;$outHash&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: monospace;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: monospace;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://rcampi.blogspot.com/feeds/2966368489343940043/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://rcampi.blogspot.com/2011/08/powershell-ghetto-way-to-output.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/175557281513638/posts/default/2966368489343940043'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/175557281513638/posts/default/2966368489343940043'/><link rel='alternate' type='text/html' href='http://rcampi.blogspot.com/2011/08/powershell-ghetto-way-to-output.html' title='Powershell - Not so elegant way to output Privileges via Powershell'/><author><name>-campi</name><uri>http://www.blogger.com/profile/09146913336110357201</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='30' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhQ-2U2NkBT2A1ClHJhcSFh8G5s72Aoqi4JhS1vLNGmHiNT24OG24a46V4WoUfYFiOOZqcR_LZR6eeozjEnLJNiBdKIJZjE_icFodW7WGprayD-XW9cTt5GLcG6ZeBJRgw/s220/avatar.jpg'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-175557281513638.post-8710610722983590838</id><published>2011-08-18T21:44:00.000-06:00</published><updated>2011-08-18T21:44:57.798-06:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="vbscript logging IIS Windows Powershell"/><title type='text'>Simple Script to Rotate Log Files Without Backup or Zip</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;Haven&#39;t used this script in awhile but in the interest of sharing, hope someone may get something out of this. I will post another one that is more mature that can archive older content.&amp;nbsp; This is vbscript, new stuff is powershell. &lt;br /&gt;
&lt;br /&gt;
&lt;code&gt;&lt;/code&gt;&lt;br /&gt;
&lt;code&gt;sFileName = &quot;Junk.txt&quot; &#39;logfile to archive&lt;br /&gt;
sPath = &quot;C:\Temp\Telalert\log\&quot;&lt;br /&gt;
sLogFile = sPath &amp;amp; sFileName&lt;br /&gt;
iInt = 5 &#39;days to keep logs&lt;br /&gt;
count = 1&lt;br /&gt;
&#39;Create Objects&lt;br /&gt;
Set oFso = CreateObject(&quot;Scripting.FileSystemObject&quot;)&lt;br /&gt;
Set oWshshell = CreateObject(&quot;Wscript.Shell&quot;)&lt;br /&gt;
&lt;br /&gt;
&#39;Main&lt;br /&gt;
On Error resume next&lt;br /&gt;
If (oFso.FileExists(sLogFile)) Then&lt;br /&gt;
&amp;nbsp;sRenameFile = sPath &amp;amp; Replace(Date(), &quot;/&quot;, &quot;-&quot;) &amp;amp; sFileName&lt;br /&gt;
&amp;nbsp;If (oFso.FileExists(sRenameFile)) Then&lt;br /&gt;
&amp;nbsp; Do While oFso.FileExists(sRenameFile) &lt;br /&gt;
&amp;nbsp;&amp;nbsp; sRenameFile = sPath &amp;amp; Replace(Date(), &quot;/&quot;, &quot;-&quot;) &amp;amp; &quot;-&quot; &amp;amp; count &amp;amp; &quot;-&quot;&amp;amp; sFileName&lt;br /&gt;
&amp;nbsp;&amp;nbsp; count = count + 1&lt;br /&gt;
&amp;nbsp; Loop&lt;br /&gt;
&amp;nbsp;End If&lt;br /&gt;
oFso.MoveFile sLogFile,sRenameFile&lt;br /&gt;
If Error &amp;lt;&amp;gt; 0 Then&lt;br /&gt;
&amp;nbsp; oWshshell.LogEvent 1,&quot;LogRotator.vbs: Error renaming &quot;&amp;amp;sLogFile&amp;amp;&quot;.&amp;nbsp; Exiting&quot;&lt;br /&gt;
&amp;nbsp; CloseSession&lt;br /&gt;
End If&lt;br /&gt;
Set fils = oFso.GetFolder(sPath).Files&lt;br /&gt;
For Each fil In fils&lt;br /&gt;
&amp;nbsp;sfile = fil.name&lt;br /&gt;
&amp;nbsp;If InStr(1,sfile,sFileName) then&lt;br /&gt;
&amp;nbsp; If IsDate(Left(sfile,10)) then&lt;br /&gt;
&amp;nbsp;&amp;nbsp; sDate = CDate(Left(sfile,10))&lt;br /&gt;
&amp;nbsp;&amp;nbsp; days = DateDiff(&quot;d&quot;,sDate,date())&lt;br /&gt;
&amp;nbsp;&amp;nbsp; If days &amp;gt;= iInt then&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; oFso.DeleteFile sPath &amp;amp; sfile&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; If Error &amp;lt;&amp;gt; 0 then&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; oWshshell.LogEvent 1,&quot;LogRotator.vbs: Error deleting &quot;&amp;amp;Path&amp;amp;sfile&amp;amp;&quot;.&amp;nbsp; Exiting&quot;&amp;nbsp; &lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; end If&lt;br /&gt;
&amp;nbsp;&amp;nbsp; end if&lt;br /&gt;
&amp;nbsp; end if&lt;br /&gt;
&amp;nbsp;end if&amp;nbsp; &lt;br /&gt;
Next&lt;br /&gt;
Else&lt;br /&gt;
&amp;nbsp;oWshshell.LogEvent 1,&quot;LogRotator.vbs: Logfile &quot; &amp;amp; sLogFile &amp;amp; &quot; does not exist.&amp;nbsp; Exiting&quot;&lt;br /&gt;
&amp;nbsp;CloseSession&lt;br /&gt;
End If&lt;br /&gt;
oWshshell.LogEvent 0,&quot;LogRotator.vbs: Logfile &quot; &amp;amp; sLogFile &amp;amp; &quot; has been archived as &quot; &amp;amp; _&lt;br /&gt;
sRenameFile &amp;amp; &quot;.&amp;nbsp; Exiting&quot;&lt;br /&gt;
CloseSession &lt;br /&gt;
&#39;------------------------------------------------------------------------&lt;br /&gt;
Sub CloseSession&lt;br /&gt;
On Error Resume Next&lt;br /&gt;
&amp;nbsp;Set oFSO = Nothing&lt;br /&gt;
&amp;nbsp;Set oWshshell = Nothing&lt;br /&gt;
&amp;nbsp;Set objReg = Nothing&lt;br /&gt;
&amp;nbsp;hInput.Close&lt;br /&gt;
&amp;nbsp;hOutput.Close&lt;br /&gt;
&amp;nbsp;hErr.Close&lt;br /&gt;
&amp;nbsp;WScript.Quit&lt;br /&gt;
End Sub &lt;/code&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://rcampi.blogspot.com/feeds/8710610722983590838/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://rcampi.blogspot.com/2011/08/simple-script-to-rotate-log-files.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/175557281513638/posts/default/8710610722983590838'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/175557281513638/posts/default/8710610722983590838'/><link rel='alternate' type='text/html' href='http://rcampi.blogspot.com/2011/08/simple-script-to-rotate-log-files.html' title='Simple Script to Rotate Log Files Without Backup or Zip'/><author><name>-campi</name><uri>http://www.blogger.com/profile/09146913336110357201</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='30' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhQ-2U2NkBT2A1ClHJhcSFh8G5s72Aoqi4JhS1vLNGmHiNT24OG24a46V4WoUfYFiOOZqcR_LZR6eeozjEnLJNiBdKIJZjE_icFodW7WGprayD-XW9cTt5GLcG6ZeBJRgw/s220/avatar.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-175557281513638.post-1186096980618888168</id><published>2011-08-17T21:34:00.000-06:00</published><updated>2011-08-17T21:34:39.399-06:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="vbscript IIS monitoring"/><title type='text'>Simple vbscript for Monitoring Web Site Availability</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;Simple vbscript that was used for quite awhile to monitor a troublesome web site and restart IIS on failure.&amp;nbsp; This was running as a scheduled task on Windows Server 2003 for a long time but not tested on newer server versions.&amp;nbsp; Just replace strsearch variable with valid HTML returned from the page you configure.&amp;nbsp; It will create and log to the same directory the script is executing from.&amp;nbsp; Hope this helps someone looking for a quick temporary solution.&lt;br /&gt;
&lt;br /&gt;
&lt;code&gt;&lt;/code&gt;&lt;br /&gt;
&lt;code&gt;On Error Resume Next &lt;/code&gt;&lt;br /&gt;
&lt;code&gt;Set objFSO = Wscript.CreateObject(&quot;Scripting.FileSystemObject&quot;)&lt;br /&gt;
Set objWinHttp = Wscript.CreateObject(&quot;WinHttp.WinHttpRequest.5&quot;)&lt;br /&gt;
Set objShell = WScript.CreateObject(&quot;WScript.Shell&quot;)&lt;br /&gt;
scriptname = WScript.ScriptFullName&lt;br /&gt;
&#39;get path to script&lt;br /&gt;
path = Left(scriptname, InStrRev(scriptname, &quot;\&quot;))&lt;br /&gt;
Set Output = objFSO.OpenTextFile(path &amp;amp; &quot;WebAvailability.log&quot;,8,true)&lt;br /&gt;
&lt;br /&gt;
objWinHttp.Open &quot;GET&quot;, &quot;http://www.website.com/testpage.aspx&quot; , false&lt;br /&gt;
objWinHttp.Send&lt;br /&gt;
If err &amp;lt;&amp;gt; 0 then&lt;br /&gt;
&amp;nbsp;output.writeline &quot;Error&quot; &amp;amp; &quot;,&quot; &amp;amp; Now&lt;br /&gt;
&amp;nbsp;objShell.LogEvent 1, &quot;Site encountered following error: The web server is not responding to request&quot;&lt;br /&gt;
&amp;nbsp;Wscript.quit&lt;br /&gt;
End If&lt;br /&gt;
return = objWinHttp.ResponseText&lt;br /&gt;
strSearch = &quot;Successful - This is text returned from the web page when successful&quot;&lt;br /&gt;
intPos = inStr(return,strSearch) &lt;br /&gt;
If intPos = 0 then&lt;br /&gt;
&amp;nbsp;output.writeline &quot;Error&quot; &amp;amp; &quot;,&quot; &amp;amp; Now&lt;br /&gt;
&amp;nbsp;output.writeline return&lt;br /&gt;
&amp;nbsp;objShell.LogEvent 1, &quot;website encountered following error:&quot; &amp;amp; vbCrLf &amp;amp; return&lt;br /&gt;
&amp;nbsp;output.writeline &quot;Restarting IIS,&quot; &amp;amp; Now&lt;br /&gt;
&amp;nbsp;objShell.run &quot;iisreset /restart&quot;&lt;br /&gt;
Else&lt;br /&gt;
&amp;nbsp;output.writeline &quot;Successful&quot; &amp;amp; &quot;,&quot; &amp;amp; Now&lt;br /&gt;
End if&lt;br /&gt;
&lt;br /&gt;
Set objFSO = Nothing&lt;br /&gt;
Set objWinHttp = Nothing&lt;br /&gt;
Set objShell = Nothing&lt;/code&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://rcampi.blogspot.com/feeds/1186096980618888168/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://rcampi.blogspot.com/2011/08/simple-vbscript-for-monitoring-web-site.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/175557281513638/posts/default/1186096980618888168'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/175557281513638/posts/default/1186096980618888168'/><link rel='alternate' type='text/html' href='http://rcampi.blogspot.com/2011/08/simple-vbscript-for-monitoring-web-site.html' title='Simple vbscript for Monitoring Web Site Availability'/><author><name>-campi</name><uri>http://www.blogger.com/profile/09146913336110357201</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='30' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhQ-2U2NkBT2A1ClHJhcSFh8G5s72Aoqi4JhS1vLNGmHiNT24OG24a46V4WoUfYFiOOZqcR_LZR6eeozjEnLJNiBdKIJZjE_icFodW7WGprayD-XW9cTt5GLcG6ZeBJRgw/s220/avatar.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-175557281513638.post-5336952760588826964</id><published>2011-08-15T14:06:00.001-06:00</published><updated>2011-08-16T08:37:33.625-06:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="powershell Windows Server"/><title type='text'>Powershell - Quick Way to delete all event log entries</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;The native clear-eventlog method in Powershell v2 does not work with all the event logs.&amp;nbsp; We run this on templates before we package them for sysprep to clean up the logs.&amp;nbsp; This method deletes them all, and there are quite a few in Server 2008 R2.:&lt;br /&gt;
&lt;br /&gt;
$logs = @()&lt;br /&gt;
$logs = get-winevent -ListLog *&lt;br /&gt;
foreach ($log in $logs){ [System.Diagnostics.Eventing.Reader.EventLogSession]::GlobalSession.ClearLog($log.LogName)}&amp;nbsp; &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://rcampi.blogspot.com/feeds/5336952760588826964/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://rcampi.blogspot.com/2011/08/powershell-quick-way-to-delete-all.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/175557281513638/posts/default/5336952760588826964'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/175557281513638/posts/default/5336952760588826964'/><link rel='alternate' type='text/html' href='http://rcampi.blogspot.com/2011/08/powershell-quick-way-to-delete-all.html' title='Powershell - Quick Way to delete all event log entries'/><author><name>-campi</name><uri>http://www.blogger.com/profile/09146913336110357201</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='30' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhQ-2U2NkBT2A1ClHJhcSFh8G5s72Aoqi4JhS1vLNGmHiNT24OG24a46V4WoUfYFiOOZqcR_LZR6eeozjEnLJNiBdKIJZjE_icFodW7WGprayD-XW9cTt5GLcG6ZeBJRgw/s220/avatar.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-175557281513638.post-521642916805460662</id><published>2011-08-11T18:52:00.002-06:00</published><updated>2011-08-11T18:52:55.501-06:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Powershell FTP"/><title type='text'>Nice little Function so you can FTP using binary mode</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;##Purpose of this function is to FTP file.&amp;nbsp; If you want to specify binary you can&#39;t use simple WebClient method&lt;br /&gt;
function ftpfile{ param([string]$filename,[string]$port=21,[string]$user,[string]$pass,[string]$ftpUri) &lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; #Write-output $filename&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; #Write-output $port&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; #Write-output $user&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; #Write-output $pass&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; #Write-output $ftpUri&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; $fileContent = [System.IO.File]::ReadAllBytes($fileName)&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; $req = [System.Net.FtpWebRequest]::create($ftpUri)&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; $req.Method = [System.Net.WebRequestMethods+Ftp]::UploadFile&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; $req.Credentials =&amp;nbsp; New-Object System.net.NetworkCredential($user,$pass)&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; $req.UseBinary = $true&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; $req.ContentLength = $fileContent.Length&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; $requestStream = $req.GetRequestStream()&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; $requestStream.Write($fileContent,0, $fileContent.Length)&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; $requestStream.Close()&lt;br /&gt;
} &lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://rcampi.blogspot.com/feeds/521642916805460662/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://rcampi.blogspot.com/2011/08/nice-little-function-so-you-can-ftp.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/175557281513638/posts/default/521642916805460662'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/175557281513638/posts/default/521642916805460662'/><link rel='alternate' type='text/html' href='http://rcampi.blogspot.com/2011/08/nice-little-function-so-you-can-ftp.html' title='Nice little Function so you can FTP using binary mode'/><author><name>-campi</name><uri>http://www.blogger.com/profile/09146913336110357201</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='30' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhQ-2U2NkBT2A1ClHJhcSFh8G5s72Aoqi4JhS1vLNGmHiNT24OG24a46V4WoUfYFiOOZqcR_LZR6eeozjEnLJNiBdKIJZjE_icFodW7WGprayD-XW9cTt5GLcG6ZeBJRgw/s220/avatar.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-175557281513638.post-3704778386282402279</id><published>2011-07-06T21:12:00.005-06:00</published><updated>2012-05-11T07:24:52.001-06:00</updated><title type='text'>Powershell - Add domain account to local Administrators group when authenticated with local account</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
I thought you may need to authenticate to the domain to add a domain account to the local group but you just need to provide it in a string formatted like below.&amp;nbsp; When I was looking at samples, they all showed logging on via LDAP to browse the directory.&amp;nbsp; If you know what the account is, authentication isn&#39;t needed.&lt;br /&gt;
&lt;br /&gt;
$user = &quot;WinNT://domain.local.pri/service.account&quot;&lt;br /&gt;
$group = New-Object System.DirectoryServices.DirectoryEntry(&quot;WinNT://./Administrators&quot;)&lt;br /&gt;
$group.PSBase.Invoke(&quot;Add&quot;,$user)&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://rcampi.blogspot.com/feeds/3704778386282402279/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://rcampi.blogspot.com/2011/07/powershell-add-domain-account-to-local.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/175557281513638/posts/default/3704778386282402279'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/175557281513638/posts/default/3704778386282402279'/><link rel='alternate' type='text/html' href='http://rcampi.blogspot.com/2011/07/powershell-add-domain-account-to-local.html' title='Powershell - Add domain account to local Administrators group when authenticated with local account'/><author><name>-campi</name><uri>http://www.blogger.com/profile/09146913336110357201</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='30' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhQ-2U2NkBT2A1ClHJhcSFh8G5s72Aoqi4JhS1vLNGmHiNT24OG24a46V4WoUfYFiOOZqcR_LZR6eeozjEnLJNiBdKIJZjE_icFodW7WGprayD-XW9cTt5GLcG6ZeBJRgw/s220/avatar.jpg'/></author><thr:total>0</thr:total></entry></feed>