PowerShell

Tech Short: “execution of scripts is disabled on this system.”

Attempting to run a PowerShell script I got the following error:

File C:\Work\ps.ps1 cannot be loaded because running scripts is disabled on this system. For more information, see about_Execution_Policies at http://go.microsoft.com/fwlink/?LinkID=135170.
+ CategoryInfo : SecurityError: (:) [], ParentContainsErrorRecordException
+ FullyQualifiedErrorId : UnauthorizedAccess

To run PowerShell scripts (files that end with .ps1), you must set the execution policy to Unrestricted. This is done by issuing the following command in powersehll

*note* you need to do this in a elevated powershell (run it as administrator)

Once you do that, Windows will allow you to execute any .ps1 file.

 

PowerShell for Office 365

Hiya; Have you moved into Office 365? Oh you did!

Then you are already aware of all the fun things you can do and some of the ones you can’t without the use of powershell commands

Thankfully Microsoft and the Office 365 team have released a new site titled PowerShell for Office 365 which targets Office 365 IT administrator who is new to PowerShell.

They get you started by having you download the right tools to your local computer. Here is a list for starters.

  • Download Microsoft Online Services Sign-in Assistant to sign into Office 365.
  • Download Azure Active Directory (AD) Module so that you can perform administrative tasks in Office 365.
  • Download SharePoint Online Module so that you can manage SharePoint Online.
  • Download Skype for Business Online Module so that you can manage Skype for Business Online.

So go have a look and happy learning and Administration of Office 365

For more info: http://powershell.office.com/

 

Renaming SharePoint 2013 Server

I spent sometime today renaming SharePoint 2013 Servers for a project I was pulled in on. It involved using PowerShell cmdlets and other administrative tasks.

The project required me to “Clone” SharePoint farm servers to make template environments for demonstration and development task.

I originally followed steps provided here: Renaming SharePoint then later streamlined the process so its something I found useful. Here are my notes saved in PowerShell format so it could be run step by step using PowerShell ISE:

 

Best,

Jermal

Power Off & On VMware Guest with a Scheduled Task

 

Using Windows task scheduler you can schedule power off and on events for guest systems running in VMware vCenter or a standalone ESXi host.

My steps:

  1. Create a basic task – give it a name and description (optional)
  2. Choose when you want this task to stat
  3. Select the start date and time
  4. Choose “Start a program”
  5. Choose the program you would like to run.  In this setup we will be running the following:
  6. C:\WINDOWS\system32\WindowsPowerShell\v1.0\powershell.exe -NoLogo -NonInteractive -File “C:\work\task\jermsmit.ps1”

     
  7. Click Next, Select Yes when Task Scheduler prompts you
  8. On the Finish screen, click Finish  – You can open properties to set this to run unattended

 

The script I am now using does the following:

  1. Loads the VMware PowerCli modules to powershell
  2. Connects to Specified ESXi or vCenter Server
  3. Issues a stop to specific VM Guests
  4. Issues a start to the VM Guest

Script Example:

 

Use cases:

  1. Powering systems down to conserve energy (earth day initiative)
  2. Allow for systems with large workloads to have full system resources without contention during scheduled down periods of the systems that are offline.
  3. Quick restore of nonpersistant environments

 

Thanks for visiting – jermal

Tech Short: PowerShell to list users in AD security group

You want to get a list of users who exist as members of a AD (Active Directory) security group. Here are some quick steps on accomplishing this task.

Lets begin:

  1. Open PowerShell or PowerShell ISE
  2. Type Import-Module ActiveDirectory
  3. Followed by Get-ADGroupMember -identity “Group Name” | select name | Out-GridView

And there you go, fast and simple to do.

 

Tech Short: Stop and Start Lync Services On A Server

How can I take on this task, let me count the ways…

After installing a new certificate on our Lync server I needed to restart the services to complete the change.  I was able to do this with two powershell commands.

Stop Services

Start Services

 

Office 365: Initiate a full password sync using DirSync

Having a need to rapidly sync passwords to Office 365 using Directly Sync (DirSync) I come across the following method that seems to work with minimal effort.  By default the DirSync only kicks off ever 3-5 min’s.

To initiate a full password sync you can do the following:

  1. Open PowerShell, and then type:

     
  2.  Then Type:

     
  3. Press Enter
  4. Load Services.msc
  5. Restart the Forefront Identity Manager Synchronization Service Service. (FIMSynchronizationService)

In your application event logs you should notices multiple events  of 656 (Password Sync Requests) and Even 657 (Password Sync Results) indicating that your full password sync has kicked off.

 

Office365: Using PowerShell to get Office365 license info

Working to apply bulk apply licenses I stumbled upon some useful commands to list the licenses assigned to my Office 365 Account.

The following command will list account Sku ID’s along with the active and consumed units. Best of all list them in a nice grid view

We can also pull the subset of information such as items include with pack we have.

The following command will list included service plans under our package

 

Office 365: Convert Mailbox to Shared Mailbox after Cutover Migration

When performing a cut-over migration the Exchange attribute indicating that the mailbox was a shared mailbox is lost. To correct this I have done the following steps:

List out all of the shared mailboxes form my on-premises Exchange and export them into a CSV file.

Now prepare the CSV file with the list of user principal names of all mailboxes to be converted. Make sure the column header for the user principal names is “UserPrincipalName”

Now we run the following powershell script to change the mailbox type of all items in the CSV file.

Please note

Running Exchange Online Powershell commands / scripts requires you have had installed the Microsoft Online Service Sign-In Assistant, Windows Powershell, Windows Azure Active Directory Powershell

For more info:

http://www.microsoft.com/en-us/download/details.aspx?id=41950

http://jermsmit.com/azure-active-directory-module-for-windows-powershell-how-to-connect/

 

Tech Short: Office365 – Convert select on-premises mailboxes to mail-enabled users

When you convert on-premises mailboxes to mail-enabled users (MEUs), the proxy addresses and other information from the Office 365 mailboxes are copied to the MEUs, which reside in Active Directory in your on-premises organization. These MEU properties enable the Directory Synchronization tool, to match each MEU with its corresponding cloud mailbox.

Using the steps provided here I was able to export a list of only user mailboxes and leaving out other mailbox types

Run the following PowerShell command:

The following full steps of what to do next can be found here: http://community.office365.com/en-us/w/exchange/835.cutover-exchange-migration-and-single-sign-on.aspx