Tag Archives: Powershell

Powershell Form – Send Encrypted PDF Form

Due to recent changes in global privacy and data protection laws ( GDPR & Israeli Privacy Law)

I had to find a quick and easy  way to send encrypted PDF files by email.
So, after 6 hours of searching and writing i finally managed to create a workaround

At first I found this Password Protect PDF document script:  https://efcomputer.net.au/blog/password-protect-pdf-document/ 
and i used a part of the code that responsible for encrypting the file (Thanks:) )

So the following PowerShell script will Encrypt PDF files and send them by Email.

There are two folders, one with an English based form and the other with an Hebrew based form.

It looks like this

English Form:

Hebrew Form:

Have fun 🙂

 

 

 

Teams Powershell – Create new Team and add users from CSV

לאחרונה מיקרוסופט הוציאה תמיכה  של פקודות המותאמות   ל-Teams דבר המאפשר  לאנשי ה-IT

לבצע פעולות יומיומיות פשוטות ביעילות על ידי שימוש באוטומציה.

בעזרת הפקודות נוכל לבצע פעולות כמו:

  • יצירת צוותים חדשים
  • ערוצים חדשים בקבוצה
  • הוספת  והסרה מספר רב של חברים
  • הגדרת הרשאות

ועוד..

רשימת הפקודות המלאה:

 

 התקנת ה-Module מתבצעת על ידי הרצת הפקודה:

    install-module MicrosoftTteams 

3

התחברות ל- Teams מתבצעת על ידי הפקודה:

          Connect-MicrosoftTeams

4

Office365   של   Credentialsבהופעת חלון ההתחברות יש להתחבר עם ה

5

לאחר התחברות מוצלחת יופיע בחלון ה-PowerShell ה-Account שלכם

6_thumb[1]

על מנת לראות את כל הפקודות האפשריות ל- Module מריצים את הפקודה : Get-Command -Module MicrosoftTeams

7_thumb[1]

יצירת Team חדש :

New-Team -DisplayName “Idit Bnaya New Team” -AccessType Private

על מנת לראות את רשימת ה- Teams יש להריץ Get-Team

* שימו לב, בתוצאה הדיפולטיבית יופיע רק ה- Group ID של ה-Teams, ערך חשוב מאוד כיוון שניתן ליצור Teams באותו שם אז ה-GroupID הוא הערך החד ערכי

סקריפט ליצירת Team  חדש והוספת משתמשים מקובץ CSV

תנאים להרצת הסקריפט

1.  יש להריץ את ה-Module של Teams ולהכניס משתמש עם הרשאות מתאימות

2. יש ליצור קובץ CSV עם כותרת בשם User ומתחתיה UserPrincopalName של המשתמשים אותם רוצים להכניס ל-Team

לדוגמא:

8_thumb

3 יש לשמור את הסקריפט לקובץ Ps1 או להריץ עם ISE

4. הסקריפט מקפיץ Inputbox שבו מכניסים את שם ה-Team

בהצלחה wlEmoticon-smile[2]

_________________________________________________________

<#Beginning#>

<#########################################################################

.DESCRIPTION

Create A new team and add members from CSV file

.INPUTS

Team Name

.OUTPUTS

Create a csv file with a list of the users (for log)

.NOTES

Written By: Idit Bnaya

Personal Blog (English): https://www.itblog.co.il

Microsoft Blog (Hebrew): https://blogs.microsoft.co.il/iditbna

############################################################################>

#InputBox

[System.Reflection.Assembly]::LoadWithPartialName(‘Microsoft.VisualBasic’) | Out-Null $TeamName = [Microsoft.VisualBasic.Interaction]::InputBox(‘Enter the team name’, ‘Team name’)

#create New Team

New-Team -DisplayName $TeamName -AccessType Private

#get-team | Select-Object DisplayName,GroupId (for test)

#Import Users from CSV file

$TeamsUsers = Get-Content -Path c:\temp\TeamsUsersinput.csv

#Save The GroupID of the New Team in a varaiable

$groupID = Get-Team | ?{$_.DisplayName -eq $TeamName} |select GroupId

# Add the Users from the CSV file to the new Team we created

ForEach ($user in $TeamsUsers) {

add-teamuser -user $user -GroupId $groupID.GroupId}

#Export The Result to a CSV File

Get-TeamUser -groupid $groupID.GroupId |export-csv -Path c:\temp\”teamusers-$($TeamName)”.csv –NoTypeInformation

<#End#>

 9_thumb[198]

 

Exchange 2010: Get-MailboxDatabase -Status for Whitespace

In exchange 2010, event id 1221 does not exist anymore, and in order for us to find the whitespace, Microsoft has provided an appropriate command shell:
Get-MailboxDatabase -Status |ft name,databasesize,availablenewmailboxspace -auto

image

image

How to set all virtual directories at once With PowerShell

For internal URLs:

$urlpath = Read-Host "Type internal Client Access FQDN starting with http:// or https://"

Set-ClientAccessServer –Identity * –AutodiscoverServiceInternalUri “$urlpath/autodiscover/autodiscover.xml”
Set-webservicesvirtualdirectory –Identity * –internalurl “$urlpath/ews/exchange.asmx”
Set-oabvirtualdirectory –Identity * –internalurl “$urlpath/oab”
Set-owavirtualdirectory –Identity * –internalurl “$urlpath/owa”
Set-ecpvirtualdirectory –Identity * –internalurl “$urlpath/ecp”
Set-ActiveSyncVirtualDirectory -Identity * -InternalUrl "$urlpath/Microsoft-Server-ActiveSync"

External URLs:

Set-ClientAccessServer –Identity * –AutodiscoverServiceExternalUri “$urlpath/autodiscover/autodiscover.xml”
Set-webservicesvirtualdirectory –Identity * -ExternalUrl “$urlpath/ews/exchange.asmx”
Set-oabvirtualdirectory –Identity * –ExternalUrl “$urlpath/oab”
Set-owavirtualdirectory –Identity * –ExternalUrl “$urlpath/owa”
Set-ecpvirtualdirectory –Identity * –ExternalUrl “$urlpath/ecp”
Set-ActiveSyncVirtualDirectory -Identity * -ExternalUrl "$urlpath/Microsoft-Server-ActiveSync

save it as a .ps1 extension and run it in Exchange Management Shell

Office365 – Enable or disable IMAP, POP, OWA, MAPI, or Exchange ActiveSync for a mailbox

Enable or disable IMAP, POP, OWA, MAPI, or Exchange ActiveSync for a mailbox in Exchange Server in office365

1. Connect to office365 PowerShell  –

https://www.itblog.co.il/how-to-connect-remote-powershell-to-the-office365s-cloud-based-organization/

2. To see the current state for the mailbox – type : Get-CASMailbox -Identity “Mailbox identity”

(Where mailbox identity is the mailbox name)

clip_image002

3. To Disable one of the services type:

Set-CASMailbox -Identity idit -OWAEnabled $False

clip_image004

To enable on of the services type

Set-CASMailbox -Identity idit -OWAEnabled $True

image

To enable\disable service for all mailboxes type:

Get-CASMailbox |Set-CASMailbox -OWAEnabled $False

image

Check:

image

Office 365 – Manage licenses – ADD\Remove

1. Assign License Using the office365 portal · From the office365 Portal · Connect to – Office365 Portal with the right permissions (Or global administrator or User management administrator) · In the left section Go to the Users and Groups · Search for the user using the Magnifying glass clip_image002 · Press on the user · In the Licenses page – Check the relevant license

clip_image004

· If you did not provide the user location you will be redirected to the settings page clip_image006 ·Add the User location __________________________________________________________________________________________________ 2. Assign License to individual users Using Microsoft Online Services Module for Windows PowerShell

  • Connect to “Microsoft Online Services Module for Windows PowerShell

*In order to do that you will need to download and install this PowerShell , you can find the download in Here

  Alternatively, you can load the cmdlets manually by typing “import-module MSOnline” at the Windows PowerShell command prompt.

  • Type : Connect-msolservice
  • Enter the credentials of a user with the appropriate permissions (Or global administrator or User management administrator )
  • Get the name of the license Get-MsolAccountSku
clip_image008

 

  • Now you need to add the location for the user you whish to assign license to  (In my case the location is IL):

Get-MsolUser -UserPrincipalName idit@Domain.com |Set-MsolUser -UsageLocation “IL”

  • The next step will be to assign the license :

Get-MsolUser -UserPrincipalName idit@Domain.com | Set-MsolUserLicense -AddLicenses Domain:ENTERPRISEPACK

clip_image010

___________________________________________________________________________________________________________________________________________ 3. Assign license to multiple users with a powershell script Sometimes you need to assign licenses to multiple users , in this case you can do it with a very simple PowerShell script This script will :

· import the users from a csv file (which you create) ,

· provide the location

· assign the license

So the first thing you need to do is to add the Users UPN  of the users to a Csv file In the header of the table write– display Foe example : image Copy the following Lines to a Text file an save it as .SP1 $licenses = Import-Csv c:\temp\users.csv $licenses | ForEach-Object {get-msoluser  -MaxResults 20 -SearchString $_.display | Set-MsolUser -UsageLocation “IL”} $licenses | ForEach-Object {get-msoluser  -MaxResults 20 -SearchString $_.display | Set-MsolUserLicense –AddLicenses  Domain:ENTERPRISEPACK} (Don’t forget to run the script with the Microsoft Online Services Module for Windows PowerShell) Remove license to multiple users with a powershell script ___________________________________________________________________________________________________________________________________________ Create the csv file for the users you want to delete the license . again , write display in the header of the table on the Microsoft Online Services Module for Windows PowerShell type: 1. $licenses = Import-Csv d:\users1.csv 2. $licenses | ForEach-Object {get-msoluser – MaxResults 1000 -SearchString $_.display | Set-MsolUserLicense –RemovedLicenses Domain:ENTERPRISEPACK}     ________________________________________________________________________________________________________ Add license to all users without license

Import-Module MSOnline Connect-MsolService Get-MsolUser -all | where {-not $_.islicensed} |ForEach-Object{

Set-MsolUser -UserPrincipalName $_.UserPrincipalName -UsageLocation “IL”

Set-MsolUserLicense -UserPrincipalName $_.UserPrincipalName -AddLicenses Domain:ENTERPRISEPACK

}

________________________________________________________________________________________

Remove specific license

Connect-MsolService

$license= “Domain:ENTERPRISEPACK”

get-MsolUser -all | Where-Object {$_.Licenses.AccountSkuID -eq $license}|ForEach-Object{

Set-MsolUserLicense –UserPrincipalName $_.UserPrincipalName –RemoveLicenses “$license”

Write-host $_.UserPrincipalName

}

__________________________________________________

Export list of all users with license:

Get-MSOLUser -All | select userprincipalname,islicensed,{$_.Licenses.AccountSkuId}| Export-CSV D:\userlist3.csv -NoTypeInformation

 

 

 

q         Good Luck  Smile

Powershell error : “.ps1 cannot be loaded because the execution of scripts is disabled on this system”

When You are trying to run a PS1 script in Power shell you are getting the following error:

“File C:\scripts\.ps1 cannot be loaded because the execution of scripts is disabled on this system. Please see “get-

help about_signing” for more details.

At line:1 char:19

+ c:\scripts\.ps1 <<<<”

 

 

 

 

 

 

 

The security settings built into Windows PowerShell include something called the “execution policy;” the execution policy determines how (or if) PowerShell runs scripts. By default, PowerShell’s execution policy is set to Restricted; that means that scripts – including those you write yourself – won’t run.

You can see it by runnig to command: Get- ExecutionPolicy

As you can see , Its restricted

 

 

 

 

 

For enabling it just run :

Set-ExecutionPolicy -ExecutionPolicy Unrestricted

Now you can run your PS1 script

*Note: the unrestricted option will allow  All scripts from all sources can be run without signing

A safer option will be tp run

Set-ExecutionPolicy -ExecutionPolicy RemoteSigned