Showing posts with label Powershell. Show all posts
Showing posts with label Powershell. Show all posts

Tuesday, January 5, 2016

Office365 Dynamic Distribution Group creation with Multiple Custom Attributes

Dynamic distribution groups are mail-enabled Active Directory group objects that are created to expedite the mass sending of email messages and other information within a Microsoft Exchange organization.
Unlike regular distribution groups that contain a defined set of members, the membership list for dynamic distribution groups is calculated each time a message is sent to the group, based on the filters and conditions that you define. When an email message is sent to a dynamic distribution group, it’s delivered to all recipients in the organization that match the criteria defined for that group.

Use Case

Using Office356 Admin GUI you can create a multiple conditions in custom attribute to filter the AD group objects









Solution
Here you will find a PowerShell script functions code snippet example how to achieve this


 $name - string object your group name

$custom - string object with values separated by semicolon ";" "Test1; Test2; Test2" 

log - is a function for logging messages, you will need to implement it by yourself

function CreateDynamicDistributionGroup($name, $custom)
{
      log("Creating Dynamic distributiongroup " + $name)
      $result = $false;
      $custom = $null
     
    try{
        $results = Get-DynamicDistributionGroup -Identity $name -ErrorAction SilentlyContinue

        if($results -eq $null)
        {
            # Create new DynamicDistributionGroup
            $displayName = $name
            $alias = CreateFriendlyAlias($name)

                  $custom= FormatDynamicPropertyArray($custom)
                  $result = New-DynamicDistributionGroup -Name $name -Alias $alias -IncludedRecipients "MailboxUsers"

            $result = Set-DynamicDistributionGroup -Identity $alias -ManagedBy $appSettings["DefaultDistributionGroupOwner"] -Notes $notes
                  $result = Set-DynamicDistributionGroup -Identity $alias -IncludedRecipients "MailboxUsers" -ConditionalCustomAttribute1 $custom

            $result = $true
        }
        else
        {
            log("DistributionGroup " + $name + " already exist")
        }
    }
    catch [Exception]{
        log("Error creating distributiongroup " + $name + " Technical error: " + $_.Exception.Message)
    }

    return $result
}

function FormatDynamicPropertyArray($value)
{
      $newValueArray = @();

    if($value)
    {
          $values = $value -split ";"

              $values | ForEach-Object{
                        $newValueArray += $_.ToString()
            }
    }

      return $newValueArray

}

Have a good day! :)

Tuesday, July 21, 2015

SharePoint Online site recycle bin report by user name and items count deleted by that user


Hi,

here you will find a Powershell Script created by me to scan SharePoint Online site Recycle Bin. The script runs throught the all deleted items, sorts received item collection by deleted date using Merge sort algorithm and return items count and user names which were deleted by the user in period your entered when you requested.

For sorting items I have used the powershell scripts created by James Keeler

The powershell script can be found here:


Have a good time, J

Good luck.

Monday, June 30, 2014

Setting up App domain for SharePoint 2013 using PowerShell

Hello everybody,

Today we will prepare our SharePoint 2013 development environment to deploy app to your local machine.

So if you have a clean Virtual Environment with Windows Server 2008 R2 dacacenter, SQL 2008 R3, SharePoint 2013 instance, as I do, I suppose after that you have installed also Visual Studio 2012.

After that you opened your VS2012, made a new SharePoint Provider-hosted app and tried to deploy you got an error below, as I did, then you will need to set up App domain for SharePoint 2013:



Problem

  @"Error 1

        CorrelationId: c81cc07a-7b17-4714-b831-8d5e8507d53a

        ErrorDetail: Apps are disabled on this site.

        ErrorType: Configuration

        ErrorTypeName: Configuration

        ExceptionMessage: Microsoft.SharePoint.SPException: Apps cannot be installed. Review the diagnostic logs for more details regarding app deployment failures.

   at Microsoft.SharePoint.Utilities.SPUtility.ThrowSPExceptionWithTraceTag(UInt32 tagId, ULSCat traceCategory, String resourceId, Object[] resourceArgs)

   at Microsoft.SharePoint.Packaging.SPUserCodeSolutionDeploymentGroup.Deploy()

   at Microsoft.SharePoint.Administration.SPAppTask.DeployOperation()

   at Microsoft.SharePoint.Lifecycle.MonitoredTaskExecution.DoTask()

        Source: AppWeb

        SourceName: App Web Deployment

Error occurred in deployment step 'Install app for SharePoint': Failed to install app for SharePoint. Please see the output window for details.

If you look in ULS log and find the correlation ID you will see the followoing message:

Returning error with exception information. Type: Configuration, Source: AppWeb, Detail: Apps are disabled on this site., Correlation: c81cc07a-7b17-4714-b831-8d5e8507d53a, Exception: Microsoft.SharePoint.SPException: Apps cannot be installed. 



Solution






Set-SPAppDomain "greatsolution.com"


$cred = Get-Credential
$account = New-SPManagedAccount -Credential $cred
$appPoolSubSvc = New-SPServiceApplicationPool -Name SettingsServiceAppPool -Account $account
$appPoolAppSvc = New-SPServiceApplicationPool -Name AppServiceAppPool -Account $account
$appSubSvc = New-SPSubscriptionSettingsServiceApplication –ApplicationPool $appPoolSubSvc –Name SettingsServiceApp –DatabaseName SettingsServiceDB
$proxySubSvc = New-SPSubscriptionSettingsServiceApplicationProxy –ServiceApplication $appSubSvc
$appAppSvc = New-SPAppManagementServiceApplication -ApplicationPool $appPoolAppSvc -Name AppServiceApp -DatabaseName AppServiceDB
$proxyAppSvc = New-SPAppManagementServiceApplicationProxy -ServiceApplication $appAppSvc
Set-SPAppSiteSubscriptionName -Name "app" -Confirm:$false



Now you can deploy you APP

NOTE: You can only deploy apps for SharePoint from Visual Studio 2012 to a Developer Site.

Add your isolated app domain to your bypass list in Internet Explorer

1.      In Internet Explorer, go to Tools.
2.      Choose Internet options.
3.      On the Connections tab, choose the LAN Settings button.
4.      Clear the Automatically detect settings check box.
5.      Select the Use a proxy server for your LAN check box.
6.      Choose the Advanced button, and then add *.YourAppDomain.com to the Exceptions list.
7.      Choose the OK button.
8.      Choose the OK button to close the Local Area Network (LAN) Settings dialog box.
9.      Choose the OK button to close the Internet Options dialog box.


URL to microsoft site :


Have a good day!!!! :)