VBS Scripts – Drives,Printers & Fonts

Drives.vbs

'Remove Drives

ON ERROR RESUME NEXT

DIM objNetwork,colDrives,i

SET objNetwork = CREATEOBJECT("Wscript.Network")

SET colDrives = objNetwork.EnumNetworkDrives

FOR i = 0 to colDrives.Count-1 Step 2
 ' Force Removal of network drive and remove from user profile 
 ' objNetwork.RemoveNetworkDrive strName, [bForce], [bUpdateProfile]
 objNetwork.RemoveNetworkDrive colDrives.Item(i),TRUE,TRUE
NEXT

'Connect Drives

On Error Resume Next

Set objNetwork = CreateObject("WScript.Network")
Set objShell = CreateObject("Shell.Application")
brugernavn = objNetwork.UserName

' Attach Share
objNetwork.MapNetworkDrive "H:", "\\Server\Share", TRUE
objShell.NameSpace("H:").Self.Name = "Share"

' Attach User Share
objNetwork.MapNetworkDrive "U:", "\\Server\UserShare\" & brugernavn, TRUE
objShell.NameSpace("U:").Self.Name = brugernavn & "´s dokumenter"

Printers.vbs

Set objNetwork = CreateObject("WScript.Network")

on error resume next

objNetwork.AddWindowsPrinterConnection "\\Server\Printer1"
objNetwork.AddWindowsPrinterConnection "\\Server\Printer2"

objNetwork.RemovePrinterConnection "\\Server\Printer3"


objNetwork.SetDefaultPrinter "\\Server\Printer1"

FontInstall.vbs

Const FONTS = &H14&

Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell.Namespace(FONTS)
objFolder.CopyHere "\\Server\Share\Fonts\HelveticaNeueLTStd-Cn.otf"

 

Robocopy Scripts – Sync network shares

Robocopy Batch Script 

@ECHO OFF
SETLOCAL

SET _source=\\Server1\Share1
SET _dest=D:\Shares\Share2

SET _what=/ZB /E
:: /COPYALL :: COPY ALL file info
:: /ZB :: Use restartable mode; if access denied use Backup mode
:: /SEC :: copy files with SECurity
:: /E :: Copy Subfolders, including Empty Subfolders.
:: /PURGE :: Delete dest files/folders that no longer exist in source.
:: /MIR :: MIRror a directory tree - equivalent to /PURGE plus all subfolders (/E)

SET _options=/R:5 /W:5 /XO /TEE /ETA /NDL /NP 
/LOG:RoboCopyLog.txt
:: /R:n :: number of Retries
:: /W:n :: Wait time between retries
:: /LOG :: Output log file
:: /TEE :: Output to console window, as well as the log file
:: /NFL :: No file logging - don’t log file names
:: /NDL :: No dir logging - don’t log directory names

ROBOCOPY %_source% %_dest% %_what% %_options%


Robocopy Powershell Script 

# Define paths
$source = "\\Server1\Share1"
$destination = "D:\Shares\Share2"
$logFile = "$PSScriptRoot\RoboCopyLog.txt"

# Robocopy options
$robocopyOptions = "/ZB /E /R:5 /W:5 /XO /TEE /ETA /NDL /NP /LOG:`"$logFile`""

# Run Robocopy
Start-Process -FilePath "robocopy.exe" -ArgumentList "`"$source`" `"$destination`" $robocopyOptions" -Wait

# Email parameters
$EmailParams = @{
    To         = "receiver@mail.com"
    From       = "robocopy@mail.com"
    Subject    = "Robocopy Backup Completed"
    Body       = "The Robocopy backup has completed. See attached log."
    SmtpServer = "smtp.int.aller.eu"
    Port       = 25
    UseSsl     = $true
    Attachments = $logFile
}

# Send email
Send-MailMessage @EmailParams

Outlook Data File Performance

Outlook Data File Performance

If you have a large .pst or .ost file, you may experience application pauses while you perform typical operations in Outlook. These typical operations include reading email messages, moving email messages, and deleting email messages.

The following list summarizes expected behavior based on the size of your Outlook data file.

  • Up to 5 GB: This file size should provide a good user experience on most hardware.
  • Between 5 and 10 GB: This file size is typically hardware dependent. Therefore, if you have a fast hard disk and lots of RAM, your experience will be better. However, slower hard disk drives, such as drives that are typically found on portable computers or early-generation solid-state drives (SSDs), experience some application pauses when the drives respond.
  • More than 10 GB: When the .ost file reaches this size, short pauses begin to occur on most hardware.
  • Very large (25 GB or larger): An .ost file of this size increases the frequency of short pauses, especially while you are downloading new email messages. However, you can use Send/Receive groups to manually sync your mail. For more information about Send/Receive groups, see the “Are you synchronizing many RSS feeds?” section.

Office 365 – Setting Default Calendar Permissions To Reviewer For All Users

Step 1: Connect to Exchange Online using PowerShell

$Credential = Get-Credential
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $Credential -Authentication Basic -AllowRedirection
Import-PSSession $Session

Step 2: Generate a list of all mailboxes

$users = Get-Mailbox -Resultsize Unlimited

Step 3: Set Default access to Reviewer for all User mailboxes

foreach ($user in $users) {
Write-Host -ForegroundColor green “Setting permission for $($user.alias)…”
Set-MailboxFolderPermission -Identity “$($user.alias):\calendar” -User Default -AccessRights Reviewer
}

?: if the command says “Action can not be performed, because … was not found.”
It is because the user has changed language and you should run the command again, but substitute “\calendar with the language equivilant.

Step 4: Generate a list of all Room mailboxes

$users = Get-Mailbox -Resultsize Unlimited | Where {$_.ResourceType -eq “Room”} | Select -ExpandProperty Alias

Step 5: Set Default access to Reviewer for all Room mailboxes

foreach ($user in $users) {
Write-Host -ForegroundColor green “Setting permission for $($user.alias)…”
Set-MailboxFolderPermission -Identity “$($user.alias):\calendar” -User Default -AccessRights Reviewer
}

?: if the command says “Action can not be performed, because … was not found.”
It is because the user has changed language and you should run the command again, but substitute “\calendar with the language equivilant.

Outlook – Error “The name of the security certificate is invalid or does not match the name of the site.”

Problem
Seen in Outlook when connecting to a mailbox on an Exchange Server, its caused by using a self signed certificate OR a purchased certificate, where the internal and external names are different.

 

Solution
1. On the Exchange Server > Start > All Programs > Microsoft Exchange Server {version} > Exchange Management Console.
Exchange 2016
Set-ClientAccessService -Identity <server> -AutoDiscoverServiceInternalUri https://mail.mydomain.com/autodiscover/autodiscover.xml

Set-OwaVirtualDirectory -Identity "<server>\OWA (Default Web Site)" -ExternalUrl https://mail.mydomain.com/owa -InternalUrl https://mail.mydomain.com/owa

Set-EcpVirtualDirectory -Identity "<server>\ECP (Default Web Site)" -ExternalUrl https://mail.mydomain.com/ecp -InternalUrl https://mail.mydomain.com/ecp

Set-WebServicesVirtualDirectory -Identity "<server>\EWS (Default Web Site)" -ExternalUrl https://mail.mydomain.com/EWS/Exchange.asmx -InternalUrl https://mail.mydomain.com/EWS/Exchange.asmx

Set-ActiveSyncVirtualDirectory -Identity "<server>\Microsoft-Server-ActiveSync (Default Web Site)" -ExternalUrl https://mail.mydomain.com/Microsoft-Server-ActiveSync -InternalUrl https://mail.mydomain.com/Microsoft-Server-ActiveSync

Set-OabVirtualDirectory -Identity "<server>\OAB (Default Web Site)" -ExternalUrl https://mail.mydomain.com/OAB -InternalUrl https://mail.mydomain.com/OAB

Set-MapiVirtualDirectory -Identity "<server>\mapi (Default Web Site)" -ExternalUrl https://mail.mydomain.com/mapi -InternalUrl https://mail.mydomain.com/mapi

Set-ClientAccessServer -Identity <server> AutoDiscoverServiceInternalUri https://mail.mydomain.com/Autodiscover/Autodiscover.xml

Set-OutlookAnywhere -Identity "<server>\RPC (Default Web Site)" -ExternalHostname mail.mydomain.com -InternalHostname mail.mydomain.com -ExternalClientsRequireSsl $true -InternalClientsRequireSsl $true -DefaultAuthenticationMethod NTLM
Exchange 2010 and SBS 2011 (change the values in red)

Set-ClientAccessServer -Identity EXCHANGE-MAIL -AutodiscoverServiceInternalUri https://mail.publicdomain.co.uk/autodiscover/autodiscover.xml

Set-WebServicesVirtualDirectory -Identity “EXCHANGE-MAIL\EWS (Default Web Site)” –InternalUrl https://mail.publicdomain.co.uk/EWS/Exchange.asmx

Set-OABVirtualDirectory -Identity “EXCHANGE-MAIL\OAB (Default Web Site)” -InternalURL https://mail.publicdomain.co.uk/OAB

Set-ActiveSyncVirtualDirectory -Identity “EXCHANGE-MAIL\Microsoft-Server-ActiveSync (Default Web Site)” -InternalURL https://mail.publicdomain.co.uk/Microsoft-Server-Activesync

Outlook Anywhere Note

If you intend to use Outlook Anywhere, you may also want to execute the following command. Particularly if you use SBS, which has a habit of setting remote.publicdomain.com as the default outside name.

Set-WebServicesVirtualDirectory –Identity ‘EXCHANGE-MAIL\EWS (Default Web Site)’ –ExternalUrl https://mail.publicdomain.co.uk/ews/exchange.asmx

Exchange 2007 (change the values in red)

Set-ClientAccessServer -Identity EXCHANGE-MAIL -AutodiscoverServiceInternalUri https://mail.publicdomain.co.uk/autodiscover/autodiscover.xml

Set-WebServicesVirtualDirectory -Identity “EXCHANGE-MAIL\EWS (Default Web Site)” -InternalUrl https://mail.publicdomain.co.uk/ews/exchange.asmx

Set-OABVirtualDirectory -Identity “EXCHANGE-MAIL\oab (Default Web Site)” -InternalUrl https://mail.publicdomain.co.uk/oab

Set-UMVirtualDirectory -Identity “EXCHANGE-MAIL\unifiedmessaging (Default Web Site)” -InternalUrl https://mail.publicdomain.co.uk/unifiedmessaging/service.asmx
For Small Business Server 2008
For SBS 2008 the commands are Different! (the following commands are for Exchange 2007 on SBS 2008 ONLY;

Set-ClientAccessServer -Identity EXCHANGE-MAIL -AutodiscoverServiceInternalUri https://mail.publicdomain.co.uk/autodiscover/autodiscover.xml

Set-WebServicesVirtualDirectory -Identity “EXCHANGE-MAIL\EWS (SBS Web Applications)” -InternalUrl https://mail.publicdomain.co.uk/ews/exchange.asmx

Set-OABVirtualDirectory -Identity “EXCHANGE-MAIL\oab (SBS Web Applications)” -InternalUrl https://mail.publicdomain.co.uk/oab

et-UMVirtualDirectory -Identity “EXCHANGE-MAIL\unifiedmessaging (SBS Web Applications)” -InternalUrl https://mail.publicdomain.co.uk/unifiedmessaging/service.asmx
Note: where EXCHANGE-MAIL is internal and mail.publicdomain.co.uk is external name

2. Then open the IIS Manager Expand Application Pools > MSExchangeAutodiscoverAppPool > Right Click > Recycle.
Note: You may have to enter the FQDN of the server rather than its Netbios name!!

Outlook – Manually Set up Office 365

Outlook 2013 (PC) Manually Set up for Office 365

Follow these instructions to do so:

1. Go to Control Panel, and click Mail.
2. Click Show Profiles and then click Add.
3. Type in a friendly name for the profile, and click OK.
4. Click to select the Manual setup, and click Next.
5. Click Microsoft Exchange, and then click Next.
6. In the Server box, enter outlook.office365.com.
7. Make sure that the Use Cached Exchange Mode option is selected.
8. In the User Name box, type your name (Eg; ‘John Smith’) and then click More Settings.
9. Click the Security tab, make sure ‘Encryption’ box is unticked and choose Anonymous Authentication.
10. Click the Connection tab.
11. Make sure that the Connect to Microsoft Exchange using HTTP check box is selected, and then click Exchange Proxy Settings.
12. In the ‘Use this URL to connect to my proxy server for Exchange’ box, enter:outlook.office365.com
13. Make sure that the ‘Only connect to proxy servers that have this principal name in their certificate’ check box is selected, and enter: msstd:outlook.com
14. Click both ‘On fast networks, connect using HTTP first, then connect using TCP/IP check box, and ‘On slow networks, connect using HTTP first, then connect using TCP/IP’ check boxes.
15. Under Proxy authentication settings, click Basic Authentication.
16. Click OK twice.
17. Click Check Name. You will be prompted to login. Enter your VUW login ID followed by @staff.vuw.ac.nz (Eg; smithjo@staff.vuw.ac.nz). Tick the box for ‘Remember my credentials’ .
18. When the server name and the user name are displayed with an underline, click Next.
18. Click Finish.