<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>&#62;_</title>
	<atom:link href="http://p0w3rsh3ll.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://p0w3rsh3ll.wordpress.com</link>
	<description>de parvis grandis acervus erit</description>
	<lastBuildDate>Sun, 19 Feb 2012 16:39:13 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='p0w3rsh3ll.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>&#62;_</title>
		<link>http://p0w3rsh3ll.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://p0w3rsh3ll.wordpress.com/osd.xml" title="&#62;_" />
	<atom:link rel='hub' href='http://p0w3rsh3ll.wordpress.com/?pushpress=hub'/>
		<item>
		<title>Get-FirefoxInfo</title>
		<link>http://p0w3rsh3ll.wordpress.com/2012/02/19/get-firefoxinfo/</link>
		<comments>http://p0w3rsh3ll.wordpress.com/2012/02/19/get-firefoxinfo/#comments</comments>
		<pubDate>Sun, 19 Feb 2012 16:33:45 +0000</pubDate>
		<dc:creator>_Emin_</dc:creator>
				<category><![CDATA[powershell]]></category>

		<guid isPermaLink="false">http://p0w3rsh3ll.wordpress.com/?p=221</guid>
		<description><![CDATA[In less than 2 weeks, the Mozilla foundation released two security updates for both the ESR (Extended Support Release) and the &#8216;Release&#8217; channel version of Firefox. With all previous releases of Firefox, we used to check the version of firefox.exe &#8230; <a href="http://p0w3rsh3ll.wordpress.com/2012/02/19/get-firefoxinfo/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=p0w3rsh3ll.wordpress.com&amp;blog=31062221&amp;post=221&amp;subd=p0w3rsh3ll&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>In less than 2 weeks, the Mozilla foundation released two security updates for both the <a href="https://www.mozilla.org/en-US/firefox/organizations/" title="https://www.mozilla.org/en-US/firefox/organizations/" target="_blank">ESR</a> (<a href="https://wiki.mozilla.org/Enterprise/Firefox/ExtendedSupport:Proposal" title="https://wiki.mozilla.org/Enterprise/Firefox/ExtendedSupport:Proposal" target="_blank">Extended Support Release</a>) and the &#8216;Release&#8217; channel version of Firefox.</p>
<p>With all previous releases of Firefox, we used to check the version of firefox.exe to find out which version it was.</p>
<p>With Firefox 10.0 executable, we had a version 10.0.0.4412 for the ESR and 10.0.0.4411 for the release update channel but for firefox 10.0.1, we have both 10.0.1.4421 which doesn&#8217;t allow us to differentiate between the ESR and the release channel version anymore.</p>
<p>I&#8217;ve asked the <a href="https://mail.mozilla.org/listinfo/enterprise" title="https://mail.mozilla.org/listinfo/enterprise" target="_blank">Enterprise Working group</a> and got the following answer from the Ben Hearsum</p>
<blockquote><p>The only way to distinguish between the two versions these days is through the application.ini file. The SourceRepository field in the [App] section will be &#8220;http://hg.mozilla.org/releases/mozilla-esr10&#8243; for this line of ESR builds. (When we start the next line of ESR at Firefox 17 this will change, of course.)</p>
<p>The version you&#8217;re looking at isn&#8217;t used by us at all. The only thing we do is guarantee that it doesn&#8217;t go backwards.
</p></blockquote>
<p>Powershell, to the rescue&#8230; <img src='http://s1.wp.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /><br />
<pre class="brush: powershell; light: true;">
#Requires -Version 3.0

&lt;#
.SYNOPSIS    
    Get the channel and version of Mozilla Firefox
 
.DESCRIPTION  
    Get the channel and version of Mozilla Firefox
 
.PARAMETER ComputerName
    Non mandatory parameter, array of remote computernames
 
.PARAMETER Credential
    Non mandatory parameter, credential used to contact remote computer

.NOTES    
    Name: Get-FirefoxInfo
    Author: Emin Atac
    DateCreated: 19/02/2012
 
.LINK    
    http://p0w3rsh3ll.wordpress.com
 
.EXAMPLE    
    .\Get-FirefoxInfo.ps1

    Channel         Version
    -------         -------
    release         10.0
    
    Returns the channel and version of Mozilla Firefox found locally
.EXAMPLE    
    .\Get-FirefoxInfo.ps1 -ComputerName &quot;PAR903&quot;,&quot;127.0.0.1&quot;
    Returns the channel and version of Mozilla Firefox of the two remote computers

.EXAMPLE    
    .\Get-FirefoxInfo.ps1 -ComputerName &quot;remoteComputer1&quot;,&quot;remoteComputer2&quot; -Credential (Get-Credential) 
    Use the credentials you specified to retrieve the channel and version of Mozilla Firefox of the two remote computers
#&gt;

[cmdletbinding(DefaultParameterSetName='',SupportsTransactions=$false)]
param(
    [Parameter(Mandatory=$false,ParameterSetName='',ValueFromPipeline=$true,Position=0)]
    [system.array]$ComputerName=$null,

    [parameter(Mandatory=$false,ParameterSetName='',ValueFromPipeline=$true,Position=1)]
    [System.Management.Automation.PSCredential]$Credential = $null
)

# Build a hashtable for splatting
$otherparams = @{}
if ($credential)
{
    $otherparams += @{Credential = $Credential}
}
# Note to myself: both test-path and get-content support PScredential inputs

if ($ComputerName -ne $null)
{
    foreach ($computer in $ComputerName)
    {
        # Variable reset
        $osprop = $programfiles = $appinipath = $content = $sourcerep = $URL = $channel = $sourcever = $version = $MFOjb = $null
        # We need to get the target OS architecture and systemdrive
        try
        {
            $osprop = @(Get-WmiObject -Query &quot;Select * FROM Win32_operatingsystem&quot; -ComputerName $computer -ErrorAction Stop @otherparams)
        } 
        catch
        {
            # WMI was unable to retrieve the information
            switch ($_)
            {
                {$_.Exception.ErrorCode -eq 0x800706ba} { $reason =  &quot;Unavailable (offline, firewall)&quot; }
                {$_.CategoryInfo.Reason -eq 'UnauthorizedAccessException' } { $reason = &quot;Access denied&quot; }
                default { $reason  = $_.Exception.Message }
            }
            Write-Host -ForegroundColor Yellow  -Object &quot;Failed to connect to WMI on $Computer because: $reason&quot;
            # break
        } # end of catch
        
        if (($osprop.Count -ne 0) -and ($osprop -ne $null))
        {
            # Based on the OS architecture, we set the target program files directory
            if ($osprop[0].OSArchitecture -eq &quot;64-bit&quot;)
            {
                $programfiles = &quot;Program Files (x86)&quot;
            } else {
                $programfiles = &quot;Program Files&quot;
            }
            # Now we are ready to build the full target path
            $appinipath = &quot;\\&quot; + $computer + &quot;\&quot; + ($osprop[0].SystemDrive -Replace &quot;:&quot;,&quot;$&quot;) + &quot;\&quot; +  $programfiles + &quot;\Mozilla Firefox\application.ini&quot;
            # $appinipath
            if (Test-Path -Path $appinipath @otherparams)
            {
                try
                {
                    $content = Get-Content -Path $appinipath @otherparams
                } catch {
                    $reason  = $_.Exception.Message
                    Write-Host -ForegroundColor Yellow  -Object &quot;Failed to use get-content against $computer because: $reason&quot;
                }
                if ($content -ne $null)
                {
                    # Look for the SourceRepository into the application.ini file
                    $sourcerep = @($content | Select-String -Pattern &quot;^SourceRepository=http&quot;)
    
                    if ($sourcerep.Count -ne 0)
                    {
                        # Cast the URL into a System.URI object and split its segments properties
                        $URL = ([System.URI](($sourcerep[0] -split &quot;=&quot;)[1].ToString())).Segments[2]
                        if ($URL -eq &quot;mozilla-release&quot;)
                        {
                            $channel = &quot;release&quot;
                        } elseif ($URL -match &quot;mozilla-esr&quot;) {
                            $channel = &quot;esr&quot;
                        } else {
                            Write-Host -ForegroundColor Red -Object (&quot;SourceRepository not recognised in $appinipath&quot;)
                            $channel = &quot;Unknown&quot;
                        }
                    } else {
                        Write-Host -ForegroundColor Red -Object (&quot;SourceRepository not found in $appinipath&quot;)
                    }
    
                    # Look for the Version into the application.ini file
                    $sourcever = @($content | Select-String -Pattern &quot;^Version=\d{2}\.\d{1}&quot;)
                    if ($sourcever.Count -ne 0)
                    {
                        $version = [system.version]($sourcever[0] -split &quot;=&quot;)[1].ToString()
                    } else {
                        Write-Host -ForegroundColor Red -Object (&quot;Version not found in $appinipath&quot;)
                        $version = &quot;Unknown&quot;
                    }
                    # Build a custom object
                    $MFobj = New-Object -TypeName PSObject -Property @{
                        Channel = $Channel
                        Version = $Version
                    }
                    # Return it
                    Write-Output -InputObject $MFobj
                } #end of if $content -ne $null
            } else {
                Write-Host -ForegroundColor Red -Object (&quot;Cannot find a recent installed version of Firefox in $appinipath&quot;)
            } # end of test-path
        } # end of osprop is null
    } # end of foreach computer
} else {
    # No paramter has been passed, so we can use the new .Net 4 static property of system.environnemet for performance reasons compared to WMI
    if ([system.environment]::Is64BitOperatingSystem)
    {
        $programfiles = ${env:ProgramFiles(x86)}
    } else {
        $programfiles = $env:ProgramFiles
    }

    if (Test-Path -Path &quot;$programfiles\Mozilla Firefox\application.ini&quot;)
    {
        $content = Get-Content -Path &quot;$programfiles\Mozilla Firefox\application.ini&quot;
    
        # Look for the SourceRepository into the application.ini file
        $sourcerep = @($content | Select-String -Pattern &quot;^SourceRepository=http&quot;)
    
        if ($sourcerep.Count -ne 0)
        {
            # Cast the URL into a System.URI object and split its segments properties
            $URL = ([System.URI](($sourcerep[0] -split &quot;=&quot;)[1].ToString())).Segments[2]
            if ($URL -eq &quot;mozilla-release&quot;)
            {
                $channel = &quot;release&quot;
            } elseif ($URL -match &quot;mozilla-esr&quot;) {
                $channel = &quot;esr&quot;
            } else {
                Write-Host -ForegroundColor Red -Object (&quot;SourceRepository not recognised in your $programfiles\Mozilla Firefox\application.ini&quot;)
                $channel = &quot;Unknown&quot;
            }
        } else {
            Write-Host -ForegroundColor Red -Object (&quot;SourceRepository not found in your $programfiles\Mozilla Firefox\application.ini&quot;)
        }
    
        # Look for the Version into the application.ini file
        $sourcever = @($content | Select-String -Pattern &quot;^Version=\d{2}\.\d{1}&quot;)
        if ($sourcever.Count -ne 0)
        {
            $version = [system.version]($sourcever[0] -split &quot;=&quot;)[1].ToString()
        } else {
            Write-Host -ForegroundColor Red -Object (&quot;Version not found in your $programfiles\Mozilla Firefox\application.ini&quot;)
            $version = &quot;Unknown&quot;
        }
        # Build a custom object
        $MFobj = New-Object -TypeName PSObject -Property @{
            Channel = $Channel
            Version = $Version
        }
        # Return it
        Write-Output -InputObject $MFobj
    } else {
        Write-Host -ForegroundColor Red -Object (&quot;Cannot find a recent installed version of Firefox in $programfiles&quot;)
    }
}
</pre></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/p0w3rsh3ll.wordpress.com/221/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/p0w3rsh3ll.wordpress.com/221/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/p0w3rsh3ll.wordpress.com/221/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/p0w3rsh3ll.wordpress.com/221/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/p0w3rsh3ll.wordpress.com/221/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/p0w3rsh3ll.wordpress.com/221/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/p0w3rsh3ll.wordpress.com/221/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/p0w3rsh3ll.wordpress.com/221/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/p0w3rsh3ll.wordpress.com/221/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/p0w3rsh3ll.wordpress.com/221/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/p0w3rsh3ll.wordpress.com/221/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/p0w3rsh3ll.wordpress.com/221/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/p0w3rsh3ll.wordpress.com/221/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/p0w3rsh3ll.wordpress.com/221/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=p0w3rsh3ll.wordpress.com&amp;blog=31062221&amp;post=221&amp;subd=p0w3rsh3ll&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://p0w3rsh3ll.wordpress.com/2012/02/19/get-firefoxinfo/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/f416a6060a6e1cf59bd8b5618a4b1680?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">pwrshll</media:title>
		</media:content>
	</item>
		<item>
		<title>Get TimeZone</title>
		<link>http://p0w3rsh3ll.wordpress.com/2012/02/11/get-timezone/</link>
		<comments>http://p0w3rsh3ll.wordpress.com/2012/02/11/get-timezone/#comments</comments>
		<pubDate>Sat, 11 Feb 2012 17:26:32 +0000</pubDate>
		<dc:creator>_Emin_</dc:creator>
				<category><![CDATA[powershell]]></category>

		<guid isPermaLink="false">http://p0w3rsh3ll.wordpress.com/?p=187</guid>
		<description><![CDATA[I&#8217;ve a daily security audit script that checks the timezone of our computers. This script actually queries the HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\TimeZoneInformation registry key of computers and checks their StandardName value. Since Windows Vista and Windows 7, this value doesn&#8217;t contain a string &#8230; <a href="http://p0w3rsh3ll.wordpress.com/2012/02/11/get-timezone/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=p0w3rsh3ll.wordpress.com&amp;blog=31062221&amp;post=187&amp;subd=p0w3rsh3ll&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve a daily security audit script that checks the timezone of our computers. This script actually queries the HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\TimeZoneInformation registry key of computers and checks their StandardName value. Since Windows Vista and Windows 7, this value doesn&#8217;t contain a string as it usually did on Windows XP. As you can see it now contains a resource.<br />
<img src="http://p0w3rsh3ll.files.wordpress.com/2012/02/regquerytz.png?w=584" alt="regqueryTZ" /></p>
<p>To help me translate those resource back into strings, I could have used Tobias Weltner&#8217;s brillant Get-ResourceString function available on this <a href="http://powershell.com/cs/media/p/11070.aspx" title="http://powershell.com/cs/media/p/11070.aspx" target="_blank">page</a> but I wanted to dig further and learn more about timezones.<br />
<img src="http://p0w3rsh3ll.files.wordpress.com/2012/02/tw-getresourcestring.png?w=584" alt="Get-ResourceString" /></p>
<p>I know that there isn&#8217;t any simple way to set a timezone on a computer. Either you have a running computer and you should use the tzutil command or you have an offline image and you can use the dism command.<br />
<img src="http://p0w3rsh3ll.files.wordpress.com/2012/02/dism_tzutil.png?w=584" alt="dism-tzutil" /><br />
My goal wasn&#8217;t to set a timezone, but if you&#8217;re interested in performing this task, let me also mention that there&#8217;s a script available on the Technet script gallery that is a wrapper of the tzutil command called <a href="http://gallery.technet.microsoft.com/scriptcenter/Set-TimeZone-function-b5ed93b5" title="http://gallery.technet.microsoft.com/scriptcenter/Set-TimeZone-function-b5ed93b5" target="_blank">Set-TimeZone.ps1</a>. Even more interesting, the DeploymentGuys posted a way to set a timezone in powershell on <a href="http://blogs.technet.com/b/deploymentguys/archive/2009/06/07/setting-the-time-zone-using-windows-powershell.aspx" title="http://blogs.technet.com/b/deploymentguys/archive/2009/06/07/setting-the-time-zone-using-windows-powershell.aspx" target="_blank">their blog</a>.</p>
<p>To learn what&#8217;s behind the scene, I fired up a procmon and checked what the tzutil.exe /l command does. As you can see, it reads the &#8220;HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Time Zones&#8221; and its subkeys. I decided that in addition to the translation of resources, the second feature of my powershell script would read this key and dump the same output as the tzutil.exe /l command. Exploring the registry subkeys also helped me brought all the pieces together, as well as link these two goals and gave me an alternative to Tobias Weltener&#8217;s Get-ResourceString function.<br />
<img src="http://p0w3rsh3ll.files.wordpress.com/2012/02/tzutil_procmon.png?w=584" alt="procmon_tzutil" /></p>
<p>Along the learning path, I&#8217;ve discovered two useful links:</p>
<li>
Marc van Orsouw, aka MOW The powershell guy, who shows how to use some methods associated with the .NET Framework 3.5 TimeZoneinfo class: more here <a href="http://thepowershellguy.com/blogs/posh/archive/2007/12/19/powershell-get-worldtime-function.aspx" title="http://thepowershellguy.com/blogs/posh/archive/2007/12/19/powershell-get-worldtime-function.aspx" target="_blank">on his blog</a>
</li>
<li>Thomas Lee who also shows <a href="http://pshscripts.blogspot.com/2010/08/convert-dateps1.html" title="http://pshscripts.blogspot.com/2010/08/convert-dateps1.html" target="_blank">on his blog</a> how to use other methods associated with the .NET Framework 3.5 TimeZoneinfo class
</li>
<ul></ul>
<p>&#8230;and I&#8217;ve also learned 3 things:</p>
<li>
The &#8216;New-Object System.DateTime 2006, 3, 21, 2, 0, 0&#8242; that Thomas Lee uses, has an &#8216;unspecified&#8217; kind whereas you&#8217;ll get a &#8216;Kind&#8217; property set to &#8216;Local&#8217; if you use the Get-Date cmdlet to create a datetime object. This has some importance to use the ConvertTimeToUtc method of the .net TimeZoneInfo object.<br />
<img src="http://p0w3rsh3ll.files.wordpress.com/2012/02/datetimekind.png?w=584" alt="datetimeKind" />
</li>
<li>
There&#8217;s a &#8220;<a href="http://msdn.microsoft.com/en-us/library/az4se3k1.aspx#GeneralDateShortTime" title="http://msdn.microsoft.com/en-us/library/az4se3k1.aspx#GeneralDateShortTime" target="_blank">General Date Short Time (&#8220;g&#8221;) Format Specifier</a>&#8221; that can be used to format datetimes object.<br />
<pre class="brush: powershell; light: true;">
# Method 1
(Get-Date).ToString('dd/MM/yyyy HH:mm')
# Method 2
Get-Date -Format g
# Method 3
$date = Get-Date
&quot;{0:dd}/{1:MM}/{2:yyyy} {3:HH}:{4:mm}&quot; -f $date, $date, $date, $date, $date
# so 'g' is actually this:
$host.CurrentCulture.DateTimeFormat.ShortDatePattern + &quot; &quot; + $host.CurrentCulture.DateTimeFormat.ShortTimePattern
</pre><br />
<img src="http://p0w3rsh3ll.files.wordpress.com/2012/02/formatdatetime.png?w=584" alt="formatdatetime" />
</li>
<li>
How to use the <a href="http://blogs.msdn.com/b/powershell/archive/2008/12/23/powershell-v2-parametersets.aspx" title="http://blogs.msdn.com/b/powershell/archive/2008/12/23/powershell-v2-parametersets.aspx" target="_blank">ParameterSets</a> in a script
</li>
<ul></ul>
<p>Finally here&#8217;s my Get-TZ.ps1 script, enjoy <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /><br />
<pre class="brush: powershell; light: true;">
#Requires -Version 2.0

&lt;#
 
.SYNOPSIS    
    Get either all timezones, the local timezone or timezone properties on remote computers
 
.DESCRIPTION  
    Get either all timezones, the local timezone or timezone properties on remote computers

.PARAMETER Local
    Shows the local timezone
 
.PARAMETER All
    Show all timezones the same way the tzutil /l command does

.PARAMETER Full
    Must be specified with the All parameter in order to show all timezones with 4 columns: CurrentTime,DisplayName,Id,TimeSpan

    CurrentTime: time at specified location formatted in dd/MM/yyyy HH:mm 
    DisplayName: (UTC +/- HH:mm) Location
    Id: the &lt;time zone ID&gt;, i.e., it's name
    TimeSpan: a timespan object of the timezone

.PARAMETER FindResource
    Specifies the array of strings to look for

.PARAMETER ComputerName
    Specifies the array of computername to use to read their timezone using WMI

.PARAMETER Credential
    Specifies the credential to use to query remote computers

.EXAMPLE    
    Get-TZ.ps1 -Local

    Id          : Romance Standard Time
    CurrentTime : 11/02/2012 16:27
    DisplayName : (UTC+01:00) Brussels, Copenhagen, Madrid, Paris
    MUI_Std     : @tzres.dll,-302
    MUI_Display : @tzres.dll,-300
    MUI_Dlt     : @tzres.dll,-301
    TimeSpan    : 01:00:00
    Dlt         : Romance Daylight Time
    Std         : Romance Standard Time

    Returns the local timezone as a PSCustomObject

.EXAMPLE    
    Get-TZ.ps1 -All
    Retrieve all the timezones from the registry and display them the same way tzutil /l does.
 
.EXAMPLE    
    Get-TZ.ps1 -All -Full
    Retrieve all the timezones from the registry and display them the same way tzutil /l does, with two addtional columns: CurrentTime and TimeSpan
 
.EXAMPLE
    Get-TZ.ps1 &quot;.&quot;
    Get the timezone of the local computer with WMI (the computername is the default parameter and it can be omitted)
 
.EXAMPLE    
    .\Get-Tz.ps1 -Computername remotecomputer1,remotecomputer2
    Get the timezone of two remote computers with WMI
  
.EXAMPLE    
    .\Get-Tz.ps1 -Computername remotecomputer1,remotecomputer2 -Credential (Get-Credential)
    Get the timezone of two remote computers with WMI using the specified prompter credential

.EXAMPLE
    .\Get-Tz.ps1 -FindResource &quot;@tzres.dll,-300&quot;

    Id          : Romance Standard Time
    CurrentTime : 11/02/2012 16:33
    DisplayName : (UTC+01:00) Brussels, Copenhagen, Madrid, Paris
    MUI_Std     : @tzres.dll,-302
    MUI_Display : @tzres.dll,-300
    MUI_Dlt     : @tzres.dll,-301
    TimeSpan    : 01:00:00
    Dlt         : Romance Daylight Time
    Std         : Romance Standard Time
    
    Show all the timezones that have this specific resource.

.NOTES    
    Name: Get-TZ
    Author: Emin Atac
    DateCreated: 11/02/2012
 
.LINK    
    http://p0w3rsh3ll.wordpress.com
 
#&gt;

[CmdletBinding(DefaultParameterSetName='GetRemoteTZ', SupportsTransactions=$false)]
param(
   [Parameter(ParameterSetName='LocalTZ', Mandatory=$false, Position=0)]
    [System.Management.Automation.SwitchParameter]${Local},

    [Parameter(ParameterSetName='Tzutil', Mandatory=$false, Position=0)]
    [System.Management.Automation.SwitchParameter]${All},

    [Parameter(ParameterSetName='Tzutil', Mandatory=$false, Position=1)]
    [switch]${Full},

    [Parameter(ParameterSetName='Find', Mandatory=$true, Position=0)]
    [string[]]${FindResource},

    [Parameter(ParameterSetName='GetRemoteTZ', Mandatory=$true, Position=0)]
    [string[]]${Computername},

    [Parameter(ParameterSetName='GetRemoteTZ', Mandatory=$false, Position=1)]
    [System.Management.Automation.PSCredential]${Credential}
)

# Build a hashtable for splatting
$otherparams = @{}
if ($credential)
{
    $otherparams += @{Credential = $Credential}
}

# Read the main key where all time zones are stored
$root = Get-Childitem &quot;HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Time Zones&quot;

# Get the current local date time
$mydatetime = [datetime]::Now

# Initialize an empty array
$allTZobj = @()

# Loop into each subkey representing a timezone
foreach ($i in $root)
{
    # Write-Verbose -Message &quot;Dealing with $($i.Name)&quot; -Verbose:$true

    # Build the subkey path    
    $subkey = Join-Path -Path $i.PSParentPath -ChildPath $i.PSChildName

    # Get its properties
    $subkeyproperties = Get-ItemProperty -Path $subkey

    # There isn't any IsObsolete value, ie, it's null, then it's what we are looking for
    if ($subkeyproperties.IsObsolete -eq $null)
    {
        $Object = $null
        # Build an object to store all the properties we are interested in
        $Object = New-Object -TypeName PSObject -Property @{
            Id = $i.PSChildName
            Std = $subkeyproperties.Std
            TimeSpan = [System.TimeZoneInfo]::FindSystemTimeZoneById($i.PSChildName).BaseUtcOffset
            CurrentTime = ([System.TimeZoneinfo]::ConvertTime($mydatetime,([System.TimeZoneInfo]::FindSystemTimeZoneById($i.PSChildName)))).tostring('g')
            DisplayName = $subkeyproperties.Display
            Dlt = $subkeyproperties.Dlt
            MUI_Display = $subkeyproperties.MUI_Display
            MUI_Std = $subkeyproperties.MUI_Std
            MUI_Dlt = $subkeyproperties.MUI_Dlt
            }
    # Add this new object to our main array
    $allTZobj += $Object
    }
}

switch ($PsCmdlet.ParameterSetName)
{ 
    Tzutil {
        # If the additional Full switch was specified, display two additional columns
        if($PSBoundParameters['Full'])
        {
            $allTZObj | Select-Object -Property CurrentTime,DisplayName,Id,TimeSpan | Sort-Object -Descending:$false -Property TimeSpan
        } else {
            # Display the same output as tzutil /l
            # Use timespan to sort like tzutil /l but only display the same 2 properties as tzutil /l
        $allTZObj | Sort-Object -Descending:$false -Property TimeSpan | Select-Object -Property DisplayName,Id
        }
    } # end of Tzutil

    Find {
        # Parse our array and find any timezone that matches the string we specified
        foreach ($Resource in $FindResource)
        {
            $allTZObj | Where-Object { ($_.MUI_Std -eq $Resource) -or ($_.MUI_Display -eq $Resource) -or ($_.MUI_Dlt -eq $Resource)}
        }
    } # end of Find
    
    LocalTZ {
        # Parse our array and find the current time on the local computer
        $allTZObj | Where-Object { $_.Displayname -eq ([System.TimeZoneInfo]::Local).ToString()}
    } # end of LocalTZ
    
    GetRemoteTZ {
        # Read the timezone of remote computers using WMI and parse our array to display their timezone properties
        foreach ($Computer in $ComputerName)
        {
            # Define the  HKLM Constant and the Key we are looking for
            $HKLM = 2147483650
            $Key = &quot;SYSTEM\CurrentControlSet\Control\TimeZoneInformation&quot;
            try
            {
                $result = Invoke-WmiMethod -Path &quot;ROOT\DEFAULT:StdRegProv&quot; -ComputerName $Computer -Name GetStringValue -ArgumentList $HKLM,$Key,&quot;StandardName&quot;  -ErrorAction Stop @otherparams
            }
            catch
            {
                # WMI was unable to retrieve the information
                switch ($_)
                {
                    {$_.Exception.ErrorCode -eq 0x800706ba} { $reason =  &quot;Unavailable (offline, firewall)&quot; }
                    {$_.CategoryInfo.Reason -eq 'UnauthorizedAccessException' } { $reason = &quot;Access denied&quot; }
                    default { $reason  = $_.Exception.Message }
                }
                Write-Host -ForegroundColor Yellow  -Object &quot;Failed to connect to WMI on $Computer because: $reason&quot;
            }
            if ($result.sValue -ne $null)
            {
                $allTZObj | Where-Object { ($_.MUI_Std -eq $result.sValue) -or ($_.MUI_Display -eq $result.sValue) -or ($_.MUI_Dlt -eq $result.sValue)}
            }
        }
    } # end of GetRemoteTZ
} # end of switch
</pre></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/p0w3rsh3ll.wordpress.com/187/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/p0w3rsh3ll.wordpress.com/187/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/p0w3rsh3ll.wordpress.com/187/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/p0w3rsh3ll.wordpress.com/187/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/p0w3rsh3ll.wordpress.com/187/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/p0w3rsh3ll.wordpress.com/187/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/p0w3rsh3ll.wordpress.com/187/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/p0w3rsh3ll.wordpress.com/187/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/p0w3rsh3ll.wordpress.com/187/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/p0w3rsh3ll.wordpress.com/187/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/p0w3rsh3ll.wordpress.com/187/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/p0w3rsh3ll.wordpress.com/187/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/p0w3rsh3ll.wordpress.com/187/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/p0w3rsh3ll.wordpress.com/187/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=p0w3rsh3ll.wordpress.com&amp;blog=31062221&amp;post=187&amp;subd=p0w3rsh3ll&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://p0w3rsh3ll.wordpress.com/2012/02/11/get-timezone/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/f416a6060a6e1cf59bd8b5618a4b1680?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">pwrshll</media:title>
		</media:content>

		<media:content url="http://p0w3rsh3ll.files.wordpress.com/2012/02/regquerytz.png" medium="image">
			<media:title type="html">regqueryTZ</media:title>
		</media:content>

		<media:content url="http://p0w3rsh3ll.files.wordpress.com/2012/02/tw-getresourcestring.png" medium="image">
			<media:title type="html">Get-ResourceString</media:title>
		</media:content>

		<media:content url="http://p0w3rsh3ll.files.wordpress.com/2012/02/dism_tzutil.png" medium="image">
			<media:title type="html">dism-tzutil</media:title>
		</media:content>

		<media:content url="http://p0w3rsh3ll.files.wordpress.com/2012/02/tzutil_procmon.png" medium="image">
			<media:title type="html">procmon_tzutil</media:title>
		</media:content>

		<media:content url="http://p0w3rsh3ll.files.wordpress.com/2012/02/datetimekind.png" medium="image">
			<media:title type="html">datetimeKind</media:title>
		</media:content>

		<media:content url="http://p0w3rsh3ll.files.wordpress.com/2012/02/formatdatetime.png" medium="image">
			<media:title type="html">formatdatetime</media:title>
		</media:content>
	</item>
		<item>
		<title>Working with Applocker and Filepath Rules</title>
		<link>http://p0w3rsh3ll.wordpress.com/2012/02/08/working-with-applocker-and-filepath-rules/</link>
		<comments>http://p0w3rsh3ll.wordpress.com/2012/02/08/working-with-applocker-and-filepath-rules/#comments</comments>
		<pubDate>Wed, 08 Feb 2012 18:28:51 +0000</pubDate>
		<dc:creator>_Emin_</dc:creator>
				<category><![CDATA[powershell]]></category>

		<guid isPermaLink="false">http://p0w3rsh3ll.wordpress.com/?p=156</guid>
		<description><![CDATA[A few days ago, I&#8217;ve added some filepath rules concerning new servers put into production to my Applocker GPO. I decided to quickly check if all the files paths were correct. Manually typing filepath is prone to errors. To detect &#8230; <a href="http://p0w3rsh3ll.wordpress.com/2012/02/08/working-with-applocker-and-filepath-rules/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=p0w3rsh3ll.wordpress.com&amp;blog=31062221&amp;post=156&amp;subd=p0w3rsh3ll&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>A few days ago, I&#8217;ve added some filepath rules concerning new servers put into production to my Applocker GPO.<br />
I decided to quickly check if all the files paths were correct. Manually typing filepath is prone to errors. To detect typos or servers currently being unavailable, I did:</p>
<p><pre class="brush: powershell; light: true;">    

Import-Module -Name &quot;GroupPolicy&quot;
Import-Module -Name &quot;Applocker&quot;

# Read the GPO and store it as an XML object
$GPO = [xml](Get-AppLockerPolicy -Ldap (&quot;LDAP://&quot; + (Get-GPO -Name &quot;Computers Parameters&quot;).path) -Domain -XML)

(($GPO.AppLockerPolicy.RuleCollection | Where-Object { $_.Type -eq &quot;Exe&quot;}).FilePathRule) | ForEach-Object {

        $string = $_.Conditions.FilePathCondition.Path

        # Use a regular expression that represents 
        # \\servername\share\* or \\servername\share$\* or
        # \\server.fqdn.domain.suffix\share\* or \\server.fqdn.domain.suffix\share$\*
        $pattern = '^\\\\\b([A-Za-z0-9_\.\-]+)\\\b([A-Za-z0-9_\.\-]+(\$)?)\\\*$'
        if ($string -match $pattern)
        {
                if (Test-Path -Path ($string -replace &quot;\*&quot;,&quot;&quot;) -ErrorAction SilentlyContinue)
                {
                    Write-Host -ForegroundColor Green -Object ($string + &quot; -&gt; ok&quot;)
                } else {
                    Write-Host -ForegroundColor Red -Object ($string + &quot; -&gt; not resolved !&quot;)
                }
        } else {
            Write-Host -ForegroundColor Yellow -Object ($string + &quot; -&gt; ignored / not verified&quot;)
        }
    }    
</pre></p>
<p>and got the following result displayed<br />
<img src="http://p0w3rsh3ll.files.wordpress.com/2012/02/applocker_filepathrules2.png?w=584" alt="applocker filepath rules" /></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/p0w3rsh3ll.wordpress.com/156/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/p0w3rsh3ll.wordpress.com/156/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/p0w3rsh3ll.wordpress.com/156/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/p0w3rsh3ll.wordpress.com/156/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/p0w3rsh3ll.wordpress.com/156/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/p0w3rsh3ll.wordpress.com/156/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/p0w3rsh3ll.wordpress.com/156/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/p0w3rsh3ll.wordpress.com/156/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/p0w3rsh3ll.wordpress.com/156/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/p0w3rsh3ll.wordpress.com/156/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/p0w3rsh3ll.wordpress.com/156/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/p0w3rsh3ll.wordpress.com/156/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/p0w3rsh3ll.wordpress.com/156/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/p0w3rsh3ll.wordpress.com/156/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=p0w3rsh3ll.wordpress.com&amp;blog=31062221&amp;post=156&amp;subd=p0w3rsh3ll&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://p0w3rsh3ll.wordpress.com/2012/02/08/working-with-applocker-and-filepath-rules/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/f416a6060a6e1cf59bd8b5618a4b1680?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">pwrshll</media:title>
		</media:content>

		<media:content url="http://p0w3rsh3ll.files.wordpress.com/2012/02/applocker_filepathrules2.png" medium="image">
			<media:title type="html">applocker filepath rules</media:title>
		</media:content>
	</item>
		<item>
		<title>Get-share</title>
		<link>http://p0w3rsh3ll.wordpress.com/2012/02/06/get-share/</link>
		<comments>http://p0w3rsh3ll.wordpress.com/2012/02/06/get-share/#comments</comments>
		<pubDate>Mon, 06 Feb 2012 18:51:07 +0000</pubDate>
		<dc:creator>_Emin_</dc:creator>
				<category><![CDATA[powershell]]></category>

		<guid isPermaLink="false">http://p0w3rsh3ll.wordpress.com/?p=164</guid>
		<description><![CDATA[Don&#8217;t get me wrong with my previous post. I really appreciate Richard&#8217;s work and I&#8217;ve been following his blogs for years now. A few years ago, I got inspired by his work on shares that he published in the PAM &#8230; <a href="http://p0w3rsh3ll.wordpress.com/2012/02/06/get-share/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=p0w3rsh3ll.wordpress.com&amp;blog=31062221&amp;post=164&amp;subd=p0w3rsh3ll&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Don&#8217;t get me wrong with my previous post. I really appreciate Richard&#8217;s work and I&#8217;ve been following his blogs for years now. A few years ago, I got inspired by his work on shares that he published in the PAM module on codeplex and that can be downloaded on this <a href="http://psam.codeplex.com" title="http://psam.codeplex.com" target="_blank">page</a>. I extended his code to be able to create shares on remote servers in our user account creation process.</p>
<p>My original idea was actually to be able to replace our brave old (and still working) <a href="http://support.microsoft.com/kb/172599" title="http://support.microsoft.com/kb/172599" target="_blank">rmtshare.exe</a> from the <a href="http://www.microsoft.com/resources/documentation/windowsnt/4/server/reskit/en-us/reskt4u4/rku4list.mspx?mfr=true" title="http://www.microsoft.com/resources/documentation/windowsnt/4/server/reskit/en-us/reskt4u4/rku4list.mspx?mfr=true" target="_blank">NT4.0 resource kit</a>. In other words I wanted to be able to provide the same functionnalities as the &#8216;net share&#8217; command and the &#8216;rmtshare&#8217; commmand. </p>
<p>Here are some examples of what I wanted to achieve:<br />
<img src="http://p0w3rsh3ll.files.wordpress.com/2012/02/netshare-rmtshare.png?w=584" alt="net_share_and_rmtshare_output" /></p>
<p>WMI is very resourceful in this case but it&#8217;s unfortunately unable to get the caching mode of each share. The only way to do it that I found on the web is by using the code provided on this <a href="http://www.powershell-ag.de/ps/Foren/PowerShellForum/tabid/83/forumid/8/threadid/1359/scope/posts/Default.aspx" title="http://www.powershell-ag.de/ps/Foren/PowerShellForum/tabid/83/forumid/8/threadid/1359/scope/posts/Default.aspx" target="_blank">page</a>. (NB: I&#8217;ve not tested it). Of course, using the WMI approach will be much slower than using API calls, but it&#8217;s not the main goal.</p>
<p>To be able to display the users currently accessing the share I&#8217;ve used the <a href="http://msdn.microsoft.com/en-us/library/windows/desktop/aa394109%28v=vs.85%29.aspx" title="http://msdn.microsoft.com/en-us/library/windows/desktop/aa394109%28v=vs.85%29.aspx" target="_blank">Win32_ConnectionShare</a> class and the <a href="http://tfl09.blogspot.com/2008/02/powershell-wmi-type-accelerator.html" title="http://tfl09.blogspot.com/2008/02/powershell-wmi-type-accelerator.html" target="_blank">[WMI] type accelerator</a>. The power of WMI is that the Dependent key contains a full path including the computername and the WMI accelerator is able to work accross the network. The only drawback of the WMI accelerator is that you can&#8217;t specify a credential to access a remote computer.</p>
<p>For share permissions, I took a different approach than Richard&#8217;s one. I query the <a href="http://msdn.microsoft.com/en-us/library/windows/desktop/aa394186%28v=vs.85%29.aspx" title="http://msdn.microsoft.com/en-us/library/windows/desktop/aa394186%28v=vs.85%29.aspx" target="_blank">Win32_LogicalShareAccess</a> class, its AccessMask and Trustee properties. I don&#8217;t test the binary to translate it into all the subatomic permissions granted. I&#8217;ve simplified it to display only the 3 &#8220;Read&#8221;,&#8221;Change&#8221; and &#8220;Full control&#8221; available both in the UI and the output of the &#8216;net share&#8217; command.</p>
<p>The script below can run on a local computer and target remote computers as well (specified as an array, see help)<br />
You can use credentials to access remote computers if required.<br />
The script will work both on Windows 7 or Windows XP.</p>
<p>Enjoy <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<p><pre class="brush: powershell; light: true;">    

#Requires -Version 2.0

&lt;#
 
.SYNOPSIS    
    Get share related info from WMI
 
.DESCRIPTION  
    Get share related info from WMI
 
.PARAMETER ComputerName
    Non mandatory parameter, array of computernames, the default value is &quot;.&quot; which means localhost in WMI.
 
.PARAMETER ShareName
    Non mandatory parameter, array of share names, when not specified, all shares are returned like the net share command
    When a share name is specified, it will return the output of the 'net share sharename' command

.PARAMETER Credential
    Non mandatory parameter, credential used to contact remote computer

.NOTES    
    Name: Get-Share
    Author: Emin Atac
    DateCreated: 05/02/2012
 
.LINK    
    http://p0w3rsh3ll.wordpress.com
 
.EXAMPLE    
    .\Get-Share.ps1 
    Returns all the shares on the local computer with the same output as the 'net share' command
 
.EXAMPLE    
    .\Get-Share.ps1 -ShareName ADMIN$
    Get the properties of the ADMIN$ share with the same output as the 'net share ADMIN$' command
 
.EXAMPLE
    .\Get-Share.ps1 -ShareName test-share$ | Select-Object -ExpandProperty Permissions
    Get the permissions on the 'test-share$' in a more readable format by piping it into the select-object cmdlet
    The same can be achieved with:
    (.\Get-Share -sharename &quot;test-share$&quot;).Permissions
 
.EXAMPLE    
    .\Get-Share.ps1 -ShareName test-share$ -ComputerName remotecomputer1,remotecomputer2
    Get the share properties of test-share$ on remote computers
 
.EXAMPLE
    $cred = (Get-Credential)
    .\Get-Share.ps1 -ShareName &quot;test-share1&quot;,&quot;test-share2&quot; -ComputerName remotecomputer1,remotecomputer2 -Credential $cred
    Get the share properties of 2 shares specified as an array on 2 remote computers specified as an array by using another credential
    NB: Users and Caching mode will be returned as &quot;unknown&quot;.
 
#&gt;
 
[CmdletBinding(SupportsShouldProcess=$True)]
param (
[parameter(Mandatory=$false,Position=0)][system.array]$ShareName=$null,
[parameter(Mandatory=$false,Position=1)][system.array]$ComputerName=&quot;.&quot;,
[parameter(Mandatory=$false,Position=2)][System.Management.Automation.PSCredential]$Credential = $null
)


function ConvertTo-NtAccount
{
&lt;#
 
.SYNOPSIS    
    Translate a SID to its displayname
 
.DESCRIPTION  
    Translate a SID to its displayname
 
.PARAMETER Sid
    Provide a SID
 
.NOTES    
    Name: ConvertTo-NtAccount
    Author: thepowershellguy
 
.LINK    
    http://thepowershellguy.com/blogs/posh/archive/2007/01/23/powershell-converting-accountname-to-sid-and-vice-versa.aspx
 
.EXAMPLE
    ConvertTo-NtAccount S-1-1-0
    Convert a well-known SID to its displayname
 
#&gt;
 
param(
[parameter(Mandatory=$true,Position=0)][system.string]$Sid = $null
)
 begin
 {
    $obj = new-object system.security.principal.securityidentifier($sid)
 }
 process
 {
    try
    {
        $obj.translate([system.security.principal.ntaccount])
    }
    catch
    {
        # To remove the silent fail, uncomment next line
        # $_
    }
 }
 end {}
}

# Handle the sharename parameter and build a unique WMI with all share names in the array
if (-not($sharename))
{
    $Query = &quot;Select * FROM Win32_Share&quot; 
} else {

    for ( $i=0 ; $i -lt $sharename.Count ; $i++)
    {
        if ($i -eq 0)
        {
            $Query = &quot;Select * FROM Win32_Share WHERE &quot; + &quot;Name = '&quot; + $sharename[$i] + &quot;'&quot;
        } else {
            $Query = $Query + &quot; OR Name = '&quot; + $sharename[$i] + &quot;'&quot;
        }
    } # end of for loop
}

# Build a hashtable for splatting
$otherparams = @{}
if ($credential)
{
    $otherparams += @{Credential = $Credential}
}

# Prepare global script variable
$consoleoutput = @()

foreach ($computer in $computername)
{
    try
    {
        $shares = @(Get-WmiObject -ComputerName $computer -Query $Query -ErrorAction Stop @otherparams)
    }
    catch
    {
        # WMI was unable to retrieve the information
        switch ($_)
        {
            {$_.Exception.ErrorCode -eq 0x800706ba} { $reason =  &quot;Unavailable (offline, firewall)&quot; }
            {$_.CategoryInfo.Reason -eq 'UnauthorizedAccessException' } { $reason = &quot;Access denied&quot; }
            default { $reason  = $_.Exception.Message }
        }
        Write-Host -ForegroundColor Yellow  -Object &quot;Failed to connect to WMI on $Computer because: $reason&quot;
        # break
    }

    # If we have shares returned by the above WMI query
    if ($shares.Count -ne 0)
    {
        # Loop
        foreach ($shareitem in $shares)
        {
            # Get the Maximum users properties
            if ($shareitem.AllowMaximum -eq $true)
            {
                $Max = &quot;No limit&quot;
            } else {
                $Max = $shareitem.MaximumAllowed
            }

            # Replace some special characters in the share name to use it as a regular expression pattern with the match operator
            $pattern = $shareitem.Name -replace &quot;\$&quot;,&quot;\$&quot;
            $pattern = $pattern -replace &quot;\-&quot;,&quot;\-&quot;
            $pattern = $pattern -replace &quot;\.&quot;,&quot;\.&quot;

            # Get connected users to the share
            $Users = @()
            $shareconnections = @(Get-WmiObject -Class Win32_ConnectionShare -ComputerName  $computer -ErrorAction SilentlyContinue @otherparams)
            if ($shareconnections.Count -ne 0)
            {
                if (-not($credential))
                {
                    ForEach ($share in $shareconnections)
                    {
                        $allconnectedusers = @([wmi]$share.Dependent | Where-Object {$_.ShareName -match $pattern})
                        foreach ($user in $allconnectedusers)
                        {
                            $Users += (New-Object -TypeName PSObject -Property @{Username = $User.Username})
                        }
                    } # end of foreach
                } else {
                    ForEach ($share in $shareconnections)
                    {
                        if ($share.Dependent -match $pattern)
                        {
                            $Users += (New-Object -TypeName PSObject -Property @{Username = $(($share.Dependent  -split &quot;=&quot;)[-1] -replace &quot;`&quot;&quot;,&quot;&quot;)})
                        }
                    } # end of foreach
                }
            }

            # Get the caching mode of the share

            # Define the  HKLM Constant and the Key we are looking for
            $HKLM = 2147483650
            $Key = &quot;SYSTEM\CurrentControlSet\services\LanmanServer\Shares&quot;

            $result = Invoke-WmiMethod -Path &quot;ROOT\DEFAULT:StdRegProv&quot; -ComputerName $computer -Name GetMultiStringValue -ArgumentList $HKLM,$Key,$($shareitem.Name)  -ErrorAction SilentlyContinue @otherparams
            
            if ($result.sValue -ne $null)
            {
                # We split the multiline string and just look for the CSCFlags string
                $CSCFlag = $null
                $CSCFlag = ((($result.svalue -split &quot;`n&quot;) | Where-Object {$_ -match &quot;^CSCFlags&quot;}) -split &quot;=&quot;)[1]
                
                switch($CSCFlag)
                {
                    0  {$Caching = &quot;Manual caching of documents&quot;}
                    16 {$Caching = &quot;Automatic caching of documents&quot;}
                    32 {$Caching = &quot;Automatic caching of programs and documents&quot;}
                    48 {$Caching = &quot;Caching disabled&quot;}
                    default {$Caching = &quot;Unknown&quot;}
                }
            } else {
                    # If we don't find it in the registry, it means it's the default value
                    $Caching = &quot;Manual caching of documents&quot;
            }
           
            # Get Permissions of the share

            # Change a little bit our pattern
            $pattern = $pattern + &quot;`&quot;$&quot;

            # Reset array
            $Permissions = @()
                    
            # Now get the permissions for our share
            $shareperms = @(Get-WmiObject -Class Win32_LogicalShareAccess -ComputerName  $computer -ErrorAction SilentlyContinue @otherparams| Where-Object {$_.SecuritySetting -match $pattern})
                    
            # If we don't find it in the class, it means it's the default &quot;everyone, full control&quot;
            if ($shareperms.Count -eq 0)
            {
                    $Permissions = New-Object -TypeName PSObject -Property @{            
                            Username = &quot;Everyone&quot; 
                            AccessMask = &quot;Full Control&quot;
                    }
            } else {
                # Loop foreach permission returned by the WMI query of the Win32_LogicalShareAccess class
                ForEach ($perm in $shareperms)
                {
                    # Convert the SID property to a username
                    $Username = $Permission = $null
                    $Username = ConvertTo-NtAccount -SID (($perm.Trustee -split &quot;=&quot;)[1] -replace &quot;`&quot;&quot;,&quot;&quot;)

                    # Change the binary to a human readable string
                    switch($perm.AccessMask)
                    {
                        1179817 { $Mask = &quot;Read&quot;}
                        1245631 { $Mask = &quot;Change&quot;}
                        2032127 { $Mask = &quot;Full Control&quot;}
                        default { $Mask = &quot;Unknown&quot;}
                    }

                    # Add to a custom object
                    $Permission = New-Object -TypeName PSObject -Property @{            
                            Username = $Username
                            AccessMask = $Mask
                    }

                    # Add the permission to our permissions array
                    $Permissions += $Permission

                } # end of foreach shareperms
            } # end of if shareperms.count

            # Display diffently the share name on a remote computer
            $formattedshare = $null
            if ($computer -ne &quot;.&quot;)
            {
                $formattedshare = &quot;\\$Computer\&quot; + $shareitem.Name
            } else {
                $formattedshare = $shareitem.Name
            }

            # Build a final share object with all its properties
            $ShareObject = $null
            $ShareObject = New-Object -TypeName PSObject -Property @{
                &quot;Share name&quot; = $formattedshare
                Path = $shareitem.Path
                Remark = $shareitem.Description
                &quot;Maximum Users&quot; = $Max
                Users = $Users
                Caching = $Caching
                Permissions = $Permissions
                }

            # We can return it now, if we aren't listing all shares
            if (-not($sharename))
            {
                # Format the console output to display the same properties as the 'net share' command
                $consoleoutput += $ShareObject 
            } else {
                # Output the object with all its properties
                Write-Output -InputObject $ShareObject                
            }
        } # end of foreach shares

        # Console output that lists all shares
        if (-not($sharename))
        {
            Write-Output -InputObject $consoleoutput | Select-Object -Property &quot;Share Name&quot;,Path,Remark
        }
    } else {
        Write-Host -ForegroundColor Yellow &quot;$sharename share name not found on computer $computer&quot;
    } # end of if shares
} # end of foreach $computername

</pre></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/p0w3rsh3ll.wordpress.com/164/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/p0w3rsh3ll.wordpress.com/164/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/p0w3rsh3ll.wordpress.com/164/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/p0w3rsh3ll.wordpress.com/164/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/p0w3rsh3ll.wordpress.com/164/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/p0w3rsh3ll.wordpress.com/164/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/p0w3rsh3ll.wordpress.com/164/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/p0w3rsh3ll.wordpress.com/164/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/p0w3rsh3ll.wordpress.com/164/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/p0w3rsh3ll.wordpress.com/164/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/p0w3rsh3ll.wordpress.com/164/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/p0w3rsh3ll.wordpress.com/164/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/p0w3rsh3ll.wordpress.com/164/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/p0w3rsh3ll.wordpress.com/164/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=p0w3rsh3ll.wordpress.com&amp;blog=31062221&amp;post=164&amp;subd=p0w3rsh3ll&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://p0w3rsh3ll.wordpress.com/2012/02/06/get-share/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/f416a6060a6e1cf59bd8b5618a4b1680?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">pwrshll</media:title>
		</media:content>

		<media:content url="http://p0w3rsh3ll.files.wordpress.com/2012/02/netshare-rmtshare.png" medium="image">
			<media:title type="html">net_share_and_rmtshare_output</media:title>
		</media:content>
	</item>
		<item>
		<title>Get Logged on users</title>
		<link>http://p0w3rsh3ll.wordpress.com/2012/02/03/get-logged-on-users/</link>
		<comments>http://p0w3rsh3ll.wordpress.com/2012/02/03/get-logged-on-users/#comments</comments>
		<pubDate>Fri, 03 Feb 2012 21:05:21 +0000</pubDate>
		<dc:creator>_Emin_</dc:creator>
				<category><![CDATA[powershell]]></category>

		<guid isPermaLink="false">http://p0w3rsh3ll.wordpress.com/?p=152</guid>
		<description><![CDATA[The powershell MVP Richard Siddaway posted recently on his blog a way to list all currently users who have a session loaded on a computer being interactive or not. Note that it requires admin rights and the it fails to &#8230; <a href="http://p0w3rsh3ll.wordpress.com/2012/02/03/get-logged-on-users/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=p0w3rsh3ll.wordpress.com&amp;blog=31062221&amp;post=152&amp;subd=p0w3rsh3ll&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>The powershell MVP Richard Siddaway posted recently on his <a href="http://richardspowershellblog.wordpress.com/2012/01/17/get-the-logged-on-users/" title="http://richardspowershellblog.wordpress.com/2012/01/17/get-the-logged-on-users/" target="_blank">blog</a> a way to list all currently users who have a session loaded on a computer being interactive or not. Note that it requires admin rights and the it fails to display domain users if it&#8217;s unable to resolve it using a domain controller.</p>
<p>But, how do we get only users who logged on interactively ?</p>
<p><pre class="brush: powershell; light: true;">
(get-wmiobject -class Win32_ComputerSystem).Username
</pre><br />
But this has a limitation as the following page on MSDN <a href="http://msdn.microsoft.com/en-us/library/windows/desktop/aa394102%28v=vs.85%29.aspx" title="http://msdn.microsoft.com/en-us/library/windows/desktop/aa394102%28v=vs.85%29.aspx" target="_blank">about the Win32_ComputerSystem</a> states that</p>
<blockquote><p>
    Name of a user that is logged on currently. This property must have a value. In a terminal services session, UserName returns the name of the user that is logged on to the console—not the user logged on during the terminal service session.
</p></blockquote>
<p>It is also not as reliable as it seems. It may return an empty value if the user is connected using remote desktop.</p>
<p>We could also query the Win32_LoggedOnUser which seems to be promising.</p>
<p><pre class="brush: powershell; light: true;">
# To obtain Domain\Username format, we can do:
Get-WmiObject -Class Win32_LoggedOnUser | ForEach-Object { 
    Write-Host -Object (($_.Antecedent.ToString() -split '[\=\&quot;]')[2] + &quot;\&quot; +  ($_.Antecedent.ToString() -split '[\=\&quot;]')[5])
}

# Or more simply if we don't care too much about the format being displayed
Get-WmiObject -Class Win32_LoggedOnUser | ForEach-Object { Write-Host -NoNewline -Object (($_.Antecedent.ToString() -split '[\=\&quot;]')[2,5] + &quot;`n&quot;)}

</pre><br />
Unfortunately, we get more results than expected.</p>
<p>Well, in this case, what I prefer to do is the following. If someone opened an interactive session on a computer, I can assume that the explorer was loaded. So the idea is to get the owner of each explorer.exe process and voilà.</p>
<p><pre class="brush: powershell; light: true;">
$explorerprocesses = @(Get-WmiObject -Query &quot;Select * FROM Win32_Process WHERE Name='explorer.exe'&quot; -ErrorAction SilentlyContinue)
if ($explorerprocesses.Count -eq 0)
{
    &quot;No explorer process found / Nobody interactively logged on&quot;
} else {
    foreach ($i in $explorerprocesses)
    {
        $Username = $i.GetOwner().User
        $Domain = $i.GetOwner().Domain
        $Domain + &quot;\&quot; + $Username + &quot; logged on since: &quot; + ($i.ConvertToDateTime($i.CreationDate))
    }
}
</pre></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/p0w3rsh3ll.wordpress.com/152/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/p0w3rsh3ll.wordpress.com/152/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/p0w3rsh3ll.wordpress.com/152/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/p0w3rsh3ll.wordpress.com/152/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/p0w3rsh3ll.wordpress.com/152/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/p0w3rsh3ll.wordpress.com/152/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/p0w3rsh3ll.wordpress.com/152/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/p0w3rsh3ll.wordpress.com/152/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/p0w3rsh3ll.wordpress.com/152/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/p0w3rsh3ll.wordpress.com/152/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/p0w3rsh3ll.wordpress.com/152/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/p0w3rsh3ll.wordpress.com/152/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/p0w3rsh3ll.wordpress.com/152/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/p0w3rsh3ll.wordpress.com/152/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=p0w3rsh3ll.wordpress.com&amp;blog=31062221&amp;post=152&amp;subd=p0w3rsh3ll&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://p0w3rsh3ll.wordpress.com/2012/02/03/get-logged-on-users/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/f416a6060a6e1cf59bd8b5618a4b1680?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">pwrshll</media:title>
		</media:content>
	</item>
		<item>
		<title>Delete what triggers eventID 10</title>
		<link>http://p0w3rsh3ll.wordpress.com/2012/01/26/delete-what-triggers-eventid-10/</link>
		<comments>http://p0w3rsh3ll.wordpress.com/2012/01/26/delete-what-triggers-eventid-10/#comments</comments>
		<pubDate>Thu, 26 Jan 2012 18:35:42 +0000</pubDate>
		<dc:creator>_Emin_</dc:creator>
				<category><![CDATA[powershell]]></category>

		<guid isPermaLink="false">http://p0w3rsh3ll.wordpress.com/?p=139</guid>
		<description><![CDATA[Back in the old days of Vista SP1, Microsoft introducted a permanent WMI event that triggers an event in the logs whenever your processor reaches 99% of usage. It&#8217;s a good idea but it&#8217;s unfortunately written as an error and &#8230; <a href="http://p0w3rsh3ll.wordpress.com/2012/01/26/delete-what-triggers-eventid-10/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=p0w3rsh3ll.wordpress.com&amp;blog=31062221&amp;post=139&amp;subd=p0w3rsh3ll&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Back in the old days of Vista SP1, Microsoft introducted a permanent WMI event that triggers an event in the logs whenever your processor reaches 99% of usage. It&#8217;s a good idea but it&#8217;s unfortunately written as an error and catched by the administrative view filter.<br />
<img src="http://p0w3rsh3ll.files.wordpress.com/2012/01/eventid10.png?w=584" alt="eventID 10" /></p>
<p>The problem is that it&#8217;s a false positive that Microsoft reintroduced in Windows 7 SP1 <img src='http://s0.wp.com/wp-includes/images/smilies/icon_sad.gif' alt=':-(' class='wp-smiley' /><br />
Microsoft still only gives us a workaround based on an old fashioned vbscript.</p>
<p>So, here&#8217;s how to achieve the same thing as the vbscript by using powershell:</p>
<p><pre class="brush: powershell; light: true;">
# 
# Delete the eventID 10
#
# http://support.microsoft.com/kb/950375

$obj1  = @(Get-WmiObject -Namespace &quot;root\subscription&quot;  -Query &quot;Select * FROM __EventFilter WHERE Name='BVTFilter'&quot; -ErrorAction SilentlyContinue)
$obj2 = @(Get-WmiObject -Namespace &quot;root\subscription&quot;  -Query &quot;Associators Of {__EventFilter.Name='BVTFilter'} WHERE AssocClass=__FilterToConsumerBinding&quot; -ErrorAction SilentlyContinue)
if ($obj2.Count -eq 0)
{
    Write-Warning -Message &quot;obj2 not found&quot;
} else {

    foreach ($obj in $obj2)
    {
        try 
        {
            $obj.delete()
        }
        catch
        {
            Write-Warning -Message &quot;Failed to delete $obj&quot;
            $_.Exception.ErrorCode 
            $_.CategoryInfo.Reason
            $_.Exception.Message
        }
    }
}

$obj3 = @(Get-WmiObject -Namespace &quot;root\subscription&quot;  -Query &quot;References Of {__EventFilter.Name='BVTFilter'} WHERE ResultClass=__FilterToConsumerBinding&quot; -ErrorAction SilentlyContinue)
if ($obj3.Count -eq 0)
{
    Write-Warning -Message &quot;obj3 not found&quot;
} else {
    foreach ($obj in $obj3)
    {
        try 
        {
            $obj.delete()
        }
        catch
        {
            Write-Warning -Message &quot;Failed to delete $obj&quot;
            $_.Exception.ErrorCode 
            $_.CategoryInfo.Reason
            $_.Exception.Message
        }
    }
}

if ($obj1.Count -eq 0)
{
    Write-Warning -Message &quot;obj1 not found&quot;
} else {
    $obj1[0].delete()    
}
</pre></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/p0w3rsh3ll.wordpress.com/139/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/p0w3rsh3ll.wordpress.com/139/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/p0w3rsh3ll.wordpress.com/139/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/p0w3rsh3ll.wordpress.com/139/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/p0w3rsh3ll.wordpress.com/139/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/p0w3rsh3ll.wordpress.com/139/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/p0w3rsh3ll.wordpress.com/139/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/p0w3rsh3ll.wordpress.com/139/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/p0w3rsh3ll.wordpress.com/139/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/p0w3rsh3ll.wordpress.com/139/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/p0w3rsh3ll.wordpress.com/139/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/p0w3rsh3ll.wordpress.com/139/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/p0w3rsh3ll.wordpress.com/139/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/p0w3rsh3ll.wordpress.com/139/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=p0w3rsh3ll.wordpress.com&amp;blog=31062221&amp;post=139&amp;subd=p0w3rsh3ll&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://p0w3rsh3ll.wordpress.com/2012/01/26/delete-what-triggers-eventid-10/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/f416a6060a6e1cf59bd8b5618a4b1680?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">pwrshll</media:title>
		</media:content>

		<media:content url="http://p0w3rsh3ll.files.wordpress.com/2012/01/eventid10.png" medium="image">
			<media:title type="html">eventID 10</media:title>
		</media:content>
	</item>
		<item>
		<title>Get random passwords</title>
		<link>http://p0w3rsh3ll.wordpress.com/2012/01/24/get-random-passwords/</link>
		<comments>http://p0w3rsh3ll.wordpress.com/2012/01/24/get-random-passwords/#comments</comments>
		<pubDate>Tue, 24 Jan 2012 19:24:14 +0000</pubDate>
		<dc:creator>_Emin_</dc:creator>
				<category><![CDATA[powershell]]></category>

		<guid isPermaLink="false">http://p0w3rsh3ll.wordpress.com/?p=131</guid>
		<description><![CDATA[As part of my daily operations tasks, I have sometimes to create random passwords for a new series of computers to be integrated in the domain. Precisely, I have to create a list of computers and their random 10 characters &#8230; <a href="http://p0w3rsh3ll.wordpress.com/2012/01/24/get-random-passwords/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=p0w3rsh3ll.wordpress.com&amp;blog=31062221&amp;post=131&amp;subd=p0w3rsh3ll&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>As part of my daily operations tasks, I have sometimes to create random passwords for a new series of computers to be integrated in the domain.</p>
<p>Precisely, I have to create a list of computers and their random 10 characters long passwords that mixes upper and lower case letters compatible with a qwerty and azerty keyboard layout and that doesn&#8217;t match a word in a dictionary. The computer names and passwords should be tab separated so that it could be appended to our global passwords file a.xls in order to be readable in Excel (if necessary). Using a tab separated file also allows us to use this file in a scripted manner. It&#8217;s being parsed by a central custom script that checks if the password didn&#8217;t change on a daily basis.</p>
<p>So here&#8217;s the result of my quick and dirty approach for computer names from PTV800 to PTV899.</p>
<p><pre class="brush: powershell; light: true;">
# Get a list of characters
$list = [Char[]]'bcdefhijklnoprstuvxBCDEFHIJKLNOPRSTUVX'

# Loop 
0..99 | % {
 # Get a 10 characters long random password where each characters is picked up from our list of characters
 $pw = (-join (1..10 | Foreach-Object { Get-Random $list -count 1 }))
 # Build our computername matching our naming convention
 $pcname = &quot;PTV8&quot; + (&quot;{0:00}&quot; -f $_)
 Write-Host -Object ($pcname + &quot;`t&quot; + $pw)
 # Append to our global tab separated file
 Write-Output -InputObject ($pcname + &quot;`t&quot; + $pw)  | Out-File -filepath .\a.xls -Append -NoClobber -Encoding ASCII
}
</pre></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/p0w3rsh3ll.wordpress.com/131/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/p0w3rsh3ll.wordpress.com/131/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/p0w3rsh3ll.wordpress.com/131/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/p0w3rsh3ll.wordpress.com/131/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/p0w3rsh3ll.wordpress.com/131/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/p0w3rsh3ll.wordpress.com/131/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/p0w3rsh3ll.wordpress.com/131/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/p0w3rsh3ll.wordpress.com/131/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/p0w3rsh3ll.wordpress.com/131/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/p0w3rsh3ll.wordpress.com/131/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/p0w3rsh3ll.wordpress.com/131/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/p0w3rsh3ll.wordpress.com/131/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/p0w3rsh3ll.wordpress.com/131/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/p0w3rsh3ll.wordpress.com/131/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=p0w3rsh3ll.wordpress.com&amp;blog=31062221&amp;post=131&amp;subd=p0w3rsh3ll&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://p0w3rsh3ll.wordpress.com/2012/01/24/get-random-passwords/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/f416a6060a6e1cf59bd8b5618a4b1680?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">pwrshll</media:title>
		</media:content>
	</item>
		<item>
		<title>Working with system locale and user locale</title>
		<link>http://p0w3rsh3ll.wordpress.com/2012/01/22/working-with-system-locale-and-user-locale/</link>
		<comments>http://p0w3rsh3ll.wordpress.com/2012/01/22/working-with-system-locale-and-user-locale/#comments</comments>
		<pubDate>Sun, 22 Jan 2012 17:01:16 +0000</pubDate>
		<dc:creator>_Emin_</dc:creator>
				<category><![CDATA[powershell]]></category>

		<guid isPermaLink="false">http://p0w3rsh3ll.wordpress.com/?p=112</guid>
		<description><![CDATA[Last week while working with the WDRAP tool (Risk and Health Assessment Program for Windows Desktop) from Microsoft, it complained about the system locale not being en-US (English United States). So I started digging into this subject and found that &#8230; <a href="http://p0w3rsh3ll.wordpress.com/2012/01/22/working-with-system-locale-and-user-locale/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=p0w3rsh3ll.wordpress.com&amp;blog=31062221&amp;post=112&amp;subd=p0w3rsh3ll&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Last week while working with the <a href="http://www.microsoft.com/download/en/details.aspx?id=1071" title="http://www.microsoft.com/download/en/details.aspx?id=1071" target="_blank">WDRAP</a> tool (Risk and Health Assessment Program for Windows Desktop) from Microsoft, it complained about the system locale not being en-US (English United States).</p>
<p>So I started digging into this subject and found that there are many ways to get the user locale.<br />
You can query the <a href="http://technet.microsoft.com/en-us/library/dd347675.aspx" title="http://technet.microsoft.com/en-us/library/dd347675.aspx" target="_blank">$host variable</a> in your powrshell session:<br />
<pre class="brush: powershell; light: true;">
$host.CurrentCulture
</pre><br />
Or  you can also simply query the <a href="http://technet.microsoft.com/en-us/library/dd347604.aspx" title="http://technet.microsoft.com/en-us/library/dd347604.aspx" target="_blank">$PSculture</a><br />
<pre class="brush: powershell; light: true;">
$PSCulture
get-item variable:\PSCulture
</pre><br />
Or you can use the following .Net object:<br />
<pre class="brush: powershell; light: true;">
[System.Threading.Thread]::CurrentThread.CurrentCulture
</pre><br />
You could also query the registry:<br />
<pre class="brush: powershell; light: true;">
(Get-ItemProperty 'HKCU:\Control Panel\International').Locale
(Get-ItemProperty 'HKCU:\Control Panel\International').LocaleName
</pre><br />
<img src="http://p0w3rsh3ll.files.wordpress.com/2012/01/user-locale-01.png?w=584" alt="user locale" /></p>
<p>But, the user locale isn&#8217;t what I was looking for. The only way I found to query the System locale is by using WMI:<br />
<pre class="brush: powershell; light: true;">
(Get-WmiObject Win32_OperatingSystem).locale
</pre></p>
<p>The WMI query returns a system string that is actually the hexadecimal number of the system locale. I was close to the result and finally used the System.Globalization.CultureInfo .Net object preloaded in the session.</p>
<p>The tip of the week page <a href="http://technet.microsoft.com/en-us/library/ff730954.aspx" title="http://technet.microsoft.com/en-us/library/ff730954.aspx" target="_blank">about Formatting Numbers and Dates Using the CultureInfo Object</a> has a link to the .net object <a href="http://msdn.microsoft.com/en-us/library/system.globalization.cultureinfo.aspx" title="http://msdn.microsoft.com/en-us/library/system.globalization.cultureinfo.aspx" target="_blank">system.globalization.cultureinfo</a>.</p>
<p>Here is how to use it<br />
<pre class="brush: powershell; light: true;">
[System.Globalization.CultureInfo](&quot;en-US&quot;)
# The object accepts also a decimal number or a decimal number written in hexadecimal:
[System.Globalization.CultureInfo](1033)
[System.Globalization.CultureInfo](0x409)
</pre></p>
<p>Now, I&#8217;ve just got to convert the system.string to either a decimal number or a decimal number written in hexadecimal like this:<br />
<pre class="brush: powershell; light: true;">
# Using decimal number written in hexadecimal
[System.Globalization.CultureInfo]([int](&quot;0x&quot; + (Get-WmiObject Win32_OperatingSystem).locale))
# Using a decimal number, i.e, a system.int32
[System.Globalization.CultureInfo]([Convert]::ToInt32((Get-WmiObject Win32_OperatingSystem).locale,16))
</pre></p>
<p>Here are additional pages that could be as well useful resources:</p>
<p>This great page speaks also about the system.globalization.cultureinfo and much more:<br />
<a href="http://powershell.com/cs/blogs/ebook/archive/2009/03/08/chapter-6-using-objects.aspx" title="http://powershell.com/cs/blogs/ebook/archive/2009/03/08/chapter-6-using-objects.aspx" target="_blank">http://powershell.com/cs/blogs/ebook/archive/2009/03/08/chapter-6-using-objects.aspx</a></p>
<p>This one shows how to <a href="http://powershell.com/cs/media/p/203.aspx" title="http://powershell.com/cs/media/p/203.aspx" target="_blank">Convert decimal to binary to hexadecimal and vice versa</a></p>
<p>This page explains precisely what <a href="http://msdn.microsoft.com/en-us/library/dd373814%28v=VS.85%29.aspx" title="http://msdn.microsoft.com/en-us/library/dd373814%28v=VS.85%29.aspx" target="_blank">Locale Names</a> are.</p>
<p>And finally this page shows the full list of hexadecimal values and their Locale ID displayname: <a href="http://msdn.microsoft.com/en-us/library/cc233968.aspx" title="http://msdn.microsoft.com/en-us/library/cc233968.aspx" target="_blank">http://msdn.microsoft.com/en-us/library/cc233968.aspx</a></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/p0w3rsh3ll.wordpress.com/112/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/p0w3rsh3ll.wordpress.com/112/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/p0w3rsh3ll.wordpress.com/112/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/p0w3rsh3ll.wordpress.com/112/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/p0w3rsh3ll.wordpress.com/112/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/p0w3rsh3ll.wordpress.com/112/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/p0w3rsh3ll.wordpress.com/112/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/p0w3rsh3ll.wordpress.com/112/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/p0w3rsh3ll.wordpress.com/112/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/p0w3rsh3ll.wordpress.com/112/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/p0w3rsh3ll.wordpress.com/112/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/p0w3rsh3ll.wordpress.com/112/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/p0w3rsh3ll.wordpress.com/112/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/p0w3rsh3ll.wordpress.com/112/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=p0w3rsh3ll.wordpress.com&amp;blog=31062221&amp;post=112&amp;subd=p0w3rsh3ll&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://p0w3rsh3ll.wordpress.com/2012/01/22/working-with-system-locale-and-user-locale/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/f416a6060a6e1cf59bd8b5618a4b1680?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">pwrshll</media:title>
		</media:content>

		<media:content url="http://p0w3rsh3ll.files.wordpress.com/2012/01/user-locale-01.png" medium="image">
			<media:title type="html">user locale</media:title>
		</media:content>
	</item>
		<item>
		<title>Get-SysinternalsTools</title>
		<link>http://p0w3rsh3ll.wordpress.com/2012/01/18/get-sysinternalstools/</link>
		<comments>http://p0w3rsh3ll.wordpress.com/2012/01/18/get-sysinternalstools/#comments</comments>
		<pubDate>Wed, 18 Jan 2012 20:18:41 +0000</pubDate>
		<dc:creator>_Emin_</dc:creator>
				<category><![CDATA[powershell]]></category>

		<guid isPermaLink="false">http://p0w3rsh3ll.wordpress.com/?p=86</guid>
		<description><![CDATA[I&#8217;ve read the following blog post about popular scripts http://blogs.technet.com/b/heyscriptingguy/archive/2012/01/03/top-ten-scripting-wife-blogs-of-2011-show-powershell-skills.aspx and decided last week-end to update my old down_sys.bat file. I used it to download all files from http://live.sysinternals.com using wget with proxy settings into a folder called live.sysinternals.com. It &#8230; <a href="http://p0w3rsh3ll.wordpress.com/2012/01/18/get-sysinternalstools/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=p0w3rsh3ll.wordpress.com&amp;blog=31062221&amp;post=86&amp;subd=p0w3rsh3ll&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve read the following blog post about popular scripts <a href="http://blogs.technet.com/b/heyscriptingguy/archive/2012/01/03/top-ten-scripting-wife-blogs-of-2011-show-powershell-skills.aspx" title=" http://blogs.technet.com/b/heyscriptingguy/archive/2012/01/03/top-ten-scripting-wife-blogs-of-2011-show-powershell-skills.aspx" target="_blank">http://blogs.technet.com/b/heyscriptingguy/archive/2012/01/03/top-ten-scripting-wife-blogs-of-2011-show-powershell-skills.aspx</a> and decided last week-end to update my old down_sys.bat file.<br />
I used it to download all files from <a href="http://live.sysinternals.com" title="http://live.sysinternals.com" target="_blank">http://live.sysinternals.com</a> using wget with proxy settings into a folder called live.sysinternals.com. It finally compares files in my current path and produces the following output.<br />
<img src="http://p0w3rsh3ll.files.wordpress.com/2012/01/old_download_sysinternals_tools_script.png?w=584" alt="old down_sys.bat file output" /><br />
Can&#8217;t wait any further, so here&#8217;s my version of Get-SysinternalsTools.ps1 that uses the same logic:</p>
<p><pre class="brush: powershell; light: true;">
#Requires -Version 3.0

&lt;#
    
.SYNOPSIS    
    Download sysinternals tools
   
.DESCRIPTION  
    Download all sysinternal tools to .\live.sysinternals.com directory and update previous files located in current path

.PARAMETER Proxy
    Set the proxy address to use to download
     
.NOTES    
    Name: Get-SysinternalsTools
    Author: Emin Atac
    DateCreated: 14/01/2012
     
.LINK    
    http://p0w3rsh3ll.wordpress.com
     
.EXAMPLE
    .\Get-SysinternalsTools
    Download all the sysinternals tools without a proxy

.EXAMPLE
    .\Get-SysinternalsTools -proxy &quot;http://my.internal.proxy.address&quot;
    Download all the sysinternals tools with a proxy

#&gt;

param
(
[parameter(Mandatory=$false)][System.URI]$Proxy=$null,
[parameter(Mandatory=$false)][System.Management.Automation.PSCredential]$ProxyCredential=$null
)
$otherparams = @{}
if ($proxy)
{
    $otherparams += @{Proxy = $Proxy}
    if ($ProxyCredential)
    {
       $otherparams += @{ProxyCredentials = $ProxyCredential}
    }
}

# Define the download URL
$URL = &quot;http://live.sysinternals.com&quot;

# Make sure we can download into the current path + the &quot;live.sysinternals.com&quot; directory 
$targetdir = Join-path -Path (Get-item $pwd) -ChildPath &quot;live.sysinternals.com&quot;
if (-not(Test-path -path $targetdir))
{
    # Create directory
    try
    {
        New-Item -Path $targetdir -itemtype directory -force -ErrorAction SilentlyContinue | Out-Null
    } 
    catch
    {
        Write-Host -ForegroundColor Red -Object (&quot;Error cannot create destination directory live.sysinternals.com into current path $pwd&quot;)
        exit 1
    }
}

# Make sure it is a directory
if ((Get-item -Path $targetdir) -isnot [System.IO.DirectoryInfo])
{
    Write-Host -ForegroundColor Red -Object (&quot;Oops, $targetdir exits but it is not a directory&quot;)
    exit 1
}

# Here we go: get all the links from the main page
try
{
    $wr = (Invoke-WebRequest -Uri $URL -ErrorAction SilentlyContinue @otherparams)
}
catch
{
    $_
    exit 1
}

$links = $wr.Links

# Cycle through all these links
foreach ($link in $links)
{
    # Show some progress activity as it can be quiet long...
    $i++
    Write-Progress -activity &quot;Dealing with link: $($link.href)&quot; -status &quot;Percent added: &quot; -PercentComplete (($i/$links.Count)*100)

    # Make sure we avoid directories and download a file
    if ($link.href -notmatch &quot;^/.*/$&quot;)
    {
        $content = $wrq = $null
        # Write-Host -ForegroundColor DarkCyan -Object (&quot;Downloading $($link.InnerText)&quot;)
        
        try
        {
            $wrq = (Invoke-WebRequest -Uri ($URL+$link.href) -Method GET -ErrorAction SilentlyContinue @otherparams)
        } 
        catch
        {
            # Write-Host -ForegroundColor Red -Object (&quot;Failed to download $($link.InnerText)&quot;)
        }
        
        if ($wrq.StatusCode -eq 200)
        {
            $content = $wrq.Content
            $encoding = $null
            # http://en.wikipedia.org/wiki/Mime_type
            # http://technet.microsoft.com/en-us/library/dd347719.aspx
            switch ($wrq.Headers['Content-Type'])
            {
                &quot;text/plain&quot;               { $encoding = [Microsoft.PowerShell.Commands.FileSystemCmdletProviderEncoding]::string  ; break }
                &quot;application/octet-stream&quot; { $encoding = [Microsoft.PowerShell.Commands.FileSystemCmdletProviderEncoding]::byte    ; break }
                default                    { $encoding = [Microsoft.PowerShell.Commands.FileSystemCmdletProviderEncoding]::unknown ; break }
            } # end of switch

            # Save the content that is a system.byte array to a file
            Set-content -value $content -encoding $encoding -path ($targetdir + $link.href)
        }
    }
}

# Now loop and let us know what file is being updated and those remaining identical
Get-ChildItem $targetdir | ForEach-Object {
    if (Test-path (Join-path -path (Get-item $targetdir).PSParentPath -ChildPath $_.Name))
    {
        $newfileversion = $_.VersionInfo.Fileversion
        $oldfileversion = (Get-item (Join-path -path (Get-item $targetdir).PSParentPath -ChildPath $_.Name)).VersionInfo.Fileversion

        if ($newfileversion -ne $oldfileversion)
        {
            Copy-Item -Path $_.Fullname -Destination (Get-item $targetdir).PSParentPath -Force # -Confirm:$true
            Write-Host -ForegroundColor Green -Object ($_.Name + &quot; updated from &quot; + $oldfileversion + &quot; -&gt; &quot; + $newfileversion)
        } else {
            Write-Host -ForegroundColor Green -Object ($_.Name + &quot; identical&quot;)
        }
    }
} # end of foreach
</pre></p>
<p>The interesting thing with this script is that we can see &#8220;nested&#8221; (let&#8217;s say more than 1) write-progress bars in the console output while it downloads files. Among other interesting things, you have the splatting technique to handle script arguments and the &#8216;[system.URI]&#8216; .net object being preserved that nicely handles the port specified in the URL.<br />
<img src="http://p0w3rsh3ll.files.wordpress.com/2012/01/system-uri.png?w=584" alt="system.URI" /></p>
<p>The following image shows the final output we get:<br />
<img src="http://p0w3rsh3ll.files.wordpress.com/2012/01/new_get-sysinternalstools_output.png?w=584" alt="get-sysinternalstools output" /></p>
<p>I&#8217;ve also left inside the script a link to the get-content cmdlet help page <a href="http://technet.microsoft.com/en-us/library/dd347719.aspx" title="http://technet.microsoft.com/en-us/library/dd347719.aspx" target="_blank"></a> where Joel -Jaykul- Bennett and Thomas Lee updated the documentation about the -encoding parameter of the set-content cmdlet. Jason Fossen also shows on this page how to use the set-content cmdlet with the -encoding parameter:<br />
<a href="http://www.sans.org/windows-security/2010/02/11/powershell-byte-array-hex-convert" title="http://www.sans.org/windows-security/2010/02/11/powershell-byte-array-hex-convert" target="_blank">http://www.sans.org/windows-security/2010/02/11/powershell-byte-array-hex-convert</a>.<br />
So let me say, Thank you guys <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> .</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/p0w3rsh3ll.wordpress.com/86/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/p0w3rsh3ll.wordpress.com/86/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/p0w3rsh3ll.wordpress.com/86/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/p0w3rsh3ll.wordpress.com/86/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/p0w3rsh3ll.wordpress.com/86/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/p0w3rsh3ll.wordpress.com/86/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/p0w3rsh3ll.wordpress.com/86/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/p0w3rsh3ll.wordpress.com/86/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/p0w3rsh3ll.wordpress.com/86/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/p0w3rsh3ll.wordpress.com/86/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/p0w3rsh3ll.wordpress.com/86/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/p0w3rsh3ll.wordpress.com/86/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/p0w3rsh3ll.wordpress.com/86/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/p0w3rsh3ll.wordpress.com/86/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=p0w3rsh3ll.wordpress.com&amp;blog=31062221&amp;post=86&amp;subd=p0w3rsh3ll&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://p0w3rsh3ll.wordpress.com/2012/01/18/get-sysinternalstools/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/f416a6060a6e1cf59bd8b5618a4b1680?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">pwrshll</media:title>
		</media:content>

		<media:content url="http://p0w3rsh3ll.files.wordpress.com/2012/01/old_download_sysinternals_tools_script.png" medium="image">
			<media:title type="html">old down_sys.bat file output</media:title>
		</media:content>

		<media:content url="http://p0w3rsh3ll.files.wordpress.com/2012/01/system-uri.png" medium="image">
			<media:title type="html">system.URI</media:title>
		</media:content>

		<media:content url="http://p0w3rsh3ll.files.wordpress.com/2012/01/new_get-sysinternalstools_output.png" medium="image">
			<media:title type="html">get-sysinternalstools output</media:title>
		</media:content>
	</item>
		<item>
		<title>Working with GPO and Applocker</title>
		<link>http://p0w3rsh3ll.wordpress.com/2012/01/14/working-with-gpo-and-applocker/</link>
		<comments>http://p0w3rsh3ll.wordpress.com/2012/01/14/working-with-gpo-and-applocker/#comments</comments>
		<pubDate>Sat, 14 Jan 2012 10:22:23 +0000</pubDate>
		<dc:creator>_Emin_</dc:creator>
				<category><![CDATA[powershell]]></category>

		<guid isPermaLink="false">http://p0w3rsh3ll.wordpress.com/?p=73</guid>
		<description><![CDATA[The other day I was asked to provide all certificate based applocker rules. Actually, it turned out that the Group Policy that targets only active directory computer objects has some security permissions that prevents domain users from reading it. I&#8217;ve &#8230; <a href="http://p0w3rsh3ll.wordpress.com/2012/01/14/working-with-gpo-and-applocker/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=p0w3rsh3ll.wordpress.com&amp;blog=31062221&amp;post=73&amp;subd=p0w3rsh3ll&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>The other day I was asked to provide all certificate based applocker rules.<br />
Actually, it turned out that the Group Policy that targets only active directory computer objects has some security permissions that prevents domain users from reading it.</p>
<p>I&#8217;ve been able to figure out the above by counting the total number of GPO in the domain:<br />
<pre class="brush: powershell; light: true;">

Import-Module -Name &quot;GroupPolicy&quot;
Import-Module -Name &quot;Applocker&quot;

# Running as user who is not domain admin
(Get-GPO -All -Domain &quot;FQDN.of.my.domain&quot; ).Count
32

# Running as domain admin
(Get-GPO -All -Domain &quot;FQDN.of.my.domain&quot; ).Count
33
</pre></p>
<p>So, now that I know that I need to run powershell with domain admin credentials, I was able to export the settings of the GPO I was looking for. Here&#8217;s how I did it:</p>
<p><pre class="brush: powershell; light: true;">
# Read the GPO and store it as an XML object
$GPO = [xml](Get-AppLockerPolicy -Ldap (&quot;LDAP://&quot; + (Get-GPO -Name &quot;Computers Parameters&quot;).path) -Domain -XML

# Now, I can display only Publisher based rules for executables
($GPO.AppLockerPolicy.RuleCollection | Where-Object { $_.Type -eq &quot;Exe&quot;}).FilePublisherRule | ft -HideTableHeaders -AutoSize -Property Name,Action

</pre></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/p0w3rsh3ll.wordpress.com/73/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/p0w3rsh3ll.wordpress.com/73/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/p0w3rsh3ll.wordpress.com/73/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/p0w3rsh3ll.wordpress.com/73/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/p0w3rsh3ll.wordpress.com/73/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/p0w3rsh3ll.wordpress.com/73/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/p0w3rsh3ll.wordpress.com/73/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/p0w3rsh3ll.wordpress.com/73/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/p0w3rsh3ll.wordpress.com/73/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/p0w3rsh3ll.wordpress.com/73/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/p0w3rsh3ll.wordpress.com/73/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/p0w3rsh3ll.wordpress.com/73/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/p0w3rsh3ll.wordpress.com/73/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/p0w3rsh3ll.wordpress.com/73/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=p0w3rsh3ll.wordpress.com&amp;blog=31062221&amp;post=73&amp;subd=p0w3rsh3ll&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://p0w3rsh3ll.wordpress.com/2012/01/14/working-with-gpo-and-applocker/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/f416a6060a6e1cf59bd8b5618a4b1680?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">pwrshll</media:title>
		</media:content>
	</item>
	</channel>
</rss>
