24 June 2021

Run Sysinternals from the live location

Run Sysinternals from the live location https://live.sysinternals.com/

Run the below command to add the path to your environment variables:

SETX PATH "%PATH%;\\live.sysinternals.com\tools;"

Then you can run all the Sysinternal tools directly from the RUN command line

22 June 2021

Connecting to remote server failed with the following error message:
The WSMan client cannot process the request. Proxy is not supported under HTTP transport. Change the transport to HTTPS and specify valid proxy information and try again.

Check the following location in the registry:HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Internet Settings\Connections\WinHttpSettings

In the WinHttpSettings dword entry there will be an entry to a proxy server.
Delete the entire key.

Remove-Item HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Internet Settings\Connections\WinHttpSettings -Recurse


02 June 2021

We couldn't sign you in. Please try again

 We couldn't sign you in. Please try again.

And then your in a loop. Clearing the browser cache helps sometimes, but that's not the real reason why you are seeing this error.
Have you been reducing the number of global admins recently?
Or perhaps you have been messing around with PIM (Privilidged Access Management)?

Chances are you assigned yourself a load of Roles, because you are important and you need all the different roles.
But when adding to many roles to your account that's when you will see the error above.
So simple solution, lose some roles on your account.


12 April 2021

The term is not recognized as the name of a cmdlet, function, script file, or operable program. How to connect from a specific module

Get-AzureADDirectorySetting : The term 'Get-AzureADDirectorySetting' is not recognized as the name of a cmdlet,            
function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the            
path is correct and try again.
And
Get-AzureADDirectorySetting : The term 'Get-AzureADObjectSetting' is not recognized as the name of a cmdlet,            
function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the            
path is correct and try again.

That's strange, the command does get completed when tabbing after typing get-azureaddir.
The problem is it's an AzureADPreview module commandlet, so you have to connect to AzureAd from that module like so:

Connect to AzureAD with a specific module:
AzureADPreview\Connect-AzureAD

08 April 2021

Add guest users to AzureAD in bulk and update the manager with PowerShell

 Bulk invite guest users:

<#  
.NOTES
    Name      : Add-BulkGuests.ps1
    Author    : Edwin van Brenk
    Version   : 1.0
    Date      : 08-04-2021
    Requires  : PowerShell v2 or higher
                AzureAD module
.SYNOPSIS
    -
.DESCRIPTION
    Bulk invite guest users in your AzureAD tenant
.PARAMETER
    -
.EXAMPLE
    -
.CSV FILE
    The csv need to look like this:
    DisplayName,EmailAddress
    firstname lastname,firstname.lastname@domain.com

#>            
            
# Connect to your tenant            
Connect-AzureAD            
            
# Import the csv file            
$guests = Import-Csv C:\temp\BulkGuests2.csv            
            
# Invite all users in the imported csv file            
foreach ($guest in $guests)            
{            
# Function Variables            
$emailaddress = $guest.EmailAddress            
$displayname = $guest.DisplayName            
            
   New-AzureADMSInvitation -InvitedUserEmailAddress $guest.emailaddress -InvitedUserDisplayName $guest.displayName -InviteRedirectUrl https://myapplications.microsoft.com -SendInvitationMessage $True            
   Write-Host "Invite sent to $emailaddress" -ForegroundColor Green            
}            
            
Write-Host Finished

Update the managers for the newly invited guests:

<#  
.NOTES
    Name      : Update-GuestManager.ps1
    Author    : Edwin van Brenk
    Version   : 1.0
    Date      : 08-04-2021
    Requires  : PowerShell v2 or higher
                AzureAD module
                Az.Accounts
.SYNOPSIS
    -
.DESCRIPTION
    Update guest users in your AzureAD tenant with the correct manager
.PARAMETER
    -
.EXAMPLE
    -
.CSV FILE
    The csv needs to look like this:
    User,Manager
    firstname lastname,manageremailaddress@domain.com
    
#>            
            
            
# Connecting to AzureAD            
Connect-AzureAD            
Connect-AzAccount            
            
# Importing the CSV source which has the changes             
$data = Import-Csv C:\Temp\Bulk\Manager.csv            
            
# Iterating through each row in the CSV            
foreach ($row in $data)            
{            
# Find the user and the manager            
$user = Get-AzureADUser -SearchString $row.User | select objectid            
$manager = Get-AzADUser -UserPrincipalName $row.Manager | Select Id            
            
# Updating the manager             
Set-AzureADUserManager -ObjectId $user.objectid -RefObjectId $manager.id            
            
# Completion info in the console for the specified row            
Write-Host "Updated "$row.user"" -ForegroundColor Green            
            
# Clear the variable for the next row            
$user = $null            
$manager = $null            
            
}            
Write-Host "Finished" -ForegroundColor Green

11 March 2021

Set Windows Server to use external NTP server

Stop the time service:
net stop w32time

Add the NTP servers to the manual peer list external servers:
w32tm /config /syncfromflags:manual /manualpeerlist:0.us.pool.ntp.org,1.us.pool.ntp.org,2.us.pool.ntp.org,3.us.pool.ntp.org

Set the source as reliable:
w32tm /config /reliable:yes

Start the time service:
net start w32time

Test the configuration:
w32tm /query /configuration



and
w32tm /query /status





27 February 2021

Usefull command's and little PowerShell scripts

Quickly get the Computer Name, Model, Make, and other useful information


Get-WMIObject -Class Win32_ComputerSystem             
information about the System            
            
Get-WMIObject -Class Win32_BIOS             
Information about the BIOS            
            
Get-WMIObject -Class Win32_Baseboard             
Information about the Motherboard            
            
Get-WMIObject -Class Win32_Processor             
Information about the CPU            
            
Get-WMIObject -Class Win32_LogicalDisk             
Information about Logical Drives (Includes mapped drives and I believe PSDrives)            
            
Get-WMIObject -Class Win32_DiskDrive             
Information about Physical Drives            
            
Get-WMIObject -Class Win32_PhysicalMemory             
Information about the Memory            
            
Get-WMIObject -Class Win32_NetworkAdapter             
Information about the NIC            
            
Get-WMIObject -Class Win32_NetworkAdapterConfiguration             
Information about the NICs Configuration


Check your PowerShell Version

$PSVersionTable



Restart all Network Adapters *Must be run as admin or at least local admin*

Requires PowerShell 3.0+

Get-NetAdapter | Restart-NetAdapter


Browse UNC path with PowerShell

To access UNC via PowerShell;

cd \\servername\C$\Path\To\File



Copy a file to all users Desktop’s

$Users = Get-ChildItem C:\Users\ -Exclude “Administrator”,”Public”,”Default*” # Exclude any other defaults that you don’t want.            
            
foreach($User in $Users.name){             
$Path = “C:\Users\$User\Desktop”;             
Copy-Item -Path “\\Path\To\Source\File.txt” -Destination $Path\File.txt             
}


Get free disk space on drives

This can either be run locally or part of a larger script to hit multiple machines.

$Drive=Get-WmiObject Win32_LogicalDisk -Filter “DriveType = 3”             
$DriveSize=$Drive.Size;$DriveSize=[math]::Round($DriveSize/1GB)             
$FreeSpace=$Drive.FreeSpace;$FreeSpace=[math]::Round($FreeSpace/1GB)             
$DriveName=$Drive.Name             
$ComputerName=Get-WmiObject Win32_ComputerSystem;$ComputerName=$ComputerName.Name             
$UsedSpace=$DriveSize  $FreeSpace;$UsedSpace=[string]$UsedSpace+” GB free on drive $DriveName on computer $ComputerName”            
            

26 February 2021

Enable Wake On Lan with PowerShell and send Wake On Lan packet with PowerShell

Credit for the script goes to Jan-Henrik Damaschke at https://www.itinsights.org

function Set-WakeEnabled

{            
<#
.SYNOPSIS

Set WoL on nic

Author: Jan-Henrik Damaschke (@jandamaschke)
License: BSD 3-Clause
Required Dependencies: None
Optional Dependencies: None

.DESCRIPTION

Set Wake on Lan (WOL) settings for specific network interface card

.PARAMETER InterfaceName

Specifies the name of the interface where WoL setting should be changed

.PARAMETER WakeEnabled

Specifies if WoL should be enabled or disabled

.EXAMPLE

PS C:\> Set-WakeEnabled -InterfaceName Ethernet -WakeEnabled $true

.LINK

http://itinsights.org/
#>            
            
[CmdletBinding()] Param(            
        [Parameter(Mandatory = $True, ParameterSetName="InterfaceName")]            
        [String]            
        $InterfaceName,            
            
        [Parameter(Mandatory = $True)]            
        [String]            
        $WakeEnabled,            
            
        [Parameter(Mandatory = $True, ParameterSetName="ConnectionID")]            
        [String]            
        $NetConnectionID            
)            
            
    If (-NOT ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")) {            
        Write-Warning "You do not have Administrator rights to run this script!`nPlease re-run this script as an Administrator!"            
        Break            
    }            
            
    $nicsWakeEnabled = Get-CimInstance -ClassName MSPower_DeviceWakeEnable -Namespace root/wmi            
    $nics = Get-CimInstance -ClassName Win32_NetworkAdapter | Where-Object NetEnabled -eq $true            
            
    if ($InterfaceName){            
        $nic = $nics | Where-Object Name -eq $InterfaceName            
    }            
    else {            
        $nic = $nics | Where-Object NetConnectionID -eq $NetConnectionID            
    }            
            
    $nicWakeEnabled = $nicsWakeEnabled | Where-Object InstanceName -like "*$($nic.PNPDeviceID)*"            
                
    $enabled = $nicWakeEnabled.Enable            
            
    if (!($enabled -and $WakeEnabled)){            
        Set-CimInstance $nicWakeEnabled -Property @{Enable=$enabled}            
    }            
}

Find the mac address of the nic you want to wake up.
Get-WmiObject win32_networkadapterconfiguration | select description, macaddress
Or
Get-CimInstance win32_networkadapterconfiguration | select description, macaddress

To send a wake on lan package:
Install-Module -Name wakeonlan -Force
Import-module -Name wakeonlan
Invoke-WakeOnLan -MacAddress 84:D2:4A:0F:78:44

16 February 2021

Open Windows Explorer collapsed

 Anoying.

When opening Windows Explorer it opens with all folders collapsed. The behaviour can come from different settings, such as:

Showing all folders
Allowing network discovery
Last opened folder saved when closing the explorer

And probably a few I don't k now about.

Some dude (EpilepticUnderscore) over at social.technet.com created a batch file to overcome this annoyance.
See the original thread here: Collapse all folder-trees when closing Explorer (microsoft.com)

The batch job way:

29 January 2021

Single Sign On broken - Azure Active Directory Seamless Single Sign-On

 I don't know if this is something that only happens in my environment, but it happens.

When ever I start AADConnect and make a change in the configuration, add an OU for example, and save the change SSO breaks.

Quick way to see what's up is here:


If there are zero Seamless single sign-on domain's than you know what's up.
The SSO trust is broken.

There is a blogpost on docs.microsoft.com about it:
Azure Active Directory Connect: Troubleshoot Seamless Single Sign-On | Microsoft Docs

The steps listed there are in this script below.

Run this from the AADConnect machine:

# https://docs.microsoft.com/en-us/azure/active-directory/hybrid/tshoot-connect-sso            
            
# Import the Seamless SSO PowerShell module            
cd \            
cd 'C:\Program Files\Microsoft Azure Active Directory Connect'            
Import-Module .\AzureADSSO.psd1            
# Get the list of Active Directory forests on which Seamless SSO has been enabled            
New-AzureADSSOAuthenticationContext            
Get-AzureADSSOStatus            
#Disable Seamless SSO for each Active Directory forest where you've set up the feature            
$creds = Get-Credential domain\username            
Disable-AzureADSSOForest -OnPremCredentials $creds            
# Enable Seamless SSO for each Active Directory forest            
Enable-AzureADSSOForest            
# Enable the feature on your tenant            
Enable-AzureADSSO -Enable $true