mandag den 10. oktober 2011

Working with SuperOffice though PowerShell

This powershell snap in is not meant to be a complete SuperOffice client, but for most basic stuff you can use this. Like say, you want to run a batch job everyday to update/sync information's from anther system and SuperOffice

working with powershell makes a lot of things a lot easier. Lets have a look at a few examples

First lets connect to SuperOffice. If you have the superoffice.config from your client laying around somewhere you can easily connect using that.

$module = Get-Module | where {$_.name -eq 'wingu.SuperOffice.SnapIn'}
if($module -eq $null){
$module = Get-Module -ListAvailable | where {$_.name -eq 'wingu.SuperOffice.SnapIn'}
if($module){ import-module wingu.SuperOffice.SnapIn }
}

$config = Get-SO7config c:\superoffice.config | Set-SO7config
$config.Username = $config.Explicit.DBUser
$config.Password = $config.Explicit.DBPassword

So, just to validate everything is working, lets get the license information
$LicenseInfo = Get-SO7LicenseInfo
# To replace running license use
#
Set-SO7LicenseInfo -CompanyName 'Happy Ducks Holding ApS' -SerialNumber '1234'
#
To Update current license. ( like if you buy more user licenses )
#
Set-SO7LicenseInfo $LicenseInfo

To see what credentials is associated with alz@sotest1.local and if he is logged on right now, you could so something like this


Get-SO7Person -email alz@sotest1.local | Get-SO7Credentials

Or to have a loot at who is using SuperOffice right now
Get-SO7Credentials | where {$_.CredentialType -eq 'Ticket' }

( this will not be accurate, since cleanup of ticket’s is only done when a user logs in. but still … )

Do you want a list of Persons asscociated with Contact ‘hestehøj a/s’ ?


Get-SO7Contact 'Hestejøj AS' | Get-SO7Person

Want to create a new Associate, with AD login ?


$logonName = 'alz'
$upn = 'alz@sotest1.local'
$FirstName = 'Allan'
$Lastname = 'Zimmermann'

# Get Associate if exists
$CRM7User = Get-SO7Associate -logonName $logonName -ea 0
# Get Person with email corrosonding to upn, if exists
$CRM7Person = Get-SO7Person -email $upn -ea 0
if((!$CRM7User) -and (!$CRM7Person)){
# could not find a person nor Associate so create both
$CRM7User = New-SO7Associate -FirstName $FirstName -Lastname $Lastname -logonName $logonName -Email $upn -AdUser
$CRM7User = Get-SO7Associate -logonName $logonName -ea 0
$CRM7Person = Get-SO7Person -email $upn -ea 0
}
if((!$CRM7User) -and ($CRM7Person)){
# Person exists, but have no Associate so create it and link to person
$CRM7User = New-SO7Associate -person $CRM7Person -logonName $logonName -Email $upn -AdUser
$CRM7User = Get-SO7Associate -logonName $logonName -ea 0
}
# Assign a UserLicense, allow login, and enable Windows/web
$CRM7User | Enable-SO7Associate

Or, create with a CRM5 password (not ad login) ?
$logonName = 'alz'
$upn = 'alz@sotest1.local'
$FirstName = 'Allan'
$Lastname = 'Zimmermann'
$Password = 'Passw0rd'

# Get Associate if exists
$CRM7User = Get-SO7Associate -logonName $logonName -ea 0
# Get Person with email corrosonding to upn, if exists
$CRM7Person = Get-SO7Person -email $upn -ea 0
if((!$CRM7User) -and (!$CRM7Person)){
# could not find a person nor Associate so create both
$CRM7User = New-SO7Associate -FirstName $FirstName -Lastname $Lastname -logonName $logonName -Email $upn -Password $Password
$CRM7User = Get-SO7Associate -logonName $logonName -ea 0
$CRM7Person = Get-SO7Person -email $upn -ea 0
}
if((!$CRM7User) -and ($CRM7Person)){
# Person exists, but have no Associate so create it and link to person
$CRM7User = New-SO7Associate -person $CRM7Person -logonName $logonName -Email $upn -Password $Password
$CRM7User = Get-SO7Associate -logonName $logonName -ea 0
}
# Assign a UserLicense, allow login, and enable Windows/web
$CRM7User | Enable-SO7Associate

anyway, here is a complete list of commands.
Get-Command -Module wingu.SuperOffice.SnapIn


Close-SO7Session
Decrypt-SO7H
Disable-SO7Associate
Enable-SO7Associate
Encrypt-SO7H
Get-MySO7Identity
Get-SO7Associate
Get-SO7Business
Get-SO7config
Get-SO7Contact
Get-SO7Country
Get-SO7Credentials
Get-SO7Email
Get-SO7LicenseInfo
Get-SO7Person
Get-SO7Secret
Get-SO7SystemInfo
New-SmartProcess
New-SO7Associate
New-SO7Business
New-SO7Contact
New-SO7Credentials
New-SO7Person
Remove-SO7Associate
Remove-SO7Business
Remove-SO7config
Remove-SO7Contact
Remove-SO7Credentials
Remove-SO7Email
Remove-SO7Person
Save-SO7config
Set-SO7config
Set-SO7LicenseInfo
Set-SO7Person


Ingen kommentarer:

Send en kommentar