Category Archives: Scripts

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]

 

Who am I – VB Script

‘ This script returns the following details on the local computer:

1. IP address

2. Computer name

3. Last reboot time

4. user name

image

I compiled it to exe and push it to all the workstations using GPO

It looks like this

image

Copy and save as vbs file:

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

 

Function WMIDateStringToDate(dtmBootup)
WMIDateStringToDate = CDate(Mid(dtmBootup, 5, 2) & “/” & _
Mid(dtmBootup, 7, 2) & “/” & Left(dtmBootup, 4) _
& ” ” & Mid (dtmBootup, 9, 2) & “:” & _
Mid(dtmBootup, 11, 2) & “:” & Mid(dtmBootup, _
13, 2))
End Function
Dim NIC1, Nic, StrIP, CompName, objWMIService, colOperatingSystems, dtmBootup,  dtmLastBootupTime

Set NIC1 = GetObject(“winmgmts:”).InstancesOf(“Win32_NetworkAdapterConfiguration”)

For Each Nic in NIC1

if Nic.IPEnabled then

StrIP = Nic.IPAddress(i)

Set WshNetwork = WScript.CreateObject(“WScript.Network”)

CompName= WshNetwork.Computername
end If

Next

Set objWMIService = GetObject(“winmgmts:” & strComputer & “\root\cimv2”)
Set colOperatingSystems = objWMIService.ExecQuery(“Select * from Win32_OperatingSystem”)
For Each objOS in colOperatingSystems
dtmBootup = objOS.LastBootUpTime
dtmLastBootupTime = WMIDateStringToDate(dtmBootup)

MsgBox “IP Address: “&StrIP & vbNewLine _
& “Computer Name: ” &CompName & vbNewLine _
& “Last Reboot Time: “&dtmLastBootupTime & vbNewLine _
& “User Name : “& WshNetwork.UserName
‘MsgBox “Last Reboot: ” & dtmLastBootupTime
‘MsgBox “The current user is ” & WshNetwork.UserName

wscript.quit
Next

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

Good luck סמיילי

Ping multiple computers

I came across this need  to check the availability of multiple devises by pinging them  , this script will preform ping to computers from a csv file and will create another CSV file with the computer name and true if it has ping false if it doesn’t

There are two script

1. Ping to Computer name

2. Ping to IP address

You will need to create a CSV file with the computer list and call it – “Complist.csv”

save it in the same folder with the script

the script will run on this file and create a new file called  “complist-ping.csv”

Search by Computer name  Script :

  • Copy the text and save it as VBS

Function Ping(strHost)
  Ping = False
  set objPing = GetObject("winmgmts:{impersonationLevel=impersonate}").ExecQuery("select * from Win32_PingStatus where address = ‘" & strHost & "’")
  for each objRetStatus in objPing
    if IsNull(objRetStatus.StatusCode) or objRetStatus.StatusCode<>0 then
      Ping = False
    else
      Ping = True
    end if
  next
  set objPing = nothing
End Function
 
set fs = CreateObject("Scripting.FileSystemObject")
set objfile = fs.OpenTextFile("complist.csv")
i = 0
Set mf = fs.CreateTextFile("complist-ping.csv",false)
do while not objfile.AtEndOfStream
  arr2 = split(objfile.ReadLine,",")
  if (ubound(arr2) <> -1) then
    if (left(arr2(0),1) <> ";")and(left(arr2(0),1) <> "#") then
      mf.writeline(arr2(0) & "," & cstr(Ping(arr2(0))))
      i = i + 1
    end if
  end if
Loop
objfile.close
mf.close
set objfile = nothing
 
set fs = nothing
set wa = nothing
set objEnv = nothing
set objNetwork = nothing
wscript.echo "Done " & i

Search by IP Address

  • Copy the text and save it as VBS

Function Ping(strIP)
  Ping = False
  set objPing = GetObject("winmgmts:{impersonationLevel=impersonate}").ExecQuery("select * from Win32_PingStatus where address = ‘" & strIP & "’")

  for each objRetStatus in objPing
    if IsNull(objRetStatus.StatusCode) or objRetStatus.StatusCode<>0 then
      Ping = False
    else
      Ping = True
    end if
  next
  set objPing = nothing
End Function
 
set fs = CreateObject("Scripting.FileSystemObject")
set objfile = fs.OpenTextFile("complist.csv")
i = 0
Set mf = fs.CreateTextFile("complist-ping.csv",false)
do while not objfile.AtEndOfStream
  arr2 = split(objfile.ReadLine,",")
  if (ubound(arr2) <> -1) then
    if (left(arr2(0),1) <> ";")and(left(arr2(0),1) <> "#") then
      mf.writeline(arr2(0) & "," & cstr(Ping(arr2(0))))
      i = i + 1
    end if
  end if
Loop
objfile.close
mf.close
set objfile = nothing
 
set fs = nothing
set wa = nothing
set objEnv = nothing
set objNetwork = nothing
wscript.echo "Done " & i

Good luck Smile