Category Archives: PowerShell Scripts

List Users from BookInPolicy on a room mailbox.

We can use below command to get the list of users from BookInPolicy on a resource mailbox.

Get-CalendarProcessing User@domain.com | select -ExpandProperty BookInPolicy | Get-Recipient | select PrimarySmtpAddress, RecipientType

If you have multiple Room Mailboxes to check, you can use below script.

Save all room mailbox in RoomMailbox.txt [One mailbox per line] and run the below command.

$RoomList = Get-Content C:\Temp\RoomMailbox.txt
Foreach ($room in $RoomList)
{
#$BookInPolicy = 0
$BookInPolicy = Get-CalendarProcessing $room | select -ExpandProperty BookInPolicy | Get-Recipient | select PrimarySmtpAddress, RecipientType
Write-Host "Room $room has below users"
$BookInPolicy
Write-Host "        "
Write-Host "........"
}

PowerShell Script To Send Message To Network Computer(s)

Some time back, we had a requirement to send a text message to all the client computers to inform about some activity.

I have created a this script which can send a POP UP MESSAGE to the computer(s). When you run the script it will simply prompt for inputs, and at the time of finish it will show you all the statistics.

The script can accept a single computer name or multiple computer names separated with comma (,) or path of txt file containing computers’ name, one in each line.

When you run this script it will ask you for below Input.

Message :- Type your message which you want to send to the computers. Like Hi, “Hello, Update are being installed on your computer, pleas wait” Etc.

Computer Name: – Type the computer name to which you want to send the message, if you type PC1, it will send message to PC1 computer.

You can type multiple computer names separated by the comma “,”. PC1, PC2, PC3 or you can give the path of the txt file which should have one computer name in each line.

Time :- Time :- Type time in SECONDS, duration till message pop up will remain on computer. After this time, the message pop up will disappear.

Like if you provide 5 in time prompt, the pop up will remain till 5 seconds on user’s desktop.

You can Download the script from here, or copy the below code and save as “.PS1” file.

<# Script to send message to Client computers using MSG utility.
The script will prompt you to enter the following information.
Message :-  Type your message which you want to send to the computers. Like "Your computer is pending reboot after Windows updates, please reboot.."
Computer Name :- Type the computer name to which you want to send the Message, if you type PC1, it will send message to PC1 computer.
You can type multiple computer names separated by the comma “,” like PC1, PC2, PC3 or you can give the path of the txt file with computer names, one in each line.
Like below.
PC1
PC2
PC3

Time :- Type time in SECONDS, duration till message pop up will remain on computer. After this time, the message pop up will disappear.
For example if you provide 5 in time prompt, the pop up will remain till 5 seconds on user’s desktop.
#>

# Variable declaration
$Start_Time       =       Get-Date -Format T
$logFile          =       ‘Not_Reachable_PCs.txt’
$Message          =       Read-Host -Prompt “Type Your Message Here”      
$ComputerName     =       Read-Host -Prompt “Type Computer Name Here”    
$Time             =       Read-Host -Prompt “Type Time Here” 
$Session          =       “*”
$ComputerName     =       $ComputerName -split ‘,’

if ($ComputerName -match “:”)

                      {
                      $Path = $ComputerName
                      $ComputerName = Get-Content $path
          }
                      $Total = $ComputerName.count 
                                foreach ($Computer in $ComputerName )
                                                {
                                                             if (Test-Connection -ComputerName $Computer -Count 1 -ErrorAction 0)
                                {
                                                                Write-Host “Sending Message to $Computer…….” -ForegroundColor yellow
                                msg $Session /Server:$Computer /Time:$Time $Message
                                                                Write-Host “Message Successfully Sent to $Computer” -ForegroundColor Green
                                                                }
                                                                else
                                                                                {

                                                                Out-File -FilePath $logFile -InputObject $Computer -Append -Force

                                                                                                Write-Host “$Computer is not Reachable…” -ForegroundColor red

                                                                                }

                                                }

        $Not_Reachable_Count  = @(Get-Content $logFile).count
        $End_Time   =    Get-Date -Format T
        $Minute = (New-TimeSpan -Start $Start_Time -End $End_Time).Minutes
        $Second = (New-TimeSpan -Start $Start_Time -End $End_Time).Seconds
        Write-Host Start at $Start_Time, End At $End_Time, Took About $Minute Minutes $seconds Seconds
        Write-Host “Total $Total Computer Processed, $Not_Reachable_Count computers were offline. The list is stored in $logFile” -ForegroundColor white