Showing posts with label Atomia Automation Server. Show all posts
Showing posts with label Atomia Automation Server. Show all posts

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()