Monday, December 19, 2011

Powershell and Atomia Automation Server


First you need to create class library for CoreApiBasicAuth endpoint (use http://rkeithhill.wordpress.com/2006/11/08/calling-a-wcf-service-from-powershell/ as a help how to do this)

Using this library (for example CoreApiBasicAuth.dll) you can connect to Atomia Automation Server. In following example I created powershell script to list Windows Websites for specific account.


[Reflection.Assembly]::LoadFrom("c:\CoreApiBasicAuth.dll")
$wsHttpBinding = new-object System.ServiceModel.BasicHttpBinding
$wsHttpBinding.Security.Message.ClientCredentialType = [System.ServiceModel.BasicHttpMessageCredentialType]::UserName
$wsHttpBinding.Security.Mode = [System.ServiceModel.BasicHttpSecurityMode]::TransportWithMessageCredential
$endpoint = new-object System.ServiceModel.EndpointAddress("https://provisioning.test.com/CoreAPIBasicAuth.svc")

$coreAPI = new-object CoreApiClient($wsHttpBinding, $endpoint)
$coreAPI.ClientCredentials.UserName.set_UserName("Admin")
$coreAPI.ClientCredentials.UserName.set_Password("Admin")

$Acc = $coreAPI.GetAccount("123456")

#find websites for this account
$pageInfo = New-Object Atomia.Provisioning.Base.PagingInfo 
$strNames = @("CsWindowsWebsite")
$pageInfo.PageSize = 10
$pageInfo.PageNumber = 0
$res = $coreAPI.FindServicesByNamesForAccount($Acc.AccountId, $strNames, [ref] $pageInfo)
$sites = $res | ForEach-Object {$_.properties} | Where-Object {$_.Name -eq "Hostname"} | Select-Object propStringValue
Write-Output $sites

$coreAPI.Close()




Wednesday, November 23, 2011

Using powershell to get IIS worker process

Preparation:
  • Enable execution of powershell scripts with command:
 Set-ExecutionPolicy RemoteSigned
  • Import module for IIS
  import-module webadministration


Now you should be able to see new drive (IIS)

  get-psdrive


Now, to see worker process for specific pool you only need to execute:


   dir 'IIS:\AppPools\myAppPoolName\WorkerProcesses'

To list all process IDs use:


   dir IIS:\AppPools | Get-ChildItem | Get-ChildItem | Format-Table -AutoSize  processId, appPoolName








Wednesday, September 07, 2011

Export Certificates using Powershell

dir cert:\LocalMachine\My | Where-Object { $_.hasPrivateKey } | Foreach-Object { [system.IO.file]::WriteAllBytes("$home\$($_.SubjectName).pfx", ($_.Export('PFX', '')) ) }

Free partition magic tool

Thursday, September 01, 2011

Convert amr file to mp3

Some android applications may save audio files in amr format. To convert amr file to mp3 file you can use this tool

Monday, April 11, 2011

ID4175: The issuer of the security token was not recognized...

This error is thrown by sts.
Obviously, it is error in  this section:


<issuerNameRegistry type="Microsoft.IdentityModel.Tokens.ConfigurationBasedIssuerNameRegistry, Microsoft.IdentityModel, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35">
<trustedIssuers>
  <add name="CN = test" thumbprint="12 34 56 78 89 45 45 45 45 45 44 44 44" />
</trustedIssuers>
</issuerNameRegistry>

At first look thubprint of certificate was OK. But when I open it in hex editor there was some characters that was not visible in text editor. I fix this and everything was OK. :)

Tuesday, March 29, 2011

Flatten objects tree structure


Flatten objects tree structure:



protected IEnumerable<T> Flatten<T>(IEnumerable<T> elements, Func<T, IEnumerable<T>> childrenFunc)
        {
            List<T> result = new List<T>();
            result.AddRange(elements);
            
            IEnumerable<T> children = elements.SelectMany(childrenFunc);
            
            if (children.Count() == 0)
            {
                return result;
            }

            result.AddRange(this.Flatten<T>(children, childrenFunc));

            return result;
        }