Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function New-RemoteConferenceRoom {
- [CmdletBinding()]
- param (
- [parameter(Mandatory=$true,ValueFromPipelineByPropertyName =$true)]
- [ValidateNotNullOrEmpty()]
- [string] $name,
- [parameter(Mandatory=$false,ValueFromPipelineByPropertyName =$true)]
- [ValidateNotNullOrEmpty()]
- [ValidateSet("Yes", "No","Y","N")]
- [string] $VC = "No",
- [parameter(Mandatory=$false,ValueFromPipelineByPropertyName =$true)]
- [ValidateNotNullOrEmpty()]
- [ValidateSet("Yes", "No","Y","N")]
- [string] $LCD = "No",
- [parameter(Mandatory=$false,ValueFromPipelineByPropertyName =$true)]
- [ValidateNotNullOrEmpty()]
- [ValidateSet("Yes", "No","Y","N")]
- [string] $phone = "Yes",
- [parameter(Mandatory=$false,ValueFromPipelineByPropertyName =$true)]
- [ValidateNotNullOrEmpty()]
- [ValidateSet("Yes", "No","Y","N")]
- [string] $whiteboard = "Yes",
- [parameter(Mandatory=$false,ValueFromPipelineByPropertyName =$true)]
- [ValidateNotNullOrEmpty()]
- [ValidateSet("Yes", "No","Y","N")]
- [string] $projector = "No",
- [parameter(Mandatory=$true,ValueFromPipelineByPropertyName =$true)]
- [ValidateNotNullOrEmpty()]
- [string] $location,
- [parameter(Mandatory=$true,ValueFromPipelineByPropertyName =$true)]
- [ValidateNotNullOrEmpty()]
- [Alias("Building ID")]
- [string] $buildingID,
- [parameter(Mandatory=$true,ValueFromPipelineByPropertyName =$true)]
- [ValidateNotNullOrEmpty()]
- [Alias("Seat Capacity")]
- [int] $seatCapacity,
- [parameter(Mandatory=$false,ValueFromPipelineByPropertyName =$true)]
- [Alias("Phone Number")]
- [string] $phoneNumber,
- [parameter(Mandatory=$true,ValueFromPipelineByPropertyName =$true)]
- [ValidateNotNullOrEmpty()]
- [Alias("Zip Code")]
- [string] $zipcode,
- [parameter(Mandatory=$true,ValueFromPipelineByPropertyName =$true)]
- [ValidateNotNullOrEmpty()]
- [string] $city,
- [parameter(Mandatory=$true,ValueFromPipelineByPropertyName =$true)]
- [ValidateNotNullOrEmpty()]
- [string] $address,
- [parameter(Mandatory=$true,ValueFromPipelineByPropertyName =$true)]
- [ValidateNotNullOrEmpty()]
- [string] $state,
- [parameter(Mandatory=$true,ValueFromPipelineByPropertyName =$true)]
- [ValidateNotNullOrEmpty()]
- [string] $country,
- [parameter(Mandatory=$true,ValueFromPipelineByPropertyName =$true)]
- [ValidateNotNullOrEmpty()]
- [ValidateSet("Reservable", "Non-reservable")]
- [string] $status,
- [parameter(Mandatory=$false,ValueFromPipelineByPropertyName =$true)]
- [ValidateNotNullOrEmpty()]
- [bool] $HideFromAddressBook= $false
- )
- Try {
- #Room/Videoconference, Room/LCD, Room/Phone, Room/Whiteboard,
- #Room/Projector
- #Construct a string that contains the things in the room.
- $roomResources = ""
- $exRoomResources = @()
- if ($WhiteBoard -like "Y*") {
- $roomResources += "WB"
- $exRoomResources += "Whiteboard"
- }
- if ($Phone -like "Y*") {
- $roomResources += "/PH"
- $exRoomResources += "Phone"
- }
- if ($VC -like "Y*") {
- $roomResources += "/VC"
- $exRoomResources += "VideoConference"
- }
- if ($LCD -like "Y*") {
- $roomResources += "/LCD"
- $exRoomResources += "LCD"
- }
- if ($Projector -like "Y*" ) {
- $roomResources += "/Projector"
- $exRoomResources += "Projector"
- }
- #Let's target a reachable DC in DC1-EXC for entire transaction
- $dc = Get-ADDomainController -ForceDiscover -Discover -Site 'DC1-EXC' |
- select -expand hostname
- if (-not($dc)) {
- $dc = Get-ADDomainController -ForceDiscover -Discover -Site 'DC2-EXC' |
- select -expand hostname
- }
- [Reflection.Assembly]::LoadWithPartialName("System.Web") | Out-Null
- $password = [System.Web.Security.Membership]::GeneratePassword(20,2) |
- ConvertTo-SecureString -AsPlainText -Force
- $mylocation = $location.split(".")[0]
- $DisplayName = "[" + $BuildingID + "." + $myLocation + "] " `
- + $Name + " (" + $status + " Seats " `
- + $seatCapacity + " $roomResources)"
- #derive the samaccount name (and the email address)
- #based on the location and building ID.
- $samaccountname = (($buildingid + $location).replace(".","")).trim()
- $upn = "$($samaccountname)@mydomain.com"
- $groupOU = "mydomain.com/mydomain dl's/conferenceroomcontrols"
- #create 2 groups. One group will be the bookinpolicy members.
- $Settings = @{
- 'organizationalunit' = $groupOU;
- 'DomainController' = $dc;
- }
- $bookName = $samaccountname + "Booking"
- if (!(Get-DistributionGroup $bookName -ea 'silentlycontinue')) {
- $Settings.Name = "$samaccountname Booking";
- $Settings.SamAccountName = $samaccountname + "Booking";
- New-DistributionGroup @Settings
- }
- #the other group will be the set of users with advanced viewing rights.
- $viewName = $samaccountname + "View"
- if (!(Get-DistributionGroup $viewName -ea 'silentlycontinue')) {
- $Settings.Name = "$samaccountname Viewing";
- $Settings.SamAccountName = $samaccountname + "View";
- New-DistributionGroup @Settings
- }
- $roomOU = "mydomain.com/conference rooms"
- $roomSplat = @{
- 'OnPremisesOrganizationalUnit' = $roomOU;
- 'Identity' = $samaccountname;
- 'DomainController' = $dc;
- 'ErrorAction' = 'silentlycontinue'
- }
- if (!(Get-RemoteMailbox @roomSplat)) {
- $myRoomSettings = @{
- 'Alias' = $samAccountName.trim();
- 'DisplayName' = $DisplayName;
- 'OnPremisesOrganizationalUnit' = $roomOU;
- 'DomainController' = $dc;
- 'Password' = $password;
- 'Name' = $name.trim();
- 'FirstName' = $name.trim();
- 'samaccountname' = $samaccountname.trim();
- 'UserPrincipalName' = $upn;
- 'RemoteRoutingAddress' = "$($samAccountName.trim())@mydomain.mail.onmicrosoft.com";
- 'ErrorAction' = "Stop";
- }
- New-RemoteMailbox @myRoomSettings
- }
- else {
- Write-Output "$DisplayName already exists"
- }
- $ToReplace = @{
- 'extensionattribute4' = "$exRoomResources";
- 'houseidentifier' = "$BuildingID"
- }
- $myRoomSetUser = @{
- 'Identity' = $samAccountName.trim();
- 'employeeNumber' = "999999999999"
- 'Office' = $Location;
- 'Country' = $Country;
- 'City' = $city;
- 'PostalCode' = $ZipCode;
- 'StreetAddress' = $Address;
- 'State' = $State;
- 'OfficePhone' = $phoneNumber;
- 'Server' = $dc;
- 'ErrorAction' = 'Stop'
- 'Replace' = $ToReplace
- }
- Set-ADUser @myRoomSetUser
- }
- Catch { $_ }
- }
Add Comment
Please, Sign In to add comment