Posts tagged "powershell"

Add new email alias Office365

One of our customers changed the company name. So the alias of all there SharedMailboxes on office365 needed to be changed. This script below contains 2 functions, the fist one is for adding an extra alias to the mailbox and the second one is for activating the new alias. This is the first time i scripted against office365, so it could be that the script is not faultyproof. But hey, its a beginning. Saved about 10 hours of manual clicking during the critical company name change.

 

Dynamic Group population and Role based Access PowerShell

For a customer i created a script which create new groups for all kind of unique jobtitles available in Active Directory. After the creation of all groups it loops through all users and add these to the created groups in the function above. This scripts help you to maintain for example role base access.

This scripts contains 3 functions:
1. Creating groups for all the unique jobtitle’s available.
2. Adding users with the same Jobtitle
3. Remove users after jobtitle change

 

 

Windows 10 Start menu search is not working

I had the annoying issue that my Windows 10 Search bar stops working for some reason. Trying to restart the services, restart Windows and kill the Cortana processes doesn’t work in my situation. After a lot of searching, I’ve found the solution in some forum.

The solution: Re-register Cortana with PowerShell.
Run PowerShell as administrator and past the following line:

 

 

Invoke-WebRequest : The response content cannot be parsed because the Internet Explorer engine is not available

Yesterday I was facing this error when running a SMA Runbook with the invoke-webrequest cmdlet. For troubleshooting I had to enable SMA script logging for this runbook so I was able to see wats going wrong. The error says you must run the “getting started setup” of internet explorer for the service account which is running the scripts.

 

This is not ideally when you run this script on multiple servers. Now there are 2 options available to ignore this stupid error:

1. Enable the Group policy object (GPO) for Prevent running first run wizard. This setting is in “Computer configuration -> Policies -> Administrative templates -> Windows Components -> Internet Explorer”. Set the “Prevent running first run wizard” to enabled.

2. Run the Invoke-webrequest with the –UseBasicParsing CMDlet.

 

 

PowerShell: The specified string is not in the form required for a subject

During the creation of a PowerShell SMA Runbook I was getting the following error message. This error appear when sending an automatic mail message with the send-mailmessage cmdlet. It only happens when the subject is filled with a String parameter which contains invalid characters.

After two hours of troubleshooting I formatted the string with the following regex which worked in my case:

 

 

Get PowerShell version

Sometimes you need to check the PowerShell version of your Windows System, to get the PowerShell version you need to open a PowerShell prompt (taskbar type PowerShell).

This information is contained in the following variable:

Will give you the exact version.
Other commands which can be used are:

 

Delete VM From VMM Database

Firtst, try to remove the VM with the VMM Powershell module:

If this was not succesvol you can try this:
This is a sweaty hand job, but in most cases succesful..

On your VMM Management server, stop VMM Management service and VMM Agent.
Login to your SQL Management Studio and start a Query against your VirtualManagerDB.
First search for the ID, the Spooky VM have:

After you get the ID, past this ID in the following 3 sections of code in the GUID section:

 

MSMQ errors in ClusterLog

What is MSMQ:

You can use MSMQ for Application communication across heterogeneous networks and systems that may be temporarily offline. Applications send messages to queues and read messages from queues. A queue is a temporary storage location from which messages can be sent and received reliably, as and when conditions permit. This enables communication across networks and between computers, running Windows, which may not always be connected.

When MSMQ is not enabled or not configured you get a lots of errors in your Windows Cluster log.
In our Hyper-v cluster we don’t need MSMQ.

Errors we faced:

ERR   [RHS] s_RhsRpcCreateResType: (21)’ because of ‘Startup routine for ResType MSMQTriggers returned 21.’
INFO  [RCM] result of first load attempt for type MSMQTriggers: 21
WARN  [RCM] Failed to load restype ‘MSMQTriggers’: error 21.

If you don’t use MSMQ you can disable it with the following PowerShell commands:

 

Hyper-v VM migration with VMM Powershell

Somethimes you need to bulk migrate some Hyper-v virtual machines.
This is not possible with the VMM gui.

In this situation PowerShell can help:
Filter on VMname

Replace the $VM line when you need to migrate all the machines placed on a specified host:

 

 

 

 

List all Hyper-v snapshots with the VMM PowerShell Module

There is no place where you can find an overview from all Hyper-v snapshots in the VMM Gui.
In this situation PowerShell is your friend. With a few lines of PowerShell code is this overview simple to make.

Run this commands in an elevated PowerShell  prompt where you installed the VMM Console: