Microsoft Teams – Connect to Powershell

Hi Guys,

Microsoft recently released the Powershell Cmdlets (still in beta), which gives you the opportunity to manage Microsoft Teams by Powershell.
To get started you wil first need to install the Microsoft Teams Powershell module. You can do this by using the following command:

Install-Module -Name MicrosoftTeams

install-module MicrosoftTeams
After installing the module we need to set up a connection to your Office 365 tenant, using the following command:

Connect-MicrosoftTeams


When you are finished you can use the following command to shut down the connection:

Disconnect-MicrosoftTeams

In the next blog i will explain how to use the other commands to manage your Teams.

Powershell Enable / Disable / Set / Show Windows Web Proxy

I’m currently working for a company where I have to set up a web proxy to connect my laptop to the Internet. Because I’m a little bit lazy to enable/disable this every morning when i come in, or when i open my laptop at home, i use these two oneliners in powershell:

EnableProxy:

set-itemproperty 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Internet Settings' -name ProxyEnable -value 1

DisableProxy:

set-itemproperty 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Internet Settings' -name ProxyEnable -value 0

Complete Script:

I also created a simple menu script with all the options to Enable, Disable, Set and Show. You can download the script from Technet Gallery
If you have any questions or suggestions, please let me now 🙂

Execution of Scripts is Disabled on this System

When you try to run a powershell script on Windows, you may receive the following error stating that the execution policy on your computer does not allow you to run the script.

To fix this error, you must change the PowerShell execution policy for this computer.  These instructions will explain how to allow “Unrestricted” access to running scripts on your computer.

  1. To set the execution policy to unrestricted, enter the following command (PowerShell must be run as an Administrator):
    1. Set-ExecutionPolicy Unrestricted
  2. You will receive a warning indicating that you are trying to change the execution policy and the risk that is associated with the change.  Enter ‘Y’ and press enter.
  3. Your execution policy is now changed.  You can verify this by executing the command “Get-ExecutionPolicy”.  You can now try to run your script again and you should not receive any errors.

Powershell Backup Script

Needed a backup script which i can run from the powershell or with use of the Windows schedular.

I’ve created some checks on folders and succesrate. The scripts also can email you when backup is succesful/failed.

If you have any suggestions please let me know!

##################################### Backup Script ###############################################
## Name: Backup_Script.ps1                               
## Creator: Erwin Bierens                     
## CreationDate: 10-02-2017                               
## LastModified: 10-02-2017                                
## Version: 1.0
## Website: https://erwinbierens.com/powershell-backup-script
## 
## Description: Copies the Backupdir to the Destination folder
## Deviations will be written to logfile
## Only Change Variables in Variables Section  
##
## Thx to the followingg scripts i created this one, source information
## http://www.krist-online.nl/index.php/scripts/14-robocopy-powershell-wekelijks-backup-schema
## https://blog.sat.iit.edu/2011/11/backup-script-using-robocopy-and-powershell/
## 
##
## Example: powershell -command "& 'c:\temp\Backup_Script.ps1' "
## 
####################################################################################################

####################
##Variables Section
####################

## Source directory
$source="C:\Temp\Backup\A"
 
## Destination Directory
## you can also use the network path "\\server\share"
$destination="C:\Temp\Backup\B\"
 
## Destination Log File
$logfile="c:\temp\backup\logbestand.txt"
 
## BackupRapport is being used to check if backup is succesfull
$backupReport="c:\temp\logfile_backup.txt"
 
## Make changes for email reports
$EmailFrom="backupscript@bierens.it"
$EmailTo="erwin@bierens.it"
$SMTPServer="192.168.178.32"

## Email Subjects and Body info
$successEmailSubject="Backup Succesfull"
$successEmailBody="The Backup is succesfull"
$failEmailSubject="Backup Failed"
$failEmailBody="The backup is failed, please check the attached log file"

## =========================================================
## =========== DONT CHANGE PARAMETERS BELOW ================
## =========================================================

## Check if destination exists, if no create folder
if (!(Test-Path -path $destination))
{
New-Item $destination -type directory
}
 
## robocopy command
## /XO Excludes older files.
## /COPY:DATSO Specifies the file properties to be copied. D Data, A Attributes, T Time stamps, S NTFS access control list (ACL), O Owner information
## /E /Purge Mirrors a directory tree
## /R:10 Specifies the number of retries on failed copies. The default value of N is 1,000,000 (one million retries)
## /log: Writes the status output to the log file (overwrites the existing log file). use /log+: for appending 
## /NP Specifies that the progress of the copying operation (the number of files or directories copied so far) will not be displayed.
robocopy $source $destination *.* /XO /COPY:DATSO /E /purge /R:10 /log:$logfile /NP
 
## Check variables to compare source and destination
$check_source = Dir $source
$check_destination = Dir $destination
 
## Compare source and destination, write deviations to backup report 
Compare-Object $check_source $check_destination -PassThru > $backupReport
 
## Create and send email after succesfull backup
function sendSuccessEmail{
send-mailmessage -from $EmailFrom -to $EmailTo -subject $successEmailSubject -body $successEmailBody -Attachments "$logfile" -priority High -dno onSuccess, onFailure -smtpServer $SMTPServer
}
 
## Create and send email after unsuccesfull backup
function sendFailEmail{
send-mailmessage -from $EmailFrom -to $EmailTo -subject $failEmailSubject -body $failEmailBody -Attachments "$logfile" -priority High -dno onSuccess, onFailure -smtpServer $SMTPServer
}
 
## If backupreport is empty, backup is succesfull send email
$File = Get-ChildItem $backupReport
if ($File.Length -eq 0) {sendSuccessEmail}
 
## If backup report is not empty, something is going wrong. Email will be send
$File = Get-ChildItem $backupReport
if ($File.Length -gt 0) {sendFailEmail}
#EOF

Powershell Cheatsheet

Getting crazy from all the site’s on the internet for Powershell commands, combining these sites on this cheat page

Some randon cheat sheets on the internet