PowerShell

Error: Setting up PowerShell Remoting

In an attempt to connect to a remote Hyper-V host I needed to enable PowerShell Remoting.

To enable this you simple run PowerShell as Administrator and issue the following command:

The command runs and then errors with the following output:

PS C:\WINDOWS\system32> Enable-PSRemoting

WinRM has been updated to receive requests.
WinRM service type changed successfully.
WinRM service started.

Set-WSManQuickConfig : <f:WSManFault xmlns:f=”http://schemas.microsoft.com/wbem/wsman/1/wsmanfault” Code=”2150859113″ Machine=”localhost”><f:Message><f:ProviderFault
provider=”Config provider” path=”%systemroot%\system32\WsmSvc.dll”><f:WSManFault xmlns:f=”http://schemas.microsoft.com/wbem/wsman/1/wsmanfault” Code=”2150859113″
Machine=”workstation.jermsmit.com”><f:Message>WinRM firewall exception will not work since one of the network connection types on this machine is set to Public. Change
the network connection type to either Domain or Private and try again. </f:Message></f:WSManFault></f:ProviderFault></f:Message></f:WSManFault>
At line:116 char:17
+ Set-WSManQuickConfig -force
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [Set-WSManQuickConfig], InvalidOperationException
+ FullyQualifiedErrorId : WsManError,Microsoft.WSMan.Management.SetWSManQuickConfigCommand

To correct this I opened another PowerShell window, also running as Administrator issue the following command to change each of the network interfaces to be private.

 

At this point I was able to run the Enable-PSRemoting without error

PS C:\WINDOWS\system32> Enable-PSRemoting
WinRM is already set up to receive requests on this computer.
WinRM has been updated for remote management.
Created a WinRM listener on HTTP://* to accept WS-Man requests to any IP on this machine.
WinRM firewall exception enabled.

 

TechShort: PowerShell to Setup VPN Connections

Here is a way we can be consistent with our setup of VPN connections on computers.

Using PowerShell this is made simple with a small script on a USB stick, network share or whatever method you choose to get the to the client machine

The following is a one line PowerShell command:

Next is to see if this can be placed in a group policy to have it automated on end user computers

I hope this helps your process of machine setups.

– Jermal

Ref: https://technet.microsoft.com/en-us/%5Clibrary/JJ554820(v=WPS.630).aspx

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