<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:atom="https://www.w3.org/2005/Atom" xmlns:sy="https://purl.org/rss/1.0/modules/syndication/" xmlns:dc="https://purl.org/dc/elements/1.1/" xmlns:content="https://purl.org/rss/1.0/modules/content/" xmlns:wfw="https://wellformedweb.org/CommentAPI/" xmlns:slash="https://purl.org/rss/1.0/modules/slash/"
  version="2.0">
  <channel>
    <title>PowerShell Notes</title>
    <atom:link
      href="https://docs.microsoft.com/archive/blogs/candede/feed.xml"
      rel="self"
      type="application/rss+xml" />
    <link>https://docs.microsoft.com/archive/blogs/candede/feed.xml</link>
    <description />
    <lastBuildDate>Tue, 16 Apr 2019 04:50:15 GMT</lastBuildDate>
    <language>en-US</language>
    <sy:updatePeriod>hourly</sy:updatePeriod>
    <sy:updateFrequency>1</sy:updateFrequency>
    <item>
      <title>RBAC Manager for Exchange 2010 Project on Codeplex</title>
      <link>https://docs.microsoft.com/archive/blogs/candede/rbac-manager-for-exchange-2010-project-on-codeplex</link>
      <pubDate>Tue, 03 Aug 2010 06:48:00 GMT</pubDate>
      <dc:creator><![CDATA[candede]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/candede/2010/08/03/rbac-manager-for-exchange-2010-project-on-codeplex/</guid>
      <description><![CDATA[Latest Version 1.5.5.0
https://rbac.codeplex.com]]></description>
      <content:encoded><![CDATA[<p>Latest Version 1.5.5.0</p>
<p><a href="https://rbac.codeplex.com">https://rbac.codeplex.com</a></p>]]></content:encoded>
    </item>
    <item>
      <title>Setting Access Control Entries (ACEs) of directory objects in Powershell</title>
      <link>https://docs.microsoft.com/archive/blogs/candede/setting-access-control-entries-aces-of-directory-objects-in-powershell</link>
      <pubDate>Fri, 22 Jan 2010 12:39:00 GMT</pubDate>
      <dc:creator><![CDATA[candede]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/candede/2010/01/22/setting-access-control-entries-aces-of-directory-objects-in-powershell/</guid>
      <description><![CDATA[Please check Get Access Control Entry (ACE) of directory objects in Powershell&nbsp;post for...]]></description>
      <content:encoded><![CDATA[<P>Please check <A title=Get-Ace href="https://blogs.msdn.com/candede/archive/2010/01/22/get-access-control-entry-ace-of-directory-objects-in-powershell.aspx" mce_href="https://blogs.msdn.com/candede/archive/2010/01/22/get-access-control-entry-ace-of-directory-objects-in-powershell.aspx">Get Access Control Entry (ACE) of directory objects in Powershell</A>&nbsp;post for background information. <STRONG>Please be warned without taking any further action</STRONG>; the script provided in this post is still under construction; to be honest this is true for every other script you can find on this blog but there is an <STRONG><EM>extra warning</EM></STRONG> here as this will alter the security permissions; damage can be done more easily. I need to do more testing and develop some poor areas which I know they exists but couldnt find time yet to correct them</P>
<P>&nbsp;a picture worth a thousand words :)</P>
<P><IMG style="WIDTH: 1251px; HEIGHT: 425px" title=Set-Ace alt=Set-Ace src="https://hwnn7a.bay.livefilestore.com/y1p6-YTe2qAMiH1WVI4wQuWcgo0voyp7VP2EHikknJPpmFkP_QU-J8dtEKH3RRQ5wNR02AXQelUXO5V9VVoYtsjA4INxxc206TZ/Set-Ace.PNG" width=1251 height=425 mce_src="https://hwnn7a.bay.livefilestore.com/y1p6-YTe2qAMiH1WVI4wQuWcgo0voyp7VP2EHikknJPpmFkP_QU-J8dtEKH3RRQ5wNR02AXQelUXO5V9VVoYtsjA4INxxc206TZ/Set-Ace.PNG"></P>
<P mce_keep="true">Reference #1: <A href="https://www.microsoft.com/technet/scriptcenter/resources/pstips/may08/pstip0516.mspx">https://www.microsoft.com/technet/scriptcenter/resources/pstips/may08/pstip0516.mspx</A></P>
<P>Cheers, CanD</P>
<p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Components.PostAttachments/00/09/95/21/61/Set-Ace.ps1" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-components-postattachments/00-09-95-21-61/Set_2D00_Ace.ps1">Set-Ace.ps1</a></p>]]></content:encoded>
    </item>
    <item>
      <title>Getting Access Control Entries (ACEs) of directory objects in Powershell</title>
      <link>https://docs.microsoft.com/archive/blogs/candede/getting-access-control-entries-aces-of-directory-objects-in-powershell</link>
      <pubDate>Fri, 22 Jan 2010 10:49:00 GMT</pubDate>
      <dc:creator><![CDATA[candede]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/candede/2010/01/22/getting-access-control-entries-aces-of-directory-objects-in-powershell/</guid>
      <description><![CDATA[You can use Get-Acl / Set-Acl cmdlets to change the security permissions of directory objects in...]]></description>
      <content:encoded><![CDATA[<P>You can use Get-Acl / Set-Acl cmdlets to change the security permissions of directory objects in Powershell; but Set-Acl does not give you any option other than making a copy-paste of one file's ACL&nbsp;to another. Simply you can get the Access Control List of one file with Get-Acl and then use Set-Acl to assign that ACL to whatever file(s) you want; but there is no way to change that ACL in the way like adding or removing new ACEs (at least with standart cmdlets; at least I dont know now if there is any)</P>
<P>Get-Ace indeed uses Get-Acl cmdlet and doing nothing special that you can't do with Get-Acl. So why we need that? It just exists to make things easier&nbsp;when one is using Set-Acl which is the subject of next post</P>
<P>Standart output of the Get-Ace (<STRONG>check the attachment for .ps1 file</STRONG>)&nbsp;with no parameters; this will return all of the ACEs which can be assigned to a variable</P>
<P><IMG style="WIDTH: 914px; HEIGHT: 410px" title=Get-Acl alt=Get-Acl src="https://hwnn7a.bay.livefilestore.com/y1p40G6fOtsKDBMWiRJxqB7L3rMh3N5c0kf9CTzDy2FtqasAyzwKWu7BDaKSeA0UiWWVM8Ia__GXemKA9gtvoILYzIPS1Alm6rs/Get-Ace.PNG" width=914 height=410 mce_src="https://hwnn7a.bay.livefilestore.com/y1p40G6fOtsKDBMWiRJxqB7L3rMh3N5c0kf9CTzDy2FtqasAyzwKWu7BDaKSeA0UiWWVM8Ia__GXemKA9gtvoILYzIPS1Alm6rs/Get-Ace.PNG"></P>
<P mce_keep="true">&nbsp;</P>
<P>Usage of the Get-Ace with -List and -Number parameter; -List parameter returns a numbered list so that you can associate an ACE with a number and call it later with -Number parameter. With -Number you can return single ACE from the ACL and assign it to a varibable. For example;</P>
<P>&nbsp;$authUserAce = Get-Ace c:\ps\test.txt -Number 3</P>
<P><IMG style="WIDTH: 997px; HEIGHT: 284px" title="Get-Ace -List" alt="Get-Ace -List" src="https://hwnn7a.bay.livefilestore.com/y1pEO8JsYPnoPJHE8SZ4huz_NWtqWVr9YPMusbwT2mW27p4WVllYnUmaXO1mZwcGmEC4qFk7EmapF8lQNRC-GzfXDGDxlunhhMi/Get-Ace2.PNG" width=997 height=284 mce_src="https://hwnn7a.bay.livefilestore.com/y1pEO8JsYPnoPJHE8SZ4huz_NWtqWVr9YPMusbwT2mW27p4WVllYnUmaXO1mZwcGmEC4qFk7EmapF8lQNRC-GzfXDGDxlunhhMi/Get-Ace2.PNG">&nbsp;</P>
<P mce_keep="true">Cheers, CanD</P>
<p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Components.PostAttachments/00/09/95/21/40/Get-Ace.ps1" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-components-postattachments/00-09-95-21-40/Get_2D00_Ace.ps1">Get-Ace.ps1</a></p>]]></content:encoded>
    </item>
    <item>
      <title>Parameter Types in Powershell</title>
      <link>https://docs.microsoft.com/archive/blogs/candede/parameter-types-in-powershell</link>
      <pubDate>Thu, 14 Jan 2010 12:39:00 GMT</pubDate>
      <dc:creator><![CDATA[candede]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/candede/2010/01/14/parameter-types-in-powershell/</guid>
      <description><![CDATA[In my previous posts I used "-AsJob" parameter to determine if&nbsp;function will be called as a...]]></description>
      <content:encoded><![CDATA[<P>In my previous posts I used "-AsJob" parameter to determine if&nbsp;function will be called as a background Powershell&nbsp;job or not. I declared "$AsJob" object as [bool] so one should type explicitly&nbsp;"-AsJob $true" or "-AsJob $false" to make it run. I was trying to figure out a way to get rid of unnecessary $true/$false typings and I encountered with the sites in references. So I learnt what I was searching for; it's called "<STRONG>switch parameter</STRONG>"</P>
<P>For example "<A title="Monitor File Size" href="https://blogs.msdn.com/candede/archive/2010/01/14/monitor-file-size.aspx" mce_href="https://blogs.msdn.com/candede/archive/2010/01/14/monitor-file-size.aspx">Test-FileSizeUntil</A>" function had the following parameter declaration; $AsJob&nbsp;is [bool] -&gt; BAD IDEA :)</P>
<P>[Parameter(mandatory=$false)]<BR>[bool]$AsJob=$false</P>
<P><EM>it should be:</EM></P>
<P>[Parameter(mandatory=$false)]<BR>[switch]$AsJob</P>
<P>Check the references for more info..</P>
<P>Reference#1: <A href="https://devcentral.f5.com/weblogs/Joe/archive/2009/01/13/powershell-abcs---p-is-for-parameters.aspx" mce_href="https://devcentral.f5.com/weblogs/Joe/archive/2009/01/13/powershell-abcs---p-is-for-parameters.aspx">https://devcentral.f5.com/weblogs/Joe/archive/2009/01/13/powershell-abcs---p-is-for-parameters.aspx</A></P>
<P>Reference#2: <A href="https://msgoodies.blogspot.com/2006/12/negating-powershell-switch-parameters.html" mce_href="https://msgoodies.blogspot.com/2006/12/negating-powershell-switch-parameters.html">https://msgoodies.blogspot.com/2006/12/negating-powershell-switch-parameters.html</A></P>
<P>&nbsp;Cheers, CanD</P>]]></content:encoded>
    </item>
    <item>
      <title>Monitor File Size</title>
      <link>https://docs.microsoft.com/archive/blogs/candede/monitor-file-size</link>
      <pubDate>Thu, 14 Jan 2010 04:11:00 GMT</pubDate>
      <dc:creator><![CDATA[candede]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/candede/2010/01/14/monitor-file-size/</guid>
      <description><![CDATA[Test-FileSizeUntil monitors the size of a file and triggers an action when it reaches a certain...]]></description>
      <content:encoded><![CDATA[<P>Test-FileSizeUntil monitors the size of a file and triggers an action when it reaches a certain value. Basically I wrote it for a colleague who needs to create an action when a log file reaches a specific size. It monitors the size periodically; by default every 30 seconds and this behaviour can be changed&nbsp;by setting&nbsp;-Interval to anything you want (-Interval value is in seconds)</P>
<P>-Size parameter is the targeted size of the file; thanks to Powershell you can use values like 10KB, 1MB, 3GB</P>
<P>&nbsp;Test-FileSizeUntil returns the job object when it is used with "-AsJob $true"&nbsp;parameter; please note that you have to copy Test-FileSizeUntil.ps1 file under "C:\ps\library" otherwise script does not function with "AsJob" parameter. Please check <A title="How Do I Use the Functions Provided in This Blog" href="https://blogs.msdn.com/candede/archive/2010/01/13/how-do-i-use-the-functions-provided-in-this-blog.aspx" mce_href="https://blogs.msdn.com/candede/archive/2010/01/13/how-do-i-use-the-functions-provided-in-this-blog.aspx">How Do I Use the Functions Provided in This Blog</A> post for more information</P>
<P>Below you may see the usage of the function; I decided not to copy-paste script anymore inside of the blog; instead check the attachment</P>
<P><IMG style="WIDTH: 998px; HEIGHT: 177px" title=Test-FileSizeUntil alt=Test-FileSizeUntil src="https://hwnn7a.bay.livefilestore.com/y1pX-PL5UjxBmro4ZkHEt2FBVEzOtAO510BNGTsGMFS2EIbvMFHjDuPziUbizci35drJ75w0ZSo08qS3-mPz61TvI_yn8J5ev0H/Test-FileSizeUntil.PNG" width=998 height=177 mce_src="https://hwnn7a.bay.livefilestore.com/y1pX-PL5UjxBmro4ZkHEt2FBVEzOtAO510BNGTsGMFS2EIbvMFHjDuPziUbizci35drJ75w0ZSo08qS3-mPz61TvI_yn8J5ev0H/Test-FileSizeUntil.PNG"></P>
<P mce_keep="true">Cheers, CanD</P>
<P mce_keep="true">&nbsp;</P>
<p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Components.PostAttachments/00/09/94/83/35/Test-FileSizeUntil.ps1" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-components-postattachments/00-09-94-83-35/Test_2D00_FileSizeUntil.ps1">Test-FileSizeUntil.ps1</a></p>]]></content:encoded>
    </item>
    <item>
      <title>How Do I Use the Functions Provided in This Blog</title>
      <link>https://docs.microsoft.com/archive/blogs/candede/how-do-i-use-the-functions-provided-in-this-blog</link>
      <pubDate>Wed, 13 Jan 2010 06:12:00 GMT</pubDate>
      <dc:creator><![CDATA[candede]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/candede/2010/01/13/how-do-i-use-the-functions-provided-in-this-blog/</guid>
      <description><![CDATA[In my last blog post; I mentioned that I would give you more information on how&nbsp;you could...]]></description>
      <content:encoded><![CDATA[<P>In my last blog post; I mentioned that I would give you more information on how&nbsp;you could import these functions. I didnt create a module for it so you cannot use Import-Module yet for it; what I'm doing right now is I'm creating Verb-Noun.ps1 file and copy-paste my function in it with the same name (function Verb-Noun{} ) and I put these files under c:\ps\library folder</P>
<P>&nbsp;<IMG style="WIDTH: 660px; HEIGHT: 251px" title=PSLibrary alt=PSLibrary align=left src="https://hwnn7a.bay.livefilestore.com/y1pwYOL7hUkwVD55MdSlTMw06ddjfKmxy9wyTdyC4naouKInn65qq5ItvIEV_RDMzMWrbuEMTFLbH7HXd062VufdZ0Ffyd_sfkI/ps_library.PNG" width=660 height=251 mce_src="https://hwnn7a.bay.livefilestore.com/y1pwYOL7hUkwVD55MdSlTMw06ddjfKmxy9wyTdyC4naouKInn65qq5ItvIEV_RDMzMWrbuEMTFLbH7HXd062VufdZ0Ffyd_sfkI/ps_library.PNG"></P>
<P mce_keep="true">&nbsp;</P>
<P mce_keep="true">&nbsp;</P>
<P mce_keep="true">&nbsp;</P>
<P mce_keep="true">&nbsp;</P>
<P mce_keep="true">&nbsp;</P>
<P mce_keep="true">&nbsp;</P>
<P mce_keep="true">&nbsp;</P>
<P mce_keep="true">&nbsp;</P>
<P mce_keep="true">In order to be able to run these functions every time you open a new Powershell window you need to edit your Powershell profile. Powershell console and GUI versions has both their own profile files so you need to edit them both; simply type "notepad $profile" in Powershell and start editing your profile</P>
<P mce_keep="true">I added the following line so that all files under C:\ps\library will be dotted during profile execution before you see actual prompt</P>gci c:\ps\library | %{. $_.pspath} 
<P mce_keep="true"><IMG style="WIDTH: 303px; HEIGHT: 85px" title=profile_ps_library alt=profile_ps_library align=left src="https://hwnn7a.bay.livefilestore.com/y1pM7DghP0cEuJAt5L2Rutij1ooOe6TwXRAVD9AZc-PsyDbMA6EazuQJumu9Z321i9jMbZoVMyeGcvkajEhtlim4eATifogB9WG/profile_ps_library.PNG" width=303 height=85 mce_src="https://hwnn7a.bay.livefilestore.com/y1pM7DghP0cEuJAt5L2Rutij1ooOe6TwXRAVD9AZc-PsyDbMA6EazuQJumu9Z321i9jMbZoVMyeGcvkajEhtlim4eATifogB9WG/profile_ps_library.PNG"></P>
<P mce_keep="true">&nbsp;</P>
<P mce_keep="true">&nbsp;</P>
<P mce_keep="true">&nbsp;</P>
<P mce_keep="true">Probably&nbsp;in the&nbsp;end I'll find myself creating a module for this:)&nbsp;</P>
<P mce_keep="true">Cheers, CanD</P>]]></content:encoded>
    </item>
    <item>
      <title>Hunting Event Logs</title>
      <link>https://docs.microsoft.com/archive/blogs/candede/hunting-event-logs</link>
      <pubDate>Wed, 13 Jan 2010 03:33:00 GMT</pubDate>
      <dc:creator><![CDATA[candede]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/candede/2010/01/13/hunting-event-logs/</guid>
      <description><![CDATA[Hunt-EventLog function monitors a specific Event log like Application, System or any other and...]]></description>
      <content:encoded><![CDATA[<P>Hunt-EventLog function monitors a specific Event log like Application, System or any other and triggers an action when a specific Event occurs. By default it looks for changes in the Event log every 30 seconds and searches the EventID; you can change this interval with -Interval paramaters. Hunt-EventLog&nbsp;echoes information in every interval which can be silenced with -Silent $true</P>
<P>Hunt-EventLog also can be called as a background job with -AsJob $true parameter. When you call Hunt-EventLog with -AsJob $true parameter it returns the Job object that is created for it; so you can assign it to a variable to return the output later. AsJob parameter works only if you copy the Hunt-EventLog.ps1 file under C:\ps\library\Hunt-EventLog.ps1. I will post another blog about how I'm using these scripts in my own environment</P>
<P><IMG style="WIDTH: 995px; HEIGHT: 427px" title=Hunt-EventLog alt=Hunt-EventLog src="https://hwnn7a.bay.livefilestore.com/y1pkgTUyr0LjQMy6SgW8KqMm0hkp4TMaFP5d4IExXR2ZgsyXVnASQJxRyVascSaaRQPFPE66uxU5OMynLw-Nd12tNJ1Mt8ti0CP/Hunt-EventLog.PNG" width=995 height=427 mce_src="https://hwnn7a.bay.livefilestore.com/y1pkgTUyr0LjQMy6SgW8KqMm0hkp4TMaFP5d4IExXR2ZgsyXVnASQJxRyVascSaaRQPFPE66uxU5OMynLw-Nd12tNJ1Mt8ti0CP/Hunt-EventLog.PNG"></P>
<P>Here is the function code; as usual check the attachment to get it in ps1 format&nbsp;</P>
<P>function Hunt-EventLog<BR>{</P>
<P>&lt;#</P>
<P>.Synopsis<BR>&nbsp;Searches for a specific EventID in Event Viewer and gives a specific response<BR>.Description<BR>&nbsp;This cmdlet loops until it finds the EventID that user enters and gives the response user wants<BR>.Parameter EventID<BR>&nbsp;Specifies EventID that is being search for<BR>.Parameter LogName<BR>&nbsp;Specifies the name of the event log. EventID will be searched in this log<BR>.Parameter ScriptString<BR>&nbsp;&nbsp;&nbsp; Specifies the action commands to run. Enclose the commands in double quotes ( " " ) to create a script string<BR>.Parameter Interval<BR>&nbsp;Specifies the wait interval between the executions of the function. The value of this parameter is second and default value is 30 seconds<BR>.Parameter Silent<BR>&nbsp;Specifies whether output to the screen is allowed or not<BR>.Parameter AsJob<BR>&nbsp;Creates a background job for the cmdlet and echoes the jobID<BR>.Example<BR>Hunt-EventLog -LogName Application -EventID 8225 -ScriptString "do something"<BR>.Example<BR>Hunt-EventLog -LogName Application -EventID 8225 -Interval 60<BR>.Link<BR>&nbsp;<A href="https://blogs.msdn.com/candede" mce_href="https://blogs.msdn.com/candede">https://blogs.msdn.com/candede</A><BR>.Notes<BR>&nbsp;Author: Can Dedeoglu<BR>#&gt;</P>
<P>param<BR>(<BR>[Parameter(mandatory=$true,position=0)]<BR>[string]$LogName<BR>,<BR>[Parameter(mandatory=$true,position=1)]<BR>[string]$EventID<BR>,<BR>[Parameter(mandatory=$true)]<BR>[string]$ScriptString<BR>,<BR>[Parameter(mandatory=$false)]<BR>[int]$Interval = 30<BR>,<BR>[Parameter(mandatory=$false)]<BR>[bool]$Silent = $false<BR>,<BR>[Parameter(mandatory=$false)]<BR>[bool]$AsJob = $false<BR>)</P>
<P><BR>$startupLog = Get-EventLog $LogName -Newest 1<BR>$startupTime = $startupLog.TimeGenerated<BR>$startupIndex = $startupLog.Index</P>
<P>[bool]$logsCaptured = $false</P>
<P>function startControl([datetime]$time)<BR>{</P>
<P>function writeConsole([int]$output)<BR>{<BR>if(!$Silent)<BR>{<BR>&nbsp;switch($output)<BR>&nbsp;{<BR>&nbsp;1<BR>&nbsp;&nbsp;{<BR>&nbsp;&nbsp;$(Get-Date).tostring("HHmmss") + ": Logs between Index " + ($newLogs[-1]).Index&nbsp; + "-" + ($newLogs[0]).Index + " has been scanned; there is no match"<BR>&nbsp;&nbsp;}<BR>&nbsp;2<BR>&nbsp;&nbsp;{<BR>&nbsp;&nbsp;(Get-Date).tostring("HHmmss") + ": sleeping " + $Interval + " seconds"<BR>&nbsp;&nbsp;}<BR>&nbsp;3<BR>&nbsp;&nbsp;{<BR>&nbsp;&nbsp;(Get-Date).tostring("HHmmss") + ": no new logs, last log Index was " + $currentIndex<BR>&nbsp;&nbsp;}<BR>&nbsp;}<BR>}<BR>}</P>
<P><BR>$newLogs = @(Get-EventLog $LogName -After $time)</P>
<P>if(!$logsCaptured)<BR>&nbsp;&nbsp;&nbsp; {<BR>&nbsp;&nbsp;&nbsp; $currentIndex = $startupIndex<BR>&nbsp;&nbsp;&nbsp; $currentTime = $startupTime<BR>&nbsp;&nbsp;&nbsp; }</P>
<P>if($newLogs.count -gt 0)<BR>&nbsp;&nbsp;&nbsp; {<BR>&nbsp;&nbsp;&nbsp; $newTime = ($newLogs[-1]).TimeGenerated<BR>&nbsp;&nbsp;&nbsp; $results = @($newLogs | ?{$_.InstanceId -eq $EventID})<BR>&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; if($results.count -gt 0)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Invoke-Command -ScriptBlock ([scriptblock]::Create($ScriptString))<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<BR>&nbsp;&nbsp;&nbsp; else<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; writeConsole(1)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; writeConsole(2)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $currentIndex = ($newLogs[0]).Index<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $currentTime = ($newLogs[0]).TimeGenerated<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $logsCaptured = $true<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Start-Sleep -Seconds $Interval<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; startControl $newTime<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</P>
<P>&nbsp;&nbsp;&nbsp; }<BR>else<BR>&nbsp;&nbsp;&nbsp; {<BR>&nbsp;&nbsp;&nbsp; writeConsole(3)<BR>&nbsp;&nbsp;&nbsp; writeConsole(2)<BR>&nbsp;&nbsp;&nbsp; Start-Sleep -Seconds $Interval<BR>&nbsp;&nbsp;&nbsp; startControl $currentTime<BR>&nbsp;&nbsp;&nbsp; }<BR>}</P>
<P>if(!$AsJob)<BR>&nbsp;{<BR>&nbsp;startControl $startupTime<BR>&nbsp;}</P>
<P><BR>else<BR>&nbsp;{<BR>&nbsp;Start-Job -ScriptBlock ([scriptblock]::Create(". c:\ps\library\Hunt-EventLog.ps1; Hunt-EventLog -LogName $LogName -EventID $EventID -ScriptString `"$ScriptString`" -Interval $Interval -Silent `$$Silent"))<BR>&nbsp;}</P>
<P>}</P>
<P mce_keep="true">&nbsp;</P>
<P>Cheers, CanD</P>
<p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Components.PostAttachments/00/09/94/77/07/Hunt-EventLog.ps1" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-components-postattachments/00-09-94-77-07/Hunt_2D00_EventLog.ps1">Hunt-EventLog.ps1</a></p>]]></content:encoded>
    </item>
    <item>
      <title>Test Registry Paths</title>
      <link>https://docs.microsoft.com/archive/blogs/candede/test-registry-paths</link>
      <pubDate>Wed, 13 Jan 2010 03:13:00 GMT</pubDate>
      <dc:creator><![CDATA[candede]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/candede/2010/01/13/test-registry-paths/</guid>
      <description><![CDATA[Test-Path is a great cmdlet to verify the existence of files and folders but unfortunately&nbsp;it...]]></description>
      <content:encoded><![CDATA[<P>Test-Path is a great cmdlet to verify the existence of files and folders but unfortunately&nbsp;it doesnt verify the existence of Registry&nbsp;keys which&nbsp;Test-PathReg does.&nbsp;Test-PathReg works&nbsp;pretty much same as Test-Path; return true/false as a result.</P>
<P>If you want to check if Hostname property exists&nbsp;under HKLM:\SYSTEM\CurrentControlSet\services\Tcpip\Parameters; run the function like this:</P>
<P>Test-PathReg HKLM:\SYSTEM\CurrentControlSet\services\Tcpip\Parameters Hostname<BR></P>
<P>Here is the function code; as usual check the attachment to get it in ps1 format</P>
<P>function Test-PathReg<BR>{</P>
<P>&lt;#</P>
<P>.Synopsis<BR>&nbsp;Validates the existence of a registry key<BR>.Description<BR>&nbsp;This function searches for the registry value (Property attribute) under the given registry key (Path attribute) and returns $true if it exists<BR>.Parameter Path<BR>&nbsp;Specifies the Registry path<BR>.Parameter Property<BR>&nbsp;Specifies the name of the registry property that will be searched for under the given Registry path<BR>.Example<BR>Test-PathReg -Path HKLM:\SYSTEM\CurrentControlSet\services\Tcpip\Parameters -Property Hostname<BR>.Link<BR>&nbsp;<A href="https://blogs.msdn.com/candede" mce_href="https://blogs.msdn.com/candede">https://blogs.msdn.com/candede</A><BR>.Notes<BR>&nbsp;Author: Can Dedeoglu<BR>#&gt;</P>
<P>param<BR>(<BR>[Parameter(mandatory=$true,position=0)]<BR>[string]$Path<BR>,<BR>[Parameter(mandatory=$true,position=1)]<BR>[string]$Property<BR>)</P>
<P><BR>$compare = (Get-ItemProperty -LiteralPath $Path).psbase.members | %{$_.name} | compare $Property -IncludeEqual -ExcludeDifferent<BR>if($compare.SideIndicator -like "==") <BR>&nbsp;&nbsp;&nbsp; {<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return $true<BR>&nbsp;&nbsp;&nbsp; }<BR>else<BR>&nbsp;&nbsp;&nbsp; {<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return $false<BR>&nbsp;&nbsp;&nbsp; }<BR>}<BR></P>
<P>Cheers, CanD</P>
<p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Components.PostAttachments/00/09/94/77/01/Test-PathReg.ps1" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-components-postattachments/00-09-94-77-01/Test_2D00_PathReg.ps1">Test-PathReg.ps1</a></p>]]></content:encoded>
    </item>
    <item>
      <title>Getting Uptime of Multiple Servers</title>
      <link>https://docs.microsoft.com/archive/blogs/candede/getting-uptime-of-multiple-servers</link>
      <pubDate>Tue, 12 Jan 2010 09:21:00 GMT</pubDate>
      <dc:creator><![CDATA[candede]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/candede/2010/01/12/getting-uptime-of-multiple-servers/</guid>
      <description><![CDATA[During a Premier case we needed to get uptime information of several servers in customers...]]></description>
      <content:encoded><![CDATA[<P mce_keep="true">During a Premier case we needed to get uptime information of several servers in customers environment. To save time we used the function below; function gets server names as arguments and simply converts DMTF datetime format (Date and time representation in WMI) to DateTime, please check reference for more info</P>
<P mce_keep="true">You may find the script in action below; and find the attachment in txt format...hope it helps!!</P>
<P>PS C:\Windows\system32&gt; function Get-UpTime<BR>&gt;&gt; {<BR>&gt;&gt; foreach($comp in $args)<BR>&gt;&gt; {<BR>&gt;&gt; $upTime = [Management.ManagementDateTimeConverter]::ToDateTime((gwmi win32_operatingsystem -computer $comp).lastbootuptime)<BR>&gt;&gt; write-host $comp "-&gt; server is up since" $upTime "which means" ([datetime]::now - $upTime).Days "days"<BR>&gt;&gt; }<BR>&gt;&gt; }<BR>&gt;&gt;<BR>PS C:\Windows\system32&gt; Get-UpTime cdvm cdvm2<BR>cdvm -&gt; server is up since 12/23/2009 4:24:34 PM which means 20 days<BR>cdvm2 -&gt; server is up since 12/25/2009 2:42:32 PM which means 18 days<BR>PS C:\Windows\system32&gt;</P>
<P mce_keep="true">&nbsp;</P>
<P>Reference: <A href="https://msdn.microsoft.com/en-us/library/system.management.managementdatetimeconverter.todatetime.aspx" mce_href="https://msdn.microsoft.com/en-us/library/system.management.managementdatetimeconverter.todatetime.aspx">https://msdn.microsoft.com/en-us/library/system.management.managementdatetimeconverter.todatetime.aspx</A></P>
<P>Cheers, CanD</P>
<p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Components.PostAttachments/00/09/94/72/11/Get-UpTime.txt" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-components-postattachments/00-09-94-72-11/Get_2D00_UpTime.txt">Get-UpTime.txt</a></p>]]></content:encoded>
    </item>
  </channel>
</rss>