Get a list of Exchange mailbox with forwarding

Are you looking for a way to find out how to get hold of all mailbox that has forward in their mailbox and where it’s going?

Get-Mailbox | Where {($_.ForwardingSMTPAddress -ne $null) -or ($_.ForwardingAddress -ne $null)} | Select Name, ForwardingSMTPAddress, ForwardingAddress, DeliverToMailboxAndForward | format-Table -AutoSize

| format-Table -AutoSize, in the end, might not be needed, but for me I feel so much easier to read the information I get back when I can read the entire email address.

Default Domin Password Policy

Do you want to find out the default policy set up on your company?

You can use this PowerShell command you will get the Default Domin Password Policy

Get-ADDefaultDomainPasswordPolicy

The variable you will get back should look something like this, plus a value in the end of course

ComplexityEnabled :
DistinguishedName :
LockoutDuration :
LockoutObservationWindow :
LockoutThreshold :
MaxPasswordAge :
MinPasswordAge :
MinPasswordLength :
objectClass :
objectGuid :
PasswordHistoryCount :
ReversibleEncryptionEnabled :

Remove Azure Role Assignment

How to remove users Access Management from Top level

First, make user you have full access in azure,
Then go to Azure AD, then to Properties

Change from No to Yes
When this is done, you can run this PowerShell command

Remove-AzRoleAssignment -SignInName first.lastname@company.com -RoleDefinitionName "User Access Administrator" -Scope "/"

This will remove the user’s access from the top level.
Make sure your user account change back your access right.

Azure AD Threshold sync

Have you encountered the problem that you want to make more change than allowed or that you just wonder changes how to change Azure AD Sync Threshold?
This needs to be done on the server that has an Azure Sync client.


First to find out if there is one and what is the setup?
Get-ADSyncExportDeletionThreshold

If you want to disable this rule for some reason,
we strongly advise against it.
Disable-ADSyncExportDeletionThreshold

Then there nothing stopping if someone accidentally deleted to many accounts between two syncs.

If you want to change the Threshold to 10
Enable-ADSyncExportDeletionThreshold -DeletionThreshold 10

Read more about it

Powershell SMB

Windows Server 2012 R2 & 2016: PowerShell methods

Detect: SMB v1
Get-WindowsFeature FS-SMB1

Disable:
Disable-WindowsOptionalFeature -Online -FeatureName smb1protocol

Enable:
Enable-WindowsOptionalFeature -Online -FeatureName smb1protocol

Detect: SMB v2/v3
Get-SmbServerConfiguration | Select EnableSMB2Protocol

Disable:
Set-SmbServerConfiguration -EnableSMB2Protocol $false

Enable:
Set-SmbServerConfiguration -EnableSMB2Protocol $true

Windows 8.1 and Windows 10: PowerShell method

Detect: SMB v1 Protocol
Get-WindowsOptionalFeature –Online –FeatureName SMB1Protocol

Disable:
Disable-WindowsOptionalFeature -Online -FeatureName SMB1Protocol

Enable:
Enable-WindowsOptionalFeature -Online -FeatureName SMB1Protocol

Detect: SMB v2/v3 Protocol
Get-SmbServerConfiguration | Select EnableSMB2Protocol

Disable:
Set-SmbServerConfiguration –EnableSMB2Protocol $false

Enable:
Set-SmbServerConfiguration –EnableSMB2Protocol $true

Read more about at Microsoft

Powershell mount drive

How to mount a drive in Powershell



$url = hostname
$folder = specific folder
$port = port nr
$username = account name
$pass = password

 

$connectTestResult = Test-NetConnection -ComputerName $url -Port $port
if ($connectTestResult.TcpTestSucceeded) {
    # Save the password so the drive will persist on reboot
    cmd.exe /C "cmdkey /add:`"$url`" /user:`"$username`" /pass:`$pass`""
    # Mount the drive
    New-PSDrive -Name Z -PSProvider FileSystem -Root "$folder"-Persist
} else {
    Write-Error -Message "Unable to reach the $url storage account via port $port. Check to make sure your organization or ISP is not blocking port $port"

}

Computer branding with PDQ

Hey
What do you say we give it a shot and try to do computer branding with PDQ?

Here you have a code you can try to experiment with.

More information about $location check out this post, there you can read how to fetch the information and import it into PDQ Inventory database.

$location = "where you want to store CSV file that PDQ will fetch from"
$localLocation "where you want to store local txt file"

#Featch Values
function MenuGui()
{
#To use the .NET functionality to create forms, we use the class System.Windows.Forms. To load this class into a PowerShell session, you can use the following code:
Add-Type -assembly System.Windows.Forms

#Now create the screen form (window)
$main_form = New-Object System.Windows.Forms.Form

#Set the title and size of the window:
$main_form.Text ='Helpdesk'
$main_form.Width = 400
$main_form.Height = 50

#To make the form automatically stretch, if the elements on the form are out of bounds, we use the AutoSize property.
$main_form.AutoSize = $true

#Create a label element on the form about user name
$Label = New-Object System.Windows.Forms.Label
$Label.Text = "User: " + $WhoAmI
$Label.Location  = New-Object System.Drawing.Point(150,10)
$Label.AutoSize = $true
$main_form.Controls.Add($Label)

#Create a secound label element on the form about computer name
$Label2 = New-Object System.Windows.Forms.Label
$Label2.Text = "Computer name: " + $Hostname  
$Label2.Location  = New-Object System.Drawing.Point(150,25)
$Label2.AutoSize = $true
$main_form.Controls.Add($Label2)

  # Add Button 1
    $Button = New-Object System.Windows.Forms.Button
    $Button.Location = New-Object System.Drawing.Size(150,45)
    $Button.Size = New-Object System.Drawing.Size(145,23)
    $Button.Text = "Change Owner"
    $main_form.Controls.Add($Button)
  
  #Add close form function to the button, when you click
        $Button.add_click({
        $employees = @($Hostname+","+$WhoAmI)
        $employees | foreach { Add-Content -Path $locationv -Value $_ }
        New-Item -Path $localLocation\ -Name "Owner.txt" -ItemType "file" -Value $env:UserName -Force
        $main_form.Close()})

    
#Create a label element on the form about user name
$Label3 = New-Object System.Windows.Forms.Label
$Label3.Text = "You get this message for our systems says someone else is the owner of this computer`n then the user who is logged in. Please press Change Owner if its incorrect`n`nIf any question contact us on Phone: XXX, Email: xxx@xxx.com "
$Label3.Location  = New-Object System.Drawing.Point(1,80)
$Label3.AutoSize = $true
$main_form.Controls.Add($Label3)
  

#Now you can display the form on the screen.
$main_form.ShowDialog()
}

#Variable
$Hostname = $env:COMPUTERNAME
$WhoAmI = $env:UserName


$WantFile = "$localLocation\Owner.txt"
$FileExists = Test-Path $WantFile
If ($FileExists -eq $True) 
{
    Write-Host "Yippee file exist"
}

Else 
{
    New-Item -Path $localLocation\ -Name "Owner.txt" -ItemType "file" -Value $env:UserName -Force
    $employees = @($Hostname+","+$WhoAmI)
    $employees | foreach { Add-Content -Path $location -Value $_ }
    Write-Host "NO! File do not exist"
}


$textfile = Get-Content -Path $localLocation\Owner.txt

if($textfile -eq $env:UserName)
{
  echo "True value, do not run the script";
}
else
{
    echo "wrong value, please run the script";
    MenuGui
}

Enjoy!


Import data to PDQ Inventory

Do you have external data you want to import to PDQ Inventory?

With the help of this PHP code, you can do this.


$TempFile = "specify where the file is located"
$Computer = "Name"
$CustomFieldName = "Owner"
$CustomFieldType = "String" # Valid types - Boolean, String, Integer, Date, or DateTime
PDQInventory.exe ImportCustomFields -FileName $TempFile -ComputerColumn $Computer -CustomFields "$CustomFieldName=$CustomFieldName" -AllowOverwrite

A good place to find help is PDQ Community

Module MSOnline Powershell

So you want to use Powershell to do things in o365 MSOnline?

First of you need to import MSOnline

Import-Module Connect-MsolService

#Before it was
Import-Module MSOnline

Then after that, you can start using for example

get-msoluser -UserPrincipalName mailbox@technologynexus.onmicrosoft.com | select PasswordNeverExpires

And many other commands that come with the import of MSOnline

Don’t forget that you need to connect to Azure with PowerShell before you can start using the commands.

Module Az.advisor Powershell

So you want to use Powershell to do things in Azure Advisor?

First of you need to import Az.Advisor

import-module Az.Advisor

Then after that, you can start using for example

Get-AzAdvisorRecommendation -Category HighAvailability

And many other commands that come with the import of Az.advisor

Don’t forget that you need to connect to Azure with PowerShell before you can start using the commands.