Tag PowerShell

Connect to Exchange Online with PowerShell

Install Exchange Online PowerShell Module Open Internet Explorer or Edge. (If you are using the Chromium version of Edge you will need to enable Edge OneClick [chrome://flags/#edge-click-once]). Other browsers are not supported. Go to or your local exchange server,…

Restore deleted files from SharePoint Online

The easiest way to restore files in SharePoint Online is obviously just to restore the deleted files using the web interface as Microsoft recommends. However, that won’t work if you need to restore 1000-plus files. Basically, the restore process will just get stuck, and you will probably die of age before anything happens. 💀 PowerShell to the rescue! 🦸‍♂️ Install the SharePoint Patterns and Practices (PnP) cmdlet Connect to the SharePoint site Notice the sites/rooms in the URL. You need to connect to an actual site on your SharePoint, not just the root of the site. In other words, you need to know from which site the files were deleted from. List all deleted items in the site “rooms” List all items deleted by a specific user Restore all files deleted by a specific user The restore process will take a while. In my case, I restored about 1000 files in about 20 minutes. Note that you will not get a restore log, but you can of course use the above command to check if files disappear from the recycle bin. If files exist on the server you will get error messages, which is fine. This just means that the deleted file already exists, or a newer file exists. Sources: Restore Recycle bin SharePoint Online with PowerShell

Export local Active Directory information with PowerShell

Need to get a list of users in your domain? Or perhaps an inventory list of computers, or security groups? PowerShell is your friend! 🤝 Requirements and installation For first time and one-time setup you need to do the following: Download Remote Server Administration Tools for Windows 10 from Microsoft and install it. Make sure you choose the one appropriate for your operating system. In Windows run OptionalFeatures.exe and turn on Remote Server Administration Tools. In PowerShell you will have to run Import-Module ActiveDirectory. Usage Here are some common use cases. If you want more you can check out the official documentation. Export all users in AD with all attributes to a csv file. Make sure you Set-Location -Path or cd to the export path first. Export users of a specific organizational unit: If your domain is adatum.local then you should write DC=adatum,DC=local. For some strange reason the list of OU’s and DCs must be listed in a reverse order like this: But we could make it tidier by setting the list of OU and DC as variables. We can also make a variable with attributes. This makes it easier to change or adapt the script to different tasks. Export users that are actually human employees A lot of times you might have some service-accounts, test accounts or similar. If you just want to export a list of actual employees you can filter the results by using any attribute such as the employee number or employeeID. Get all disabled users that have an employee number Export memberships of users with employee number Find all employees with employee number and export their respective memberships to individual text files. Export all attributes of users with employee number Find all employees with employee number and export their all their respective attributes to individual […]

Windows 10 language settings with PowerShell

Language settings in Windows 10 is a little more complicated than just setting the display language and keyboard input. Let me explain further. Region settings The region settings control a number of things. If you change the language here, you will also change “cultural” properties such as date format, currency, number formatting and so on. These settings are linked together with the region language. That means you can’t have English display language and Danish currency and time format. Because if you change the region to English you will also get English cultural settings. 😲 Stupid right? Note: this behavior may have changed in Windows 10 1903, but I have not tested this thoroughly. This is super frustrating for those who would like to have Windows in English, but different region settings. The solution is a simple PowerShell command: As the documentation says, this disables the action of dynamically setting the “culture” for the current user based on changes to the Windows display language. So now you can set the region in one of two ways. You can either set the region with the cmdlet: or you can edit the region language in Control Panel – > Region. Display language and keyboard language In Windows 10 there is also something called “language lists“. Languages in Windows 10 can be a little more complicated than just setting the right display language and keyboard language. I mean, if you think about it… Switzerland, for example, has four national languages; German, French, Italian and Romansh. People living in the cities Canton of Valais, Fribourg, and Bern are bilingual (speaking French and German), while Canton Graubünden is trilingual (German, Romansh and Italian). So what language settings would you use in Switzerland? My point here is that although you may have one main language, you might […]

Remove automapping for a shared mailbox in Office 365

In short, there is no simple way to remove automapping from a shared mailbox in Office 365 unfortunately. But there is a more tedious way 😉 First remove the user from the mailbox, then re-add the user without automapping enabled. Fire up PowerShell and connect to your Office 365 tenant with: Remove the user from the shared mailbox delegation: Remove-MailboxPermission -Identity shared.mail@example.com -User user.mail@example.com -AccessRights FullAccess Then add the user to the shared mailbox delegation again, without automapping: Add-MailboxPermission -Identity shared.mail@example.com -User user.mail@example.com -AccessRight FullAccess -InheritanceType All -Automapping $false If you need to give the user send as permission too you can do: Sources: https://support.microsoft.com/en-us/help/2646504/how-to-remove-automapping-for-a-shared-mailbox-in-office-365