Tuesday, 26 April 2016

JetBrains dotMemory not attaching = reload .NET perf counters

If you get an issue using dotMemory where it wont connect to the profiler, then run the following two commands from a .net command prompt…
unlodctr .NETFramework
lodctr C:\Windows\Inf\.NETFramework\corperfmonsymbols.ini

Friday, 22 January 2016

Wednesday, 13 January 2016

Extract job titles from AD using powershell

For a given list of userids in a file called users.txt use the following powershell command in the same directory


Get-Content users.txt | foreach {Get-ADUser -Identity $PSItem -Properties mail,title | select -Property mail, title} |Export-Csv users.csv

Or use this to find new starters in the organisation...

$lastWeek = (get-date).AddDays(-31);

Get-ADUser -Filter "Description -like 'London'"  -Properties Name, Title, Manager, whenCreated, DistinguishedName, LastLogonDate | ? whenCreated  -gt $lastWeek | select Name, Title, Manager, whenCreated, DistinguishedName, LastLogonDate | fl

Note: For windows 7 desktop users you’ll need to install the active directory modules for powershell by following the installation steps here
https://www.microsoft.com/en-gb/download/details.aspx?id=7887
For all active directory attributes / propery names, see this link here
http://www.kouti.com/tables/userattributes.htm
Another way to have done it would have been usng SQL via a linked server
https://www.mssqltips.com/sqlservertip/2580/querying-active-directory-data-from-sql-server/
e.g.
SELECT     *
FROM OPENQUERY( ADSI,
    'SELECT samaccountname, mail, title, sn
     FROM ''LDAP://dc=companyname,dc=com''
     WHERE objectCategory = ''Person'' AND objectClass= ''user''
     AND userprincipalname = ''*'' AND mail = ''*'' AND SN = ''*''
         ORDER BY useraccountcontrol
      ')
      Where
      samaccountname= ‘myaccountloginname’

Wednesday, 6 January 2016

Powershell cruise control build output parser

<#
.Synopsis
   Write-XmlPathOutput processes all files in a directory for a given XPath expression and puts the results to .txt files of the same name
.EXAMPLE
   Write-XmlPathOutput -DirectoryPath DirectoryPath -XPath //*/project
.INPUTS
   DirectoryPath - the path to the directory
   XPath - the xpath you wish to use
.OUTPUTS
   .txt text files in the same directory
#>
function Write-XmlPathOutput
{
    [CmdletBinding(DefaultParameterSetName='Parameter Set 1',
                  SupportsShouldProcess=$false,
                  PositionalBinding=$false,
                  HelpUri = 'http://merrickchaffer.blogspot.com/',
                  ConfirmImpact='Medium')]
    [OutputType([String])]
    Param
    (
        # Param1 help description
        [Parameter(Mandatory=$true,
                   ValueFromPipeline=$true,
                   ValueFromPipelineByPropertyName=$true,
                   ValueFromRemainingArguments=$false,
                   Position=0,
                   ParameterSetName='Parameter Set 1')]
        [ValidateNotNull()]
        [Alias("p")]
        [String]
        $DirectoryPath = (Get-Location).Path,

        # xpath help description
        [Parameter(Mandatory=$false, ParameterSetName='Parameter Set 1', Position=1,
                    ValueFromPipeline=$true,
                   ValueFromPipelineByPropertyName=$true,
                   ValueFromRemainingArguments=$false )]
        [Alias("x")]
        [String]
        $XPath = "//*/project/@file"

    )

    Begin
    {
    }
    Process
    {
        if ($pscmdlet.ShouldProcess("Target", "Operation"))
        {
            $files = Get-ChildItem (Get-ChildItem $DirectoryPath\*.xml)
            if ($files -ne $null -and $files.Length -gt 0) {
               
                ForEach ($file in $files) {
                 
                  $OutFile = [string]::Concat($file.FullName, ".txt")
                 
                  Select-Xml -Path $file.FullName -XPath $XPath | Select -ExpandProperty Node | Out-File $OutFile

                }
            }

        }
    }
    End
    {
    }
}

Write-XmlPathOutput -DirectoryPath C:\temp -XPath "//*/project/@file"

Thursday, 31 December 2015

Great electrician

Spoke with these guys yesterday on their day off
http://www.checkatrade.com/RKBuilders/
image
and they still gave me great advice which helped me with some light fitting that I had spent the morning struggling with.
Can thoroughly recommend their services. Father and son team, and I spoke to the son, who really knew his stuff when it came to GU10 halogen downlight bayonet fitting.