Some thoughts on programming stuff

Tag: Powershell

Export list in SharePoint via PowerShell

SharePoint lists are very powerful and we often need to export list data for our customers. One of the best option to achieve that is by PowerShell. So in this blog post we will cover how to export list in SharePoint via PowerShell. After exported to CSV, it’s easy to convert to an Excel format and do whatever you want. It’s important to say that this script will work on SharePoint Server On-Premises and you will need to enter the server to run it.

But why using a PowerShell if we can do that by the UI? Well, I need to agree with you. What I can answer about that? Basically, you can schedule exporting activities, you can take leave the script running on long lists without short timeouts, etc.

A SharePoint list - Export list in SharePoint via PowerShell
A SharePoint list (PowerApps blog)
Continue reading

Test SharePoint e-mail settings with PowerShell

In case you want to test SharePoint e-mail settings with PowerShell, you can achieve that by sending a dummy e-mail to yourself by running a simple PowerShell script. In this way you can ensure your SMTP settings are good and all SharePoint notifications or coding solutions that send e-mails will work.

It’s important to test it during the configuration of a new Farm. The steps for configuring it can be found on Microsoft docs. Or maybe if you need to troubleshoot the e-mail features in your SharePoint solutions. SharePoint has many automated alerts that work with Workflows, Approval processes and Access control forms.

Electronic e-mail - Test SharePoint e-mail settings with PowerShell
E-mail is a common way to communicate and alert (Wikimedia Commons)

PowerShell script for testing SharePoint e-mail settings

The script is pretty straightforward and you will need to update just two lines. One with the right e-mail going to receive the message and the Site Collection URL that is going to trigger the message.

That’s it! I hope this script can help you when you want to test SharePoint e-mail settings with PowerShell. Also on creating new solutions for monitoring your e-mail settings on the SharePoint farms you happen to work with.

In addition to that, in case you are interested in, you can check other posts featuring PowerShell scripts.

References:
SharePoint diary

Restart Timer and Admin in SharePoint

SharePoint relies on Timer Service and Admin Service to run and manage its tasks. As any Windows Service, sometimes we need to stop and start them. That’s why I wrote this post to share a script on how to restart Timer and Admin in SharePoint.

These services are present in a SharePoint Server, inside the Windows Services list. There you can see both SharePoint Administration and SharePoint Timer Service:

  • The Admin Service performs administrative tasks for Windows Services under the Local Admin Network rights;
  • The Timer Service sends notifications and performs scheduled tasks for SharePoint services. It must run with an Account with Admin rights to server.
Timer and Admin Services - Restart Timer and Admin in SharePoint
Timer and Admin Services

Script to restart the timer and admin services

The script will load the SharePoint PowerShell dependencies and start by restarting the services in each machine present in the farm. This can throw an error if the Windows Servers are not properly configured to allow remote changes to their services.

Finally, in the end we use some objects provided by the SharePoint DLL to ensure that every Timer service is online and available.

There are other services required to run SharePoint, but it depends on how you are exploring its features. Here is the list of possible mandatory services that you may face and even restart if you want (haha):

  • SharePoint Tracing;
  • SharePoint User Code Host;
  • SharePoint VSS Writer;
  • World Wide Web Publishing Service;
  • SharePoint Server Search.

That’s it! I hope this post can be helpful when you want to restart Timer and Admin in SharePoint. Also you may find useful other posts related to PowerShell in the blog posts available.

References:
StackOverflow

Export user permissions in SharePoint

This post will present a Powershell script that will let you Export user permissions in SharePoint from all Web Applications and their Site Collections.

The script creates a CSV file and fills the data in the columns like below:

  • Site Name;
  • Site Url;
  • Name of the Group;
  • Login of the Group Owner;
  • Display name of the Group Owner;
  • User Login (who has the permission);
  • User Display Name (who has the permission);
  • The role or permission the user has.
Report after being exported (in Brazilian Portuguese) - Export user permissions in SharePoint
Report after being exported (in Brazilian Portuguese)
Continue reading

Change List Template language to reuse it in another Site with different language

When importing a list template from another Site or Site Collection built in a different language, you may not be able to see it as an App available to add to your site. It happens because SharePoint will look for the List Templates available in the current language for the Web Site. I’ve experienced it recently when migrating a list from a site collection in Portuguese to another site collection in Spanish, that’s why I decided to write this blog post that teaches how to change List Template language to reuse it in another Site with different language

In this post we will give you a PowerShell that may help you on migrating the list easily.

Continue reading

Export Workflow History to CSV in SharePoint

Sometimes you may need to export Workflow History to CSV in SharePoint, just because most of the history data is not available anymore in the Workflow History page of a document or item, thanks to the SharePoint Workflow Auto Cleanup that purges the data for performance purposes.

But what happens if someone is trying to make an audit review and cannot find the history for a specific document? Well… you can use this script!

Export Workflow History to CSV in SharePoint - Audit and reporting of document history
Audit and reporting of document history
Pxhere
Continue reading

Force Flush Blob Cache in SharePoint

If you need to force flush blob cache in SharePoint, this script is for you! It will ensure that every file once cache will be deleted and will force SharePoint on recreating it when it sometimes becomes corrupt.

After running this script, you will get back on track and the cache will be flushed. But be cautious! This script will only affect the server where it’s being executed. In cases where you have multiple web application servers working together, the script must be executed in each server. It is necessary because each server holds its personal folder where the assets will be stored and cached.

The Blob Cache is an important feature that must be used when you have heavy traffic with lots of anonymous users, or even if you need to explore Image Renditions (we have a blog post about some problems there too). You can find over the internet a lot of content about it, but I must say that exists some undocumented stuff about the topic that may have been lost in the history and it’s just present in some old books about SharePoint.

The Script to force flush Blob Cache

All the steps below are important to get things working again. Basically our script will delete the Folder where you have configured the Blob Cache to store the files, then we will call the Flush Blob Cache method offered by the SPWebApplication object from SharePoint. Finally, the iisreset is an important step because it will ensure that the everything is rewinded and refreshed.

That’s it! I hope this script can help you getting things on track, perfoming a force Flush Blob Cache in SharePoint and serving a good SharePoint Site with awesome performance to your users.

References:
Karine Bosch blog;
Microsoft documentation.

Repair Lookup column in SharePoint

Sometimes it’s necessary to repair Lookup column in SharePoint. Usually it can happen when we need to transport a list from a Production environment to a Development environment, just to reproduce some bug or situation with real world data. This is possible when you use the Save as Template feature, exporting it from an environment to another and then you recreate the list.

But, if you have Lookup fields it can give you some headaches. As soon as the list is restored in the other environment, the Internal GUIDs will be changed forever and any connection to the source list of the lookup column will be lost!

But it’s important to emphasize that Lookup columns are great as Microsoft says that “You can create relationships between lists by using a combination of unique columns, lookup columns, and relationship enforcement (cascade and restrict delete), all of which enhance your ability to create more sophisticated business solutions and help preserve the integrity of your data.”.

Continue reading

Troubleshooting errors using PowerShell in SharePoint

Today I would like to share with you an useful script to help on troubleshooting errors using PowerShell in SharePoint when some unexpected exception happens . This script can help you on tracing the exact cause of a bug in the application while relieving you from opening the entire log file and search for the error message in a not so productive way.

The SharePoint logs folder - Troubleshooting errors using Powershell in SharePoint
The SharePoint logs folder (Microsoft docs)

These logs are written by SharePoint and according to Microsoft, this is what you get from it:

“The Unified Logging Service (ULS) is the service that is responsible for keeping an eye on SharePoint and reporting what it finds. It can report events to three different locations:

  • SharePoint trace logs
  • Windows Event Log
  • SharePoint logging database

Where the event is logged (and if it’s logged at all) depends on the type of event, as well as how SharePoint is configured. The ULS is a passive service, which means that it only watches SharePoint and reports on it; it never acts on what it sees.”

Continue reading

© 2024 wiliammbr's blog

Theme by Anders NorenUp ↑