Friday, November 30, 2018

PowerShell Script to get list of Office 365 Groups

PowerShell script to get list of Office 365 Groups within your Tenant

$creds = Get-Credential
Write-Host "--- Connecting to Exchange Online Service"
$ExchOnlineSession= New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $Creds -Authentication Basic -AllowRedirection
Import-PSSession $ExchOnlineSession
write-host "--- Exchange Session Imported successfully"
Get-UnifiedGroup | Select-Object DisplayName,ManagedBy,AccessType | Export-Csv -Path "Office365Groups.csv"

You must be a Office 365 global administrator to run the cmdlet.

The Get-Credential cmdlet creates a credential object for a specified user name and password.
The New-PSSession cmdlet creates a PowerShell session (PSSession) on a local or remote computer.
The Get-UnifiedGroup cmdlet to view Office 365 Groups in your cloud-based organization. To view members, owners and subscribers for Office 365 Groups

PowerShell Script to update Site Collection Storage Quota

PowerShell Script to update SharePoint Online Site Collection Storage Quota

The Connect-SPOService cmdlet connects a SharePoint Online global administrator to the SharePoint Online Administration Center.

You must be a SharePoint Online global administrator and a site collection administrator to run the cmdlet.

Connect-SPOService -Url https://yourcompanyname-admin.sharepoint.com -credential admin@yourcompanyname.com

The Set-SPOSite cmdlet sets or updates one or more properties' values for a site collection.

Set-SPOSite -Identity https://yourcompanyname.sharepoint.com/sites/TestSiteCollection -ResourceQuota 300 -StorageQuota 10000

updates the settings of site collection https://yourcompanyname.sharepoint.com/sites/TestSiteCollection The storage quota is updated to 10000 megabytes and the resource quota is updated to 300 megabytes.

Wednesday, December 21, 2016

SharePoint Online Site External Users Report

Please use this below script to extract SharePoint Online Site External Users to an CSV file.

Get-SPOExternalUser -SiteUrl "Your Site Name" -Position 0 -PageSize 50 |Select-Object DisplayName,Email,WhenCreated,AcceptedAs,InvitedBy |Export-Csv -Path f:\script\externusers.csv -Encoding ascii


Monday, February 29, 2016

Export SharePoint List items to CSV file and then Upload to SharePoint Document Library



We have SharePoint list that has more than 5000 list items and we need to export the list to CSV file and then upload to SharePoint document Library, delete the list items that are already exported.

Here is the PowerShell Script to Export SharePoint List items to CSV file and then Upload to SharePoint Document Library



Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

###########################Variables######################################
$smtpServer = "mail.yourcompany.com"  
$fromadd = "Fromaddress@yourcompany.com" 
$email1 = "toaddress@yourcompany.com"
$sitepath= "SharePoint Site Path"
$listname = "List Name"
$timer = (Get-Date -Format yyy-mm-dd-hhmmss_)
$exportfilepath="File Path \"+ $timer + "FileName.txt"
$doclibname ="Document Library Name"

#####################################################################################
##      Step 1- Export SharePoint List
#####################################################################################

$web = Get-SPWeb -identity $sitepath
$list = $web.Lists[$listname]
$ListItemCollection = @()
$spQuery = new-object Microsoft.SharePoint.SPQuery
 $camlQuery =
 "<Where>
   <Eq>
    <FieldRef Name='STATUS' />
      <Value Type='Choice'>Shipped</Value>
   </Eq>
 </Where>"
$spQuery.Query = $camlQuery
$list.GetItems($spQuery)  |  foreach {
$ExportItem = New-Object PSObject
$ExportItem | Add-Member -MemberType NoteProperty -name “ID” -value $_[“ID”]
$ExportItem | Add-Member -MemberType NoteProperty -name "UK" -value $_["UK"]
$ListItemCollection += $ExportItem
}
$ListItemCollection | Export-CSV $exportfilepath -NoTypeInformation

#####################################################################################
##      Step 2- Upload the file to SharePoint document Library
#####################################################################################

# Get a variable that points to the folder
$dlist = $web.GetFolder($doclibname)
$files = $dlist.Files

# Get just the name of the file from the whole path
$filename = $exportfilepath.Substring($exportfilepath.LastIndexOf("\")+1)

# Load the file into a variable
$file= Get-ChildItem $exportfilepath

# Upload it to SharePoint
$Files.Add($doclibname +"/" + $filename,$file.OpenRead(),$false)
#####################################################################################
##      Step 3- Delete the sales order backlog list itme that is exproted
#####################################################################################

Import-CSV $exportfilepath -Header ID,UK | Foreach-Object{
   
    $items = $list.Items | Where {$_[“ID”] -eq $_.ID}
    foreach($item in $items)
    {
        $item.Delete();
        break;
    }
}
$web.Dispose()
#####################################################################################
if ($error -ne $null)
{
$msg = new-object Net.Mail.MailMessage
$smtp = new-object Net.Mail.SmtpClient($smtpServer)
$msg.From = $fromadd
$msg.To.Add($email1)
$msg.Subject = "Exporting list error"
$msg.Body = $error
$smtp.Send($msg)
$error.clear()
exit
}