07 May 2019

PowerShell keyboard shortcuts - PowerShell ISE keyboard shortcuts

A list of all keyboard shortcuts for PowerShell ISE is in the table below.

But there is one I want to mention that I personally find awesome:
The officialname is "IntellisenseShortcut"

Get an overview of all options for a comandlet:
Get services -
Press CTRL and Spacebar and boom:



Name
Keyboard Shortcut
EditorUndoShortcut2
Alt+Backspace
EditorSelectNextSiblingShortcut
Alt+Down
ExitShortcut
Alt+F4
EditorSelectEnclosingShortcut
Alt+Left
EditorSelectFirstChildShortcut
Alt+Right
EditorRedoShortcut2
Alt+Shift+Backspace
EditorBoxSelectLineDownShortcut
Alt+Shift+Down
ToggleHorizontalAddOnPaneShortcut
Alt+Shift+H
EditorBoxSelectToPreviousCharacterShortcut     
Alt+Shift+Left
EditorBoxSelectToNextCharacterShortcut
Alt+Shift+Right
EditorTransposeLineShortcut
Alt+Shift+T
EditorBoxSelectLineUpShortcut
Alt+Shift+Up
ToggleVerticalAddOnPaneShortcut
Alt+Shift+V
EditorSelectPreviousSiblingShortcut
Alt+Up
ShowScriptPaneTopShortcut
Ctrl+1
ShowScriptPaneRightShortcut
Ctrl+2
ShowScriptPaneMaximizedShortcut
Ctrl+3
EditorSelectAllShortcut
Ctrl+A
ZoomIn1Shortcut
Ctrl+Add
EditorMoveCurrentLineToBottomShortcut
Ctrl+Alt+End
EditorMoveCurrentLineToTopShortcut
Ctrl+Alt+Home
BreakAllDebuggerShortcut
Ctrl+B
EditorDeleteWordToLeftShortcut
Ctrl+Backspace
StopExecutionShortcut
Ctrl+Break
StopAndCopyShortcut
Ctrl+C
GoToConsoleShortcut
Ctrl+D
EditorDeleteWordToRightShortcut
Ctrl+Del
EditorScrollDownAndMoveCaretIfNecessaryShortcut
Ctrl+Down
EditorMoveToEndOfDocumentShortcut
Ctrl+End
FindShortcut
Ctrl+F
ShowCommandShortcut
Ctrl+F1
CloseScriptShortcut
Ctrl+F4
GoToLineShortcut
Ctrl+G
ReplaceShortcut
Ctrl+H
EditorMoveToStartOfDocumentShortcut
Ctrl+Home
GoToEditorShortcut
Ctrl+I
Copy2Shortcut
Ctrl+Ins
ShowSnippetShortcut
Ctrl+J
EditorMoveToPreviousWordShortcut
Ctrl+Left
ToggleOutliningExpansionShortcut
Ctrl+M
ZoomOut3Shortcut
Ctrl+Minus
NewScriptShortcut
Ctrl+N
OpenScriptShortcut
Ctrl+O
GoToMatchShortcut
Ctrl+Oem6
ZoomIn3Shortcut
Ctrl+Plus
ToggleScriptPaneShortcut
Ctrl+R
EditorMoveToNextWordShortcut
Ctrl+Right
SaveScriptShortcut
Ctrl+S
ZoomIn2Shortcut
Ctrl+Shift+Add
GetCallStackShortcut
Ctrl+Shift+D
EditorSelectToEndOfDocumentShortcut
Ctrl+Shift+End
RemoveAllBreakpointsShortcut
Ctrl+Shift+F9
HideHorizontalAddOnToolShortcut
Ctrl+Shift+H
EditorSelectToStartOfDocumentShortcut
Ctrl+Shift+Home
ListBreakpointsShortcut
Ctrl+Shift+L
EditorSelectToPreviousWordShortcut
Ctrl+Shift+Left
ZoomOut4Shortcut
Ctrl+Shift+Minus
StartPowerShellShortcut
Ctrl+Shift+P
ZoomIn4Shortcut
Ctrl+Shift+Plus
NewRemotePowerShellTabShortcut
Ctrl+Shift+R
EditorSelectToNextWordShortcut
Ctrl+Shift+Right
ZoomOut2Shortcut
Ctrl+Shift+Subtract
EditorMakeUppercaseShortcut
Ctrl+Shift+U
HideVerticalAddOnToolShortcut
Ctrl+Shift+V
IntellisenseShortcut
Ctrl+Space
ZoomOut1Shortcut
Ctrl+Subtract
NewRunspaceShortcut
Ctrl+T
EditorMakeLowercaseShortcut
Ctrl+U
EditorScrollUpAndMoveCaretIfNecessaryShortcut  
Ctrl+Up
Paste1Shortcut
Ctrl+V
CloseRunspaceShortcut
Ctrl+W
Cut1Shortcut
Ctrl+X
EditorRedoShortcut1
Ctrl+Y
EditorUndoShortcut1
Ctrl+Z
F1KeyboardDisplayName
F1
HelpShortcut
F1
StepOverShortcut
F10
F10KeyboardDisplayName 
F10
StepIntoShortcut
F11
F11KeyboardDisplayName 
F11
F12KeyboardDisplayName 
F12
F2KeyboardDisplayName
F2
F3KeyboardDisplayName
F3
FindNextShortcut
F3
F4KeyboardDisplayName
F4
F5KeyboardDisplayName
F5
RunScriptShortcut
F5
F6KeyboardDisplayName
F6
F7KeyboardDisplayName
F7
F8KeyboardDisplayName
F8
RunSelectionShortcut
F8
F9KeyboardDisplayName
F9
ToggleBreakpointShortcut
F9
EditorDeleteCharacterToLeftShortcut
Shift+Backspace
Cut2Shortcut
Shift+Del
EditorSelectLineDownShortcut
Shift+Down
EditorSelectToEndOfLineShortcut
Shift+End
EditorInsertNewLineShortcut
Shift+Enter
StepOutShortcut
Shift+F11
FindPreviousShortcut
Shift+F3
StopDebuggerShortcut
Shift+F5
EditorSelectToStartOfLineShortcut
Shift+Home
Paste2Shortcut
Shift+Ins
EditorSelectToPreviousCharacterShortcut        
Shift+Left
EditorSelectPageDownShortcut
Shift+PgDn
EditorSelectPageUpShortcut
Shift+PgUp
EditorSelectToNextCharacterShortcut
Shift+Right
EditorSelectLineUpShortcut
Shift+Up



19 April 2019

Enable Basic Authentication for one user - Exchange Online

Disable basic authentication, password spray attack, enable MFA, enable modern authentication now!!
These are the topics most blogs post about, Tweeters tweet about and Microsoft warns about.
Talk about a panic attack. Of course this is very important stuff and you should disable basic auth, enable modern auth with MFA, and implement password protection.

But what if you have an application made in 1990 that requires basic auth to access your Exchange Online environment?

You can bypass the modern auth requirement with a policy that allows you to turn on basic auth for one specific user. 😎

All this is done in Exchange Online PowerShell;
Create a policy:
New-AuthenticationPolicy -Name "Allow Basic Auth for some ancient application"
Specify what services are allowed to use basic auth:
Set-AuthenticationPolicy -Identity "Allow Basic Auth for some ancient application" -AllowBasicAuthWebServices:$true             
Set-AuthenticationPolicy -Identity "Allow Basic Auth for some ancient application" -AllowBasicAuthOutlookService:$true             
Set-AuthenticationPolicy -Identity "Allow Basic Auth for some ancient application" -AllowBasicAuthReportingWebServices:$true             
Set-AuthenticationPolicy -Identity "Allow Basic Auth for some ancient application" -AllowBasicAuthActiveSync:$true             
Set-AuthenticationPolicy -Identity "Allow Basic Auth for some ancient application" -AllowBasicAuthRest:$true             
Set-AuthenticationPolicy -Identity "Allow Basic Auth for some ancient application" -AllowBasicAuthPowershell:$true             
Set-AuthenticationPolicy -Identity "Allow Basic Auth for some ancient application" -AllowBasicAuthMapi:$true             
Set-AuthenticationPolicy -Identity "Allow Basic Auth for some ancient application" -AllowBasicAuthOfflineAddressBook:$true             
Set-AuthenticationPolicy -Identity "Allow Basic Auth for some ancient application" -AllowBasicAuthAutodiscover:$true             
Set-AuthenticationPolicy -Identity "Allow Basic Auth for some ancient application" -AllowBasicAuthRpc:$true
Check the policy settings:
Get-AuthenticationPolicy -Identity "Allow Basic Auth for some ancient application" | fl AllowBasicAuth*
AllowBasicAuthActiveSync           : True            
AllowBasicAuthAutodiscover         : True            
AllowBasicAuthImap                 : False            
AllowBasicAuthMapi                 : True            
AllowBasicAuthOfflineAddressBook   : True            
AllowBasicAuthOutlookService       : True            
AllowBasicAuthPop                  : False            
AllowBasicAuthReportingWebServices : True            
AllowBasicAuthRest                 : False            
AllowBasicAuthRpc                  : True            
AllowBasicAuthSmtp                 : False            
AllowBasicAuthWebServices          : True            
AllowBasicAuthPowershell           : True
As you can see in the example above we do not allow SMTP, POP and IMAP to use basic auth, but ofcourse you could by adding:
Set-AuthenticationPolicy -Identity "Allow Basic Auth for some ancient application" -AllowBasicAuthSmtp:$true            
Set-AuthenticationPolicy -Identity "Allow Basic Auth for some ancient application" -AllowBasicAuthImap:$true            
Set-AuthenticationPolicy -Identity "Allow Basic Auth for some ancient application" -AllowBasicAuthPop:$true
Then grant a specific user the created policy:
Set-User -Identity LegacyUser -AuthenticationPolicy "Allow Basic Auth for some ancient application"
And check if all went well:
Get-User -Identity LegacyUser | fl auth*            
AuthenticationPolicy : Allow Basic Auth for some ancient application
Name                 : LegacyUser
To check all users with an authenticationpolicy assigned:
Get-Recipient -RecipientTypeDetails UserMailbox -ResultSize Unlimited | Get-User | Format-Table
DisplayName, AuthenticationPolicy, Sts*
Update:
I just found that if a user has the "Multi-factor Auth status" set to "Enforced", you need to set it to disabled here: https://account.activedirectory.windowsazure.com/UserManagement/MultifactorVerification.aspx

And there you have it, now that one user is able to use basic auth.
Document this properly as this does pose a security threat, and these little exceptions tend to be forgotten over time.

02 April 2019

The PowerShellGallery - Find - Install - Deploy - Updating



Discovering packages from the PowerShell Gallery

Find packages in the PowerShell Gallery by using the Search control on the PowerShell Gallery's home page.
By browsing through the Modules and Scripts from the Packages page.
Running the Find-Module, Find-DscResource, and Find-Script cmdlets, depending on the package type, with -Repository PSGallery.

Installing packages from the PowerShell Gallery

To download a package from the Gallery for inspection, run either the Save-Module or Save-Script cmdlet.
Install a package from the Gallery for use, run either the Install-Module or Install-Script cmdlet.

Updating packages from the PowerShell Gallery

To update packages installed from the PowerShell Gallery, run either the Update-Module or Update-Script cmdlet.
When run without any additional parameters, [Update-Module][] attempts to update all modules installed by running Install-Module.
To selectively update modules, add the -Name parameter.

List packages that you have installed from the PowerShell Gallery

To find out which modules you have installed from the PowerShell Gallery, run the Get-InstalledModule cmdlet.
To find out which scripts you have installed from the PowerShell Gallery, run the Get-InstalledScript cmdlet.


Some examples:
Search through all scripts in the GridView window and install the selected script in the currentuser environment variable ($env:USERPROFILE\Documents\WindowsPowerShell\Modules):
Find-Script | Out-Gridview -Title "Select Script to install" -PassThru | Install-Script -Force -Scope CurrentUser

Search through all modules in the GridView window and install the selected module in the currentuser environment variable:
Find-Module | Out-Gridview -Title "Select Modules to install" -PassThru | Install-Module -Force -Scope CurrentUser

Update all installed modules without interaction:
Update-Module -Force

Update all installed script without interaction:
Update-Script -Force

15 March 2019

Install RSAT for Windows Server 2019 and Windows 10 with PowerShell

Windows Server 2019

Run the cmdlet below with the -whatif switch to check what will is allready installed and will be installed:
Install-WindowsFeature -IncludeAllSubFeature RSAT -WhatIf
Get-WindowsFeature -Name RSAT* | where 'install state' -NE Installed
To install all the tools run the cmdlet below:
Install-WindowsFeature -IncludeAllSubFeature RSAT
Or
Install-WindowsFeature -Name RSAT -IncludeAllSubFeature -IncludeManagementTools

Windows10

Check whether RSAT components are installed on your computer:
Get-WindowsCapability -Name RSAT* -Online
View the status of installed RSAT components in a easy view:
Get-WindowsCapability -Name RSAT* -Online | Select-Object -Property DisplayName, State
You can use the Add-WindowsCapacity cmdlet to install these Windows features.
To install a specific RSAT tool, such as AD management tools (including the ADUC console), run the command:
Add-WindowsCapability –online –Name “Rsat.ActiveDirectory.DS-LDS.Tools~~~~0.0.1.0”
To install the DNS management console only, run:
Add-WindowsCapability –online –Name “Rsat.Dns.Tools~~~~0.0.1.0”
And all the other single install options:
Add-WindowsCapability -Online -Name Rsat.FileServices.Tools~~~~0.0.1.0
Add-WindowsCapability -Online -Name Rsat.GroupPolicy.Management.Tools~~~~0.0.1.0
Add-WindowsCapability -Online -Name Rsat.IPAM.Client.Tools~~~~0.0.1.0
Add-WindowsCapability -Online -Name Rsat.LLDP.Tools~~~~0.0.1.0
Add-WindowsCapability -Online -Name Rsat.NetworkController.Tools~~~~0.0.1.0
Add-WindowsCapability -Online -Name Rsat.NetworkLoadBalancing.Tools~~~~0.0.1.0
Add-WindowsCapability -Online -Name Rsat.BitLocker.Recovery.Tools~~~~0.0.1.0
Add-WindowsCapability -Online -Name Rsat.CertificateServices.Tools~~~~0.0.1.0
Add-WindowsCapability -Online -Name Rsat.DHCP.Tools~~~~0.0.1.0
Add-WindowsCapability -Online -Name Rsat.FailoverCluster.Management.Tools~~~~0.0.1.0
Add-WindowsCapability -Online -Name Rsat.RemoteAccess.Management.Tools~~~~0.0.1.0
Add-WindowsCapability -Online -Name Rsat.RemoteDesktop.Services.Tools~~~~0.0.1.0
Add-WindowsCapability -Online -Name Rsat.ServerManager.Tools~~~~0.0.1.0
Add-WindowsCapability -Online -Name Rsat.Shielded.VM.Tools~~~~0.0.1.0
Add-WindowsCapability -Online -Name Rsat.StorageMigrationService.Management.Tools~~~~0.0.1.0
Add-WindowsCapability -Online -Name Rsat.StorageReplica.Tools~~~~0.0.1.0
Add-WindowsCapability -Online -Name Rsat.SystemInsights.Management.Tools~~~~0.0.1.0
Add-WindowsCapability -Online -Name Rsat.VolumeActivation.Tools~~~~0.0.1.0
Add-WindowsCapability -Online -Name Rsat.WSUS.Tools~~~~0.0.1.0
To install all the available RSAT tools at once, run:
Get-WindowsCapability -Name RSAT* -Online | Add-WindowsCapability –Online
To install only disabled RSAT components, run:
Get-WindowsCapability -Online |? {$_.Name -like "*RSAT*" -and $_.State -eq "NotPresent"} | Add-WindowsCapability -Online
If installing RSAT you encounter an error Add-WindowsCapability failed.
Error code = 0x800f0954, most likely your computer is configured to receive updates from the internal WSUS or SUP server.

To install RSAT components, you need to temporarily disable the update from the WSUS server in the registry.
Open the registry key HKLM\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU and change the UseWUServer to 0 and restart the Update Service.

Or run this script:
$currentWU = Get-ItemProperty -Path "HKLM:\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU" -Name "UseWUServer" | select -ExpandProperty UseWUServer
Set-ItemProperty -Path "HKLM:\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU" -Name "UseWUServer" -Value 0            
Restart-Service wuauserv            
Get-WindowsCapability -Name RSAT* -Online | Add-WindowsCapability –Online            
Set-ItemProperty -Path "HKLM:\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU" -Name "UseWUServer" -Value $currentWU
Restart-Service wuauserv

error code: dlg_flags_sec_cert_cn_invalid - The hostname in the website's certificate differs from the website you are trying to visit

This was one error that I couldn't find a definitive answer for after searching the error:

error code: dlg_flags_sec_cert_cn_invalid - The hostname in the website's certificate differs from the website you are trying to visit

Long story short, in my case this came down to the "Common name" or "CN" in the certificate.
I had created the cert with a CN and some SAN names like so:

CN=application.domain.lan

SAN=application.domain.lan
SAN=application
SAN=servername.domain.lan
SAN=servername
SAN=applicationalias.domain.lan
SAN=applicationalias

Internet Explorer 11, Edge, Chrome and Firefox all tripped over the Common name.
If I typed in the browser: "https://application" the error did not appear. So my conclusion is that the webserver doesn't interpret the domain suffix stated in the common name.

So I recreated the certificate with the Common name: "application".
Binded it in IIS, iisrestart and reloaded the site in IE and behold no more errors.


04 March 2019

Connect to all Azure & Office 365 services in one PowerShell window

We've all been there, when running some commandlets from Exchange online suddenly you need to switch to Sharepoint, AzureAD or Skype Online.

With this handy script you can connect to all services at once.
I personally always use the Exchange Online PowerShell module for this, as it will be updated when starting it so you always have the latest commandlets for Exchange Online.

There are some requirements that have to be met before hand:
  • .Net 4.5
  • Windows Management Framework 3.0 or 4.0
  • 64-bit version of Windows OS
Installed modules:
  • Azure Active Directory V2 module
  • SharePoint Online module
  • Skype for Business Online module
Execution policy needs to be at least "Remote Signed"

In the past I have created a script that installs all these requirements at once:
I try to keep this updated, so if anything fails leave me a comment.

Then you can run the lines below and connect to all the services in one PowerShell window.
Mind you, this is all for MFA enabled accounts.

# Azure Active Directory            
Connect-MsolService            
# SharePoint Online            
Connect-SPOService -Url https://domain-admin.sharepoint.com            
# Skype for Business Online            
Import-Module SkypeOnlineConnector            
$sfboSession = New-CsOnlineSession -UserName "username@domain.com" -OverrideAdminDomain domain.onmicrosoft.com            
Import-PSSession $sfboSession            
# Exchange Online            
Connect-Exopssession -UserPrincipalName username@domain.com            
# Microsoft Teams            
Connect-MicrosoftTeams            
# AzureAD            
Connect-AzureAD            
# Intune            
Connect-MSGraph