08 September 2017

Install-Module - unable to resolve package source 'https //www.powershellgallery.com/api/v2/'

Trying to install a PowerShell module behind a proxy?
Chances are you're getting this error:

unable to resolve package source 'https://www.powershellgallery.com/api/v2/'

Turns out it isn't allowed through your proxy server, run this in your PowerShell session and try again:

$webclient=New-Object System.Net.WebClient
$webclient.Proxy.Credentials = [System.Net.CredentialCache]::DefaultNetworkCredentials
[Net.ServicePointManager]::SecurityProtocol = "tls12"

Now every command you run is sent and allowed through the proxy.

Exchange 2013 CU16 and CU17 failed cannot find path \V15\UnifiedMessaging\grammars because it does not exist

Weird, dumb, stupid, useless and above all irritating as hell.
Error messages that don't make any sense, and make total sense at the same time.
Like this one, it states that it cannot find the path to the folder "grammars" and errors out the installation of CU16 and CU17 in my case and fails.

After creating the folder "grammars" in the path C:\Program Files\Microsoft\Exchange Server\V15\UnifiedMessaging\ and restarting the CU installation everything went fine.


D:\Temp\cu16>setup.exe /mode:upgrade /iacceptexchangeserverlicenseterms

Microsoft Exchange Server 2013 Cumulative Update 16 Unattended Setup

Copying Files...
File copy complete. Setup will now collect additional information needed for
installation.
Mailbox role: Transport service
Client Access role: Front End Transport service
Mailbox role: Client Access service
Mailbox role: Unified Messaging service
Mailbox role: Mailbox service
Management tools
Client Access role: Client Access Front End service

Performing Microsoft Exchange Server Prerequisite Check

    Configuring Prerequisites                                 COMPLETED
    Prerequisite Analysis                                     COMPLETED

Configuring Microsoft Exchange Server

    Restoring Services                                        COMPLETED
    Mailbox role: Transport service                           COMPLETED
    Client Access role: Front End Transport service           COMPLETED
    Mailbox role: Client Access service                       COMPLETED
    Mailbox role: Unified Messaging service                   FAILED
     The following error was generated when "$error.Clear();
          $grammarPath = join-path $RoleInstallPath "UnifiedMessaging\grammars\*
";

          $dirs = get-item $grammarPath;

          foreach($d in $dirs)
          {
                  if($d -isnot [System.IO.DirectoryInfo])
                  {
                    continue;
                  }

            $path1 = $d.FullName + "\*";

            $items = get-item $path1 -include *.cfg;

            if($items -ne $null)
            {
              foreach($i in $items)
              {
                remove-item $i;
              }
            }
          }
        " was run: "System.Management.Automation.ItemNotFoundException: Cannot f
ind path 'C:\Program Files\Microsoft\Exchange Server\V15\UnifiedMessaging\gramma
rs' because it does not exist.
   at System.Management.Automation.LocationGlobber.ExpandMshGlobPath(String path
, Boolean allowNonexistingPaths, PSDriveInfo drive, ContainerCmdletProvider prov
ider, CmdletProviderContext context)
   at System.Management.Automation.LocationGlobber.ResolveDriveQualifiedPath(Str
ing path, CmdletProviderContext context, Boolean allowNonexistingPaths, CmdletPr
ovider& providerInstance)
   at System.Management.Automation.LocationGlobber.GetGlobbedMonadPathsFromMonad
Path(String path, Boolean allowNonexistingPaths, CmdletProviderContext context,
CmdletProvider& providerInstance)
   at System.Management.Automation.LocationGlobber.GetGlobbedProviderPathsFromMo
nadPath(String path, Boolean allowNonexistingPaths, CmdletProviderContext contex
t, ProviderInfo& provider, CmdletProvider& providerInstance)
   at System.Management.Automation.LocationGlobber.GetChildNamesInDir(String dir
, String leafElement, Boolean getAllContainers, CmdletProviderContext context, B
oolean dirIsProviderPath, PSDriveInfo drive, ContainerCmdletProvider provider, S
tring& modifiedDirPath)
   at System.Management.Automation.LocationGlobber.GenerateNewPSPathsWithGlobLea
f(StringCollection currentDirs, PSDriveInfo drive, String leafElement, Boolean i
sLastLeaf, ContainerCmdletProvider provider, CmdletProviderContext context)
   at System.Management.Automation.LocationGlobber.ExpandMshGlobPath(String path
, Boolean allowNonexistingPaths, PSDriveInfo drive, ContainerCmdletProvider prov
ider, CmdletProviderContext context)
   at System.Management.Automation.LocationGlobber.ResolveDriveQualifiedPath(Str
ing path, CmdletProviderContext context, Boolean allowNonexistingPaths, CmdletPr
ovider& providerInstance)
   at System.Management.Automation.LocationGlobber.GetGlobbedMonadPathsFromMonad
Path(String path, Boolean allowNonexistingPaths, CmdletProviderContext context,
CmdletProvider& providerInstance)
   at System.Management.Automation.LocationGlobber.GetGlobbedProviderPathsFromMo
nadPath(String path, Boolean allowNonexistingPaths, CmdletProviderContext contex
t, ProviderInfo& provider, CmdletProvider& providerInstance)
   at System.Management.Automation.SessionStateInternal.GetItem(String[] paths,
CmdletProviderContext context)
   at Microsoft.PowerShell.Commands.GetItemCommand.ProcessRecord()".


The Exchange Server setup operation didn't complete. More details can be found
in ExchangeSetup.log located in the <SystemDrive>:\ExchangeSetupLogs folder.


D:\Temp\cu16>

24 August 2017

Windows Insider Program Get Started Button Greyed Out

I came across this because I wanted to make use of the new One-drive on demand sync feature which is only available if you run a Windows 10 insider version.

But the Insider program get started button was greyed out.

To correct this you have to set your privacy settings to "Full"
Settings > Privacy > Feedback & Diagnostics > Under "Diagnostic and usage data select "Full (Recommended)"


Also delete the following registry key:
HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Windows\DataCollection\AllowTelemetry

After a reboot you can finally join the insider preview program.




18 August 2017

PowerShell behind Authenticating proxy



I've seen this at my work a few to many times.
Certain command's just don't get through or something errors out with strange unidentifiable reasons.

Not all command in PowerShell will go through the proxy, IE will pass this on using Windows Integrated Authentication but the .NET Webclient used by PowerShell doesn't appear to do this.

How to get past this? Copy/paste this in your PowerShell windows and all your commands go through your proxy.

$wc = New-Object System.Net.WebClient
$wc.Proxy.Credentials = [System.Net.CredentialCache]::DefaultNetworkCredentials
$wc.DownloadString('http://microsoft.com')

You could add this to your profile to load at startup:

New-item –type file –force $profile            
Notepad $profile

Paste in Notepad:

$wc = New-Object System.Net.WebClient
$wc.Proxy.Credentials = [System.Net.CredentialCache]::DefaultNetworkCredentials
$wc.DownloadString('http://microsoft.com')

Save the Notepad Microsoft.PowerShellISE_profile.ps1 file

There is a request on Connect to have this looked at by the PowerShell team.
https://connect.microsoft.com/PowerShell/feedback/details/754102/a-cmdlet-to-create-a-proxy-configuration-settings-object

18 July 2017

Databasecopystatus unhealthy after installing Security update KB4018588 for Exchange 2013 CU16

I encountered another weird phenomenon after installing the security update KB4018588 for Exchange 2013 CU16.

Installed CU16 for Exchange 2013 on the active database servers and everything went fine, after that installed the security update and that went fine as well.
As a good admin I stopped the maintenace mode on the servers I updated, and checked the databasecopystatus. And there it was, all passive databasecopystatusses were failed.
After some digging around in found out that the searchhostcontroller service was disabled.
Now this service is turned on by default and should start automatically and takes care of Microsoft Exchange Search.

After setting the Microsoft Exchange Search Host service startup type as Automatic and restarting the Microsoft Exchange Search service the dabasecopystatus became healthy again.

13 July 2017

Largest FREE Microsoft eBook Giveaway 2017 - Download them all with PowerShell

It's the time of the year again!
Eric Ligman - the Director Sales Excellence at Microsoft has once again published a ton of free e-books.
This is the third year in a row he does this, and we get to benefit :-)
Like previous year there's no catch, just download and read your eyes out.

Small list of subjects what to expect:
  • Azure
  • Dynamics
  • Licensing
  • Office
  • Office365
  • PowerShell
  • SQL Server
  • System Center
  • Windows Clients
  • Windows Server
To download them all save this file as ".ps1"
2017 Free Ebook Collection

Run the script and the Ebooks will be downloaded to your Downloads\Free Ebooks 2017 folder.


I added the 2016 version as well:
2016 Free Ebook Collection
(Not all the links work anymore, so you might get some errors and 404's and 503's)

And here is the 2015 version:
2015 Free Ebook Collection
(Not all the links work anymore, so you might get some errors and 404's and 503's)

And 2014:
2014 Free Ebook Collection
(Not all the links work anymore, so you might get some errors and 404's and 503's)

There's a 2013 version as well, not downloadable by PowerShell and a bit to old but if you want some old reference material here is the website:
2013 Free Ebook Collection
And the 2012 website:
2012 Free Ebook Collection

28 June 2017

Connect-EXOPSSession behind proxy

With the new Exchange Online Remote PowerShell Module you can connect to Exchange Online with MFA enabled on your account.
But what if you are behind a proxy and are unable to connect?
Chances are that there is one process that goes directly to the internet:





When trying to connect you get the error below:
This PowerShell module allows you to connect to Exchange Online service.            
            
To connect, use: Connect-EXOPSSession -UserPrincipalName your UPN            
            
To get additional information, use: Get-Help Connect-EXOPSSession            
            
PS C:\Users\> Connect-EXOPSSession -UserPrincipalName username@yourtenant.onmicrosoft.com            
New-ExoPSSession : Connecting to remote server outlook.office365.com failed with the following error message : WinRM ca            
nnot complete the operation. Verify that the specified computer name is valid, that the computer is accessible over the            
 network and that a firewall exception for the WinRM service is enabled and allows access from this computer. By defau            
lt the WinRM firewall exception for public profiles limits access to remote computers within the same local subnet. Fo            
r more information, see the about_Remote_Troubleshooting Help topic.            
At C:\Users\username\AppData\Local\Apps\2.0\CCA4XODV.QGQ\BBNHW64J.DHE\micr..tion_c3bce3770c238a49_0010.0000_a5ac7e7ccec31            
8ba\CreateExoPSSession.ps1:179 char:22            
 PSSession = New-ExoPSSession -UserPrincipalName $UserPrincipalName -C ...            
                ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~            
     CategoryInfo          : ResourceUnavailable: (:) [New-ExoPSSession], PSRemotingTransportException            
     FullyQualifiedErrorId : System.Management.Automation.Remoting.PSRemotingDataStructureException,Microsoft.Exchang            
   e.Management.ExoPowershellSnapin.NewExoPSSession

We have to force all traffic through the proxy, the easiest way to do this is with netsh:

Check current settings for the PowerShell session:
netsh winhttp show proxy

Current WinHTTP proxy settings:

Direct access (no proxy server).

Set the proxy server:
netsh winhttp set proxy proxy.domain.lan:8080

Current WinHTTP proxy settings:

Proxy Server(s) :  proxy.domain.lan:8080
Bypass List     :  (none)

Reset to no proxy server settings:
netsh winhttp reset proxy

Current WinHTTP proxy settings:

Direct access (no proxy server).

21 June 2017

Connect to Exchange Online with MFA enabled

Been searching a little while before I got this thru my skull.

I had enabled MFA for my account over at Exchange Online and tried to connect to the remote PowerShell. Immediately my screen turned red.
New-PSSession : [outlook.office365.com] Connecting to remote server outlook.office365.com 
failed with the following error message : [ClientAccessServer=VI1PR0101CA0080,
BackEndServer=am5pr10m 
b0595.eurprd10.prod.outlook.com RequestId=d3099d49-9287-419a-b22f-91e1bf7b888d,
TimeStamp=6/21/2017 10:43:42 AM] Access Denied For more information, see the 
about_Remote_Troubleshooting Help topic.

The access denied error is what triggered me to search for the MFA solution, because in the Office Portal I could log in just fine.

After some searching on the web I came across this:
https://technet.microsoft.com/library/mt775114.aspx
This just recently became available (for as far as I know), prior MFA had to be disabled for the Organisation Management account. Which is a terrible idea of course.

After installing the Exchange Online Remote PowerShell Module you get a new icon in your start menu.
After starting the new PowerShell module you're greated by this:
As you can see there's a new way to connect to Exchange Online with MFA enabled on your command.
The Connect-EXOPSSession is the new way, and a new commandlet not available in any of the installed modules the PowerShell Module directory.
I tried to find what module is explicitly loaded but was unsuccessful.
I think it downloads the module directly from the cloud, right after starting the module a black screen is briefly displayed and then the PowerShell window is shown.

Change Hyper-V Network Category from Public to Private and from Private to DomainAuthenticated with Powershell

This is one of those things that you can do multiple ways.
In my case however the normal routine of changing the network category type from Public to Private didn't work because my machine is domain joined.

When trying to create a HomeGroup you get this on a domain joined machine:
So PowerShell saves the day once again.
First see what adapters you have and what their current category is:
Get-NetConnectionProfile

Name             : Unidentified network
InterfaceAlias   : vEthernet (Internal Virtual Switch)
InterfaceIndex   : 8
NetworkCategory  : Public
IPv4Connectivity : NoTraffic
IPv6Connectivity : NoTraffic

Then set the adapter to category private:
Set-NetConnectionProfile -InterfaceIndex 8 -NetworkCategory Private

Check the settings:
Get-NetConnectionProfile

Name             : Unidentified network
InterfaceAlias   : vEthernet (Internal Virtual Switch)
InterfaceIndex   : 8
NetworkCategory  : Private
IPv4Connectivity : NoTraffic
IPv6Connectivity : NoTraffic

And from Private to Domain:

Check the current settings:
Get-NetConnectionProfile
Name             : Network
InterfaceAlias   : vEthernet (External V-Switch)
InterfaceIndex   : 17
NetworkCategory  : Private
IPv4Connectivity : LocalNetwork
IPv6Connectivity : LocalNetwork

Set to DomainAuthenticated:
Set-NetConnectionProfile -InterfaceIndex 17 -NetworkCategory DomainAuthenticated

Then restart the Network Location Awereness Service (NLA):
Restart-Service -Name NlaSvc -Force

And check again:
Get-NetConnectionProfile

Name             : domain.lan
InterfaceAlias   : vEthernet (External V-Switch)
InterfaceIndex   : 17
NetworkCategory  : DomainAuthenticated
IPv4Connectivity : Internet
IPv6Connectivity : Internet

19 June 2017

Remote PowerShell login Office365, SkypeForBusiness Online, SharePoint Online, Exchange Online, Security and how to disconnect


Remote PowerShell login Office 365 all modules

Requisites login into Office 365 Skype for Business Online are:

· Running OS must be 64bit

· Microsoft .NET Framework 4.5.x

· PowerShell Version 3.0 or higher
(if you need to install Version 3.0+, download and install Windows Management Framework 4.0: https://www.microsoft.com/en-us/download/details.aspx?id=40855)

You need to install the modules that are required for Office 365, SharePoint Online, and Skype for Business Online:
Microsoft Online Service Sign-in Assistant for IT Professionals RTW
Windows Azure Active Directory Module for Windows PowerShell (64-bit version)

Download the Windows PowerShell module for Skype for Business Online
https://www.microsoft.com/en-us/download/details.aspx?id=39366
After installation copy the SkypeOnline and the LyncOnline module folders found in:
C:\Program Files\Common Files\Skype for Business Online\Modules
to:
C:\Windows\System32\WindowsPowerShell\v1.0\Modules
This is because when running Import-Module SkypeOnline the modules can not be found.
By copying them to the default module directory for PowerShell they can be found and load right up.

MicrosoftOnlineLogin

Set-ExecutionPolicy RemoteSigned

$credential = Get-Credential
Connect-MsolService -Credential $credential

SkypeForBusiness

Import-Module SkypeOnlineConnector
$SfBoSession = New-CsOnlineSession -Credential $credential
Import-PSSession $SfBoSession

SharePoint

Import-Module Microsoft.Online.SharePoint.PowerShell -DisableNameChecking
Connect-SPOService -Url https://domainhost-admin.sharepoint.com -credential $credential

Exchange

$exchangeSession = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri "https://outlook.office365.com/powershell-liveid/" -Credential $credential -Authentication "Basic" -AllowRedirection
Import-PSSession $exchangeSession -DisableNameChecking

Security

$ccSession = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://ps.compliance.protection.outlook.com/powershell-liveid/ -Credential $credential -Authentication Basic -AllowRedirection
Import-PSSession $ccSession -Prefix cc

Logout

Remove-PSSession $sfboSession
Remove-PSSession $exchangeSession
Remove-PSSession $ccSession
Disconnect-SPOService
There is no disconnect or remove session option for MSOL, just close the PowerShell window.