Showing posts with label Power Shell. Show all posts
Showing posts with label Power Shell. Show all posts

Most used PowerShell admin tasks in SharePoint Online

In this article we can see most used PowerShell tasks based on the requirements in SharePoint online.

How to provide site collection admin access?

Set-SPOUser -site  https://sr7yn.sharepoint.com/sites/TestPublic -LoginName $SiteCollectionAdmin -IsSiteCollectionAdmin $True


How to enable and disable custom scripting?

Set-SPOSite  https://sr7yn.sharepoint.com/sites/TestPublic -DenyAddAndCustomizePages $False


How to enable external sharing?

Set-SPOSite -Identity  https://sr7yn.sharepoint.com/sites/TestPublic -SharingCapability ExternalUserSharingOnly


How to remove external user from admin centre?

$ExternalUserEmail = "Phani_xyz.onmicrosoft.com#EXT#@abc.onmicrosoft.com"

$ExternalUser = Get-SPOExternalUser -filter $ExternalUserEmail

Remove-SPOExternalUser -UniqueIDs @($ExternalUser.UniqueId) -Confirm:$false


How to lock the site in SharePoint site?

Set-SPOSite -Identity https://sr7yn.sharepoint.com/sites/TestPublic -LockState ReadOnly

Set-SPOSite -Identity https://sr7yn.sharepoint.com/sites/TestPublic -LockState unlock


cannot be loaded because running scripts is disabled on this system

cannot be loaded because running scripts is disabled on this system.


When we are trying to run the script from Power Shell ISE , we got this error message as per the below screen shot


Issue Description:

File C:\Users\Raavi\Documents\CreateFolders.ps1 cannot be loaded because running scripts is disabled on this system. For more information, see

about_Execution_Policies at https:/go.microsoft.com/fwlink/?LinkID=135170.

    + CategoryInfo          : SecurityError: (:) [], ParentContainsErrorRecordException

    + FullyQualifiedErrorId : UnauthorizedAccess


Solution : This issue will happened when running script is disabled in our machine , to run the script 

Opened PowerShell ISE and ran this command 

Get-ExecutionPolicy

we can see the status as per the below 



Run this command this will allow us to run the scripts 

set-ExecutionPolicy RemoteSigned -Scope CurrentUser

After clicking on Yes  ,  we can again check the status Get-ExecutionPolicy



Now we are getting status as RemoteSigned , able to run scripts successfully.

Hope this will helps!!  

Enable app catalog at site collection level using PowerShell

Enable app catalog at site collection level using PowerShell

Enable app catalog at site collection level using PowerShell. 

In SharePoint Online we can deploy apps, SPX solutions based on our requirement to appcatalog at site collection, once we deployed at app catalog site collection solution will be available for all site collections and developers need to contact admins to deploys apps multiple times this will impact on project deliverable’s. 
To avoid this, we can enable app catalog at site collection level itself using PowerShell. 
To deploy apps at site collection level we need to enable app catalog at site collection level using PowerShell, for enabling we should require Tenant admin access (For me it is working fine with SharePoint Admin access) and to deploy apps required site collection admin access. 


To enable App catalog for multiple site collections based on our Input file. Create a CSV file  as per the below format . 

SiteURL 

https://dotnetsharepoint.sharepoint.com/sites/Site1 
https://dotnetsharepoint.sharepoint.com/sites/Site2 
https://dotnetsharepoint.sharepoint.com/sites/Site3
 

 Code  

 # SharePoint Admin URl 
$AdminURL = "https://dotnetsharepoint-admin.sharepoint.com" 
 $Cred = Get-Credential 
 #Connect to SharePoint Online 
Connect-SPOService -Url $AdminURL -Credential $Cred 
 #sites from csv 
$sites = Import-Csv -Path "D:\SitesInput.csv" 
 #Get sites one by one 
foreach($row in $sites) 
{ 
     $site = Get-SPOSite -Identity $row.SiteURL 
    $sitecollURL = $site.Url  
     Add-SPOSiteCollectionAppCatalog-Site$sitecollURL 
    Write-Host $sitecollURL 
  }  
 
 
 

New-SPConfigurationDatabase : The user does not exist or is not unique

When we are trying to install SharePoint 2016 using PowerShell we got the below error.
“New-SPConfigurationDatabase : The user does not exist or is not unique ” as per the below screen we face the issue.
Resolution: Make sure once you run this command in the PowerShell credential popup window will come.

New-SPConfigurationDatabase –DatabaseName SharePoint_Config –DatabaseServer DNSP2016 –AdministrationContentDatabaseName SharePoint_Content –Passphrase (ConvertTo-SecureString DotNetSharePoint2016–AsPlaintext –Force) –FarmCredentials (Get-Credential) -localserverrole SingleServerFarm

We have to enter MachineName\UserName  as per the above screen shot.

Monitoring disk space utilization using powershell

Monitoring disk space utilization is an important task in SharePoint to avoid the critical issues , we can implemented this using PowerShell to monitor the disk utilization , in this we did not kept any threshold conditions , we are generating only report in CSV format with list of all servers available  in our  environment.
We created a config file to add all servers that you want to know the disk space utilization.
Added the server names as per the below screen shot in the text file.


Please note: we are generating this only in CSV format, it is a plane text we cannot add any colors in our output file.

Add-PSSnapin microsoft.sharepoint.powershell
$resultsarray = @()
$computers = (Get-Content "d:\Allservers.txt")
$date = Get-Date -Format “dd-MM-yyyy”
foreach($computer in $computers)
{
if([string]::isnullorwhitespace($computer))
{
}
else
{
Write-Host $computer
 $drives = Get-WmiObject -ComputerName $computer Win32_LogicalDisk | Where-Object {$_.DriveType -eq 3}
 foreach($drive in $drives)
 {
  $contactObject = new-object PSObject
   $id = $drive.DeviceID
 $totalsize = [math]::round($drive.Size /1GB, 2)
 $freespace = [math]::round($drive.FreeSpace  / 1GB, 2)
 $usedspace= $totalsize-$freespace
 $freeprecent = [math]::round($freespace / $totalsize, 2) * 100
 $diskObject | add-member -membertype NoteProperty -name "Date" -Value $date
 $diskObject | add-member -membertype NoteProperty -name "Server Name" -Value $computer
 $diskObject | add-member -membertype NoteProperty -name "Drive" -Value $id
  $diskObject | add-member -membertype NoteProperty -name "Total GB" -Value  $totalsize     
   $diskObject | add-member -membertype NoteProperty -name "Used GB" -Value $usedspace   
 $diskObject | add-member -membertype NoteProperty -name "Free GB" -Value $freespace  
    $diskObject | add-member -membertype NoteProperty -name "% Free" -Value $freeprecent  
$resultsarray += $diskObject
}
}
}
$resultsarray| Export-csv -path "D:\diskreport_$date.csv" –notypeinformation

Delete SharePoint list items based on particular view using PowerShell


Send email to members of SharePoint Group using PowerShell

In this article we can see how to send email only from a particular group of people using power shell, it is very easy to user to remove/add new users whenever they want. In the below code we created a SharePoint Group with name “DotNetSharePoint”

add-pssnapin microsoft.sharepoint.powershell
$web = get-spweb -identity  "http://dotnetsharepoint.com/sites/SharePoint2013/BusinessUsers"
$groupss = $web.Groups.GetByName("DotNetSharePoint")
$emailgrouptoo =@()
foreach($user in $groupss.Users)
{
$sendemailto  =  $user.Email
$totalemail =  $sendemailto
  $emailgrouptoo+=$totalemail
 }
#You can also get this below information from Custom List also , in the article we are mainly showing how to send email to Owners Group Using PowerShell.
$smtpserver = "yourSMTP severname"
$emailfrm  =  "emailidfrom whom you have to send this email"
$Subject =  "We are sending email to Users"
$EmailBody  = "You type some information which you want to show in side the email body"
 send-mailmessage -smtpserver $smtpserver -from $emailfrm -to $emailgrouptoo  -subject $Subject -body $EmailBody

Delete SharePoint list items based on particular view using PowerShell

In this article you can able to see how to delete  SharePoint list items based on the particular view and also having another condition how have to delete items on every Monday, we created a couple of views what type of data have to delete based on item created date.
One view is used to delete SharePoint list items every day and another delete only on Monday.

Note:  by default list item limit is 30 items, we have to modify the view based on the requirement I change to 5000 so every day it will delete only 5000 items to delete.

add-pssnapin microsoft.sharepoint.powershell
$web = get-spweb -identity "http://dotnetsharepoint.com/sites/sharepoint/deleteitems"
$MainList = $web.lists["DeleteListItems"];
$today = (get-date).DayOfWeek
if($today -eq "Monday")
{
$view = $MainList.Views["DeleteMondaylistitems"];
}   
else
{
$view = $MainList.Views["DeleteEverydaylistitems"];
}
$items = $MainList.GetItems($view)
$totalcount = $items.Count
$j = 0;
for($i = $totalcount -1; $i -ge 0; $i--)
{
$deleteitem = $items[$i]
write-host $deleteitem.ID
$deleteitem.Delete()
}

Who Created Site Collection using PowerShell

In this article we can able to see who created the site collection with username and time using PowerShell.

In our environment we are having so many site collection, due to some reasons we need to know who created the site collection and when he created the site with data and time information.

The below PowerShell Script is very useful to get the basic information who created the site collection.

add-pssnapin microsoft.sharepoint.powershell
$site = Get-SPSite http://dotnetsharepoint.com/
$site.RootWeb.Author
$site.RootWeb.Created

SharePoint Online Real Time Training Contact: JLAKSHMITULASI@GMAIL.COM

Who created list in SharePoint using PowerShell

In this article we can learn, who created the list with name and date using PowerShell.


This script is very useful to know who created the list with created username and created date with time in any environment like Dev, QA and Prod using PowerShell.
Here we are having a list someone created long time back but as of now we don’t know who created this list, using below PowerShell script we can get it easily.

Add-PSSnapin microsoft.sharepoint.powershell
$web = Get-SPWeb "http://dotnetsharepoint.com/sites/sharepoint"
$list = $web.lists["listname"]
$listwhocreated = $list.Author
$listcreateddate = $list.Created
Write-Host "Created User Name:" $listwhocreated
Write-Host "Created Date:" $listcreateddate


SharePoint Online Real Time Training Contact: JLAKSHMITULASI@GMAIL.COM

Import and Export document library in SharePoint PowerShell

In this article we can able to see how to export and import document library using PowerShell, here we need to get all version document modified history and including users.

Now using the below script we are exporting in to our local D drive.

Export-SPWeb http://dotsharepoint.com/sites/SP/Documentsite/ –Path "D:\Documents.cmp" -ItemURL "Shared%20Documents" –IncludeUserSecurity  -IncludeVersions All

Now using the below script we are importing to another SharePoint site

Export-SPWeb http://dotsharepoint.com/sites/SPSite/NewDocuments/ –Path "D:\Documents.cmp" – force  –IncludeUserSecurity



SharePoint Online Real Time Training Contact: JLAKSHMITULASI@GMAIL.COM

How to get field empty values in SharePoint using PowerShell

In this article we can able to see how to get the empty values in a field with count using PowerShell
We are having list with more than 10k items in that we are have a field with Status, now we have to know for this particular filed having empty values.

Add-PSSnapin microsoft.sharepoint.powershell
$web = Get-SPWeb http://dotnetsharepoint.com/sites/sharepoint
$list = $web.lists["ListName"] 
  $i = 0;
write-host $list
$items = $list.items
 #Go through all items
foreach($item in $items)
{
 $mystring = $item["Status"]
IF([string]::IsNullOrEmpty($mystring))
{
write-host  $item.ID
$i = $i+1
}
 }

Write-host "total final items" $i

SharePoint Online Real Time Training Contact: JLAKSHMITULASI@GMAIL.COM

Copy data from one list to another list in SharePoint using PowerShell

In this article we are copying values from one list to another list in SharePoint using PowerShell
In both list having field “uniqueid” , using the “uniqueid” only I am updating values from LISTB to LISTA. In LISTB having more fields we need to copy the value from LISTB to LISTA , using camel query we are getting the value from LISTA in to this variable “$item['uniqueid']” and in FieldRef Name  we have to give the LISTB  field name.
Below is the script to update the items.

Add-PSSnapin Microsoft.sharepoint.powershell
      $web =  Get-SPWeb "http://dotnetsharepoint.com /sites/sharepoint/"
      write-host $web
    $Source =$web.Lists["LISTA"]           
     $Dest = $web.lists["LISTB”]
     write-host = $Source
     Write-host = $Dest
                            
    $items = $Source.items
    foreach ($item in $items) {
  
      $camlQuery ="<Where><Eq><FieldRef Name='uniqueid' /><Value Type='Text'>"+$item['uniqueid']+"</Value></Eq></Where>"
        $spQuery = new-object Microsoft.SharePoint.SPQuery
        $spQuery.Query = $camlQuery
        $spQuery.RowLimit = 1
        #check if the item is already present in destination list
         $ditems =  $Dest.GetItems($spQuery)
             $item["UserName"] = $ditems[0]["UserName"] 
 $modifiedBy = $item["Editor"]
$modifieddate =$item["Modified"]
Write-Host $item.ID
$item["Editor"] = $modifiedBy
$item["Modified"] = $modifieddate
$item.Update()
$Source.Update()
#Write-Host $count+1
        }

SharePoint Online Real Time Training Contact: JLAKSHMITULASI@GMAIL.COM

Labels

.Net Interview Questions add custom button in sharepoint using javascript Add custom column property into a PageLayout in SharePoint Add Page Title on their browser's title bar in SharePoint Customly add zip files in blogger Add-SPOSiteCollectionAppCatalog : Must have Manage Web Site permissions or be a tenant admin in order to add or remove sites from the site collection app catalog allow list Advance SmartObject An error occurred while accessing the resources required to serve this request. The server may not be configured for access to the requested URL. Angular 2 Angular JS Angularjs Angularjs 1 anonymous users accessing lists and libraries App Permissions for SharePoint 2013 asp.net membership unique email Asp.net TreeView Control asp.net. Attendees in SharePoint Auto refresh list using Content Editor WebPart in SharePoint 2013. Auto Refresh SharePoint list using JavaScript Block and unblock of attachment types in SharePoint Blogger C# Callouts in SharePoint 2013 Cascading Dropdown list in SharePoint change onenote to another location. change SuiteBarLeft in SharePoint 2013 check if userid exists in database c# click node text to expand/collapse in Treeview client object model Close webpart CQWP crate chart using BI site in PPS Create a modern team site collection in SharePoint online Create BI chart in PPS SharePoint 2013 create filter in dashboard designer. create kpi's in dashboard designer create kpi's in SharePoint 2013 dashboard designer Create List Create List In SharePoint Create List using Power Shell Script Create Lookup Field in List using Power Shell Script Create lookup field in List create SharePoint List custom view. create SharePoint List views in List Schema create site collection in site collection in SharePoint using powershell created Date Time calculated field in SharePoint Cross site Collection in SharePoint 2013 Crud Operation in Asp.net Using Stored Procedure Custom MasterPage Approval in SharePoint custom view for survey list Customly add SharePoint List view in Page. delete items in sharepoint using powershell Difference between Angular 1.x & Angular 2 difference between Office 365 and Windows Azure difference between Windows Azure and Office 365 in sharepoint? DifferenceBetween discussion board Display Data in Grid View display radio buttons and choice fields horizontally in SharePoint 2013 Document library DotNet Drag and drop documents in document library in SharePoint dynamically populating values from one list to another list using jquery in sharepoint edit and delete buttons in datagridview Edit Links email notification using Nintex enable anonymous access in SharePoint 2013 enable app catalog sharepoint online site collection powershell Enable appcatalog site collection level using PowerShell based on Input file Enable versions for list and library except the hidden lists using PowerShell Script Error occurred in deployment step 'Recycle IIS Application Pool': Cannot resolve model for the project package Errors&Solutions Export document library in sharepoint using powershell Export particular Group in Term Store Management in SharePoint 2013 Export to Excel first release Flow Flow features free disk space on servers using powershell Friendly URLs and Managed Navigation in SharePoint 2013 get a list of site collection with template in web application using PowerShell Script in SharePoint Get attachments in SharePoint custom list using c# get current list item id sharepoint programmatically Get current url using jquery Get data from SharePoint list using Rest api & Angular JS Get Random Get Random SharePoint items using PowerShell Get Random values from SharePoint list using PowerShell Get url of the last value using jquery Get-SPOSite : The managed path sites/yoursitename is not a managed path in this tenant. Getting Email From User Hide “Edit Links” in left navigation SharePoint 2013 hide button in sharepoint based on permissions Hide column in SharePoint List view hide fields using client side object model Hide list in Quick Launch in SharePoint using PowerShell How to add Custom Tiles to SharePoint site Page. How to add extension files in Search Navigation in SharePoint 2013 How to Add Multiple users Using SharePoint People Picker How to add SharePoint list view in Page using C# How to Approve MasterPage using PowerShell in SharePoint How to bind Multiple users Using SharePoint People Picker how to change indicators on kpi performance how to check if an email address already exists in the database in asp.net how to configure workflow manager platform for SharePoint 2013 how to create calculated value using powershell how to create certificate in SharePoint How to create flow. how to create gantt chart webpart in sharepoint how to create KPI indicators in Dashboard designer How to create moden communication site in SharePoint online How to create Multi selected filter in Dashboard How to create nintex workflow in sharepoint how to create rdlc reports in asp.net How to Display Data Grid View in ASP.net How to enable anonymous access in SharePoint How to find data in datagridview in c# How to get image names from the folder using C# how to get particular list content type id in SharePoint 2013 How to get QueryString value in SharePoint WebPart Programatically how to get the current item id for newly created item using REST API and JQuery how to hide list in sharepoint how to know who created list in sharepoint How to make a Site Collection Read-Only in SharePoint 2010 How to overlay Office 365 shared calendar on SharePoint Site how to pass jquery value to asp.net textbox control How to pass pagename as a browser's title bar in the page how to remove unused Application Pool in SharePoint how to remove zone using powershell script How to send mail to particular group of people using PowerShell how to update modified by and created by using powershell how to uplaod RAR files in blogger import csv data into sharepoint import data using powershell Import group to term store management using SharePoint 2013. InfoPath InfoPath Cascading Dropdown list Insert update delete in datagridview in C# winforms Integration from SharePoint to k2. K2 Smart Forms for SharePoint JavaScript Injection jquery JSON K2 blackpearl K2 Designer K2 Designer Workflow. K2 smartform cascading dropdown list k2 Workflow K2 workflow to send a mail with PDF left navigation Local Term Set in managed meta data Managed meta data navigation in SharePoint 2013 Managed metadata service in SharePoint 2013. Managed Navigation in SharePoint 2013. Managed Promoted Sites. meta data navigation Microsoft Flow New Features New-SPConfigurationDatabase The user does not exist or is not unique NintexWorkFlow Office 365 OneDrive OneNote overwrite existing document in sharepoint using javascript PDF Converter PDF Method in K2 Performance Point Service in SharePoint 2013 PerformancePoint Services Configurtion PerformancePoint Services Configurtion for SharePoint 2013 PerformancePoint Services in SharePoint Server 2013 Popularity trends in SharePoint 2013 Pages populate dropdown list dynamicallyusing jquery Power Power Automate Power Shell Power shell script to get SharePoint site size. PowerApps powershell read xml PowerShell Script PowerShell script to get list of users from SharePoint groups PowerShell Scripts in SharePoint 2013 Powershell to set the masterpage in SharePoint Promoted Links Promoted Sites psconfig.exe quick launch Rdlc reports Readonly Column in SharePoint Editview Realtime DotNet Interview Questions Recent Dotnet interview questions Recent SharePoint interview questions recover deleted OneNote page. OneNote content is missing Regional Settings in SharePoint 2013 Replace New Item text in SharePoint Rest API Schedule PowerShell Script Search in SharePoint 2013 Search navigation in SharePoint 2013 Secure store service SecureStore Services SecureStore Services configuration for SharePoint 2013 self-signed certificate on IIS Server Send email to members of SharePoint Group using PowerShell sharepint2010 sharepoin2010 SharePoint 2013 SharePoint 2010 SharePoint 2013 SharePoint 2013 Dashboard Designer SharePoint 2013 features SharePoint 2013 Interview Questions SharePoint 2013. SharePoint 2013.disable views from user to create SharePoint 2013.Power shell SharePoint 2013.SharePoint 2010 SharePoint 2016 SharePoint Administration SharePoint Alerts and Reminders SharePoint App Configuration SharePoint Apps SharePoint Bulk upload SharePoint Calculated field SharePoint Calendar View sharepoint interview questions SharePoint online interview questions SharePoint online training SharePoint Onprem vs Online SharePoint RealTime Online Training SharePoint2010 SharePoint2013 SharePoint2016 SharePointInterview SharePointOnline SharePointOnline;Restore deleted site;SharePoint 2013 show data in datagridview in C# Simple Insert update Delete Retrieve Clear in asp.net. Site Collection Operations in SharePoint 2013 Site Collection Read-Only in SharePoint 2013 site contents Sorting & Filtering SPO SPSite Site Collection Operation parameters in SharePoint 2013 Step by step to create rdlc report in .Net Store names in text files in C# Sub site Subsite Term store management. The server was unable to save the form at this time. please try again UI New look update created by using client side object model update field values in SharePoint using powershell update items in SharePoint list using client object model update modified by field using client side object model upload zip files in blog use IsNullOrEmpty in PowerShell VirtoSoftware VirtoSofware vitrosoftware WebParts what is Document Set in SharePoint 2010 What is Filter in SharePoint Dashboard what is Limited-access user permission lock down mode feature What is Modern Team site What is Target Audience in SharePoint Who Created Site Using PowerShell Workflow in SharePoint 2013 Workflow management platform in SharePoint 2013 Workflow manager for SharePoint 2013 XSL-Template.