Connect to Exchange powershell remotely

Connect to Exchange powershell remotely using the following commands

$exchCred=Get-Credential
$exchUri=”
http://servername/powershell”

$exchSession=New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri $exchUri -Authentication Kerberos -Credential $exchCred
Import-PSSession $exchSession

$exchCred is the credentials used to connect

$exchUri is the Uri of the Exchange server powershell virtual directory.  EG: http://exchange.anonit.net/powershell

 

To remove the session at the end, use Remove-PSSession $exchSession

 

See the powershell script here

 

Reference:

https://community.spiceworks.com/scripts/show/3956-connect-to-exchange-powershell-remotely

 

TFS fails to install with “Remove elasticsearch-service-x64”

Attempting to do a TFS upgrade, the install was failing with an error: “The following Windows service is installed on your computer: elasticsearch-service-x64. Remove elasticsearch-service-x64 to continue”

I was required to:

Go to the TFS Search directory and remove the search folder.

Stop the elastic search service, and navigate to the program files folder for elastic search (C:\Program Files\Microsoft Team Foundation Server 15.0\Search\ES\elasticsearch-2.4.1\bin)

Run the command service.bat remove to uninstall the Elastic Search service.

Download TFS 2017 for offline use

I was using TFS2017 on a single machine, and needed to transfer it to a new machine.  I performed a backup, installed on the new machine, and attempted to restore my backup.  At this point I found I had not been using the latest version of TFS, and couldn’t restore my backup.

I still had the installer file for the old version I was using, and was able to install, restore and then upgrade.  But this got me thinking.  If I didn’t have the old install files, I’d be in trouble.  So I found a way to download the install files for offline use in the future.

Download the web installer for TFS from https://www.visualstudio.com/tfs/

Run the installer with the following switches: /layout %PATHTOSAVE%

eg:

tfsserver2017.1.exe /layout c:\temp\tfs\installfiles

The installer will begin, and confirm the file location

image

image

image

image

image

Put the install files in a safe place in case you ever need to reinstall and you find you are not on the latest version.

You can also use the /passive switch to bypass the are you sure prompt.

Check out all the switches by using /?

Now off to go find out how to get TFS to tell me that a new update is available!

Enabling Windows Defender definitions in Windows 10 using a metered connection

When connected to a metered connection, Windows 10 won’t download updates.  This includes Windows Defender definitions.

Create a scheduled task to run the following command:

“c:\program files\windows defender\mpcmdrun.exe” –signatureupdate –mmpc

This is to run a signature update from the microsoft malware protection center (eg: Update from the internet).

The scheduled task can run as the user system, whether the user is logged in or not, and must be run with highest privileges.

If you want to test if your task is running correctly, you can run an elevated command prompt, issue the command mpcmdrun.exe -removedefinitions –all and then run the scheduled task.  This initial download may take some time as it will do a full download, not just a dynamic update.

mpcmdrun.exe /? gives the following command line options:

Microsoft Antimalware Service Command Line Utility (c) 2006-2015 Microsoft Corp
Use this tool to automate and troubleshoot Microsoft Antimalware Service

Usage:
MpCmdRun.exe [command] [-options]

Command Description
-? / -h                                    Displays all available options
for this tool
-Scan [-ScanType #] [-File <path> [-DisableRemediation] [-BootSectorScan]]
[-Timeout <days>]
Scans for malicious software
-Trace [-Grouping #] [-Level #]            Starts diagnostic tracing
-GetFiles                                  Collects support information
-RemoveDefinitions [-All]                  Restores the installed
signature definitions
to a previous backup copy or to
the original default set of
signatures
[-DynamicSignatures]    Removes only the dynamically
downloaded signatures
-SignatureUpdate [-UNC | -MMPC]            Checks for new definition updates
-Restore  [-ListAll | [-Name <name>] [-All] [-Path <path>]]  Restore or list
quarantined item(s)
-AddDynamicSignature [-Path]               Loads a dynamic signature
-ListAllDynamicSignatures                  List the loaded dynamic signatures
-RemoveDynamicSignature [-SignatureSetID]  Removes a dynamic signature

Additional Information:

Support information will be in the following directory:
C:\ProgramData\Microsoft\Windows Defender\Support

   -Scan [-ScanType value]
0  Default, according to your configuration
1  Quick scan
2  Full system scan
3  File and directory custom scan

           [-File <path>]
Indicates the file or directory  to be scanned, only valid for custom scan.

           [-DisableRemediation]
This option is valid only for custom scan.
When specified:
– File exclusions are ignored.
– Archive files are scanned.
– Actions are not applied after detection.
– Event log entries are not written after detection.
– Detections from the custom scan are not displayed in the user interface.
– The console output will show the list of detections from the custom scan.

           [-BootSectorScan]
Enables boot sector scanning; only valid for custom scan.

           [-Timeout <days>]
Timeout in days; maximum value is 30.
If this parameter is not specified, default value is 7 days for full scan and 1 day for all other scans.

      Return code is
0    if no malware is found or malware is successfully remediated and no additional user action is required
2    if malware is found and not remediated or additional user action is required to complete remediation or there is error in scanning.  Please check History for more information.

   -Trace [-Grouping value] [-Level value]
Begins tracing Microsoft Antimalware Service’s actions.
You can specify the components for which tracing is enabled and
how much information is recorded.
If no component is specified, all the components will be logged.
If no level is specified, the Error, Warning and Informational levels
will be logged. The data will be stored in the support directory
as a file having the current timestamp in its name and bearing
the extension BIN.

        [-Grouping]
0x1    Service
0x2    Malware Protection Engine
0x4    User Interface
0x8    Real-Time Protection
0x10   Scheduled actions
0x20   NIS/GAPA

        [-Level]
0x1    Errors
0x2    Warnings
0x4    Informational messages
0x8    Function calls
0x10   Verbose
0x20   Performance

   -GetFiles [-Scan]
Gathers the following log files and packages them together in a
compressed file in the support directory

        – Any trace files from Microsoft Antimalware Service
– The Windows Update history log
– All Microsoft Antimalware Service events from the System event log
– All relevant Microsoft Antimalware Service registry locations
– The log file of this tool
– The log file of the signature update helper tool

        [-Scan]
Scans for unusual files.  The files and results of the scan
will be packaged in the compressed file.

   -RemoveDefinitions
Restores the last set of signature definitions

        [-All]
Removes any installed signature and engine files. Use this
option if you have difficulties trying to update signatures.

        [-DynamicSignatures]
Removes all Dynamic Signatures.

   -SignatureUpdate
Checks for new definition updates

        [-UNC [-Path <path>]]
Performs update directly from UNC file share specified in <path>
If -Path is not specified, update will be performed directly from the
preconfigured UNC location

        [-MMPC]
Performs update directly from Microsoft Malware Protection Center

   -Restore
[-ListAll]
List all items that were quarantined

        [-Name <name>]
Restores the most recently quarantined item based on threat name
One Threat can map to more than one file

        [-All]
Restores all the quarantined items based on name

        [-Path]
Specify the path where the quarantined items will be restored.
If not specified, the item will be restored to the original path.
-AddDynamicSignature -Path <path>
Adds a Dynamic Signature specified by <path>

   -ListAllDynamicSignatures
Lists SignatureSet ID’s of all Dynamic Signatures added to the client
via MAPS and MPCMDRUN -AddDynamicSignature

   -RemoveDynamicSignature -SignatureSetID <SignatureSetID>
Removes a Dynamic Signature specified by <SignatureSetID>

 

References:

http://windowssecrets.com/forums/showthread.php/155034-Updating-Defender-automatically-without-automatic-downloads

Exchange 2013 default event log levels

Identity EventLevel
——– ———-
EX02\MSExchange ActiveSync\Requests Lowest
EX02\MSExchange ActiveSync\Configuration Lowest
EX02\MSExchange Antispam\General Lowest
EX02\MSExchange Assistants\Assistants Lowest
EX02\MSExchange Autodiscover\Core Lowest
EX02\MSExchange Autodiscover\Web Lowest
EX02\MSExchange Autodiscover\Provider Lowest
EX02\MSExchange Availability\Availability Service Lowest
EX02\MSExchange Availability\Availability Service General Lowest
EX02\MSExchange Availability\Availability Service Authentication Lowest
EX02\MSExchange Availability\Availability Service Authorization Lowest
EX02\MSExchange Cluster\Move Lowest
EX02\MSExchange Cluster\Upgrade Lowest
EX02\MSExchange Cluster\Action Lowest
EX02\MSExchange Common\General Lowest
EX02\MSExchange Common\Configuration Lowest
EX02\MSExchange Common\Logging Lowest
EX02\MSExchange RBAC\General Lowest
EX02\MSExchange RBAC\RBAC Low
EX02\MSExchange CmdletLogs\General Lowest
EX02\MSExchange Configuration Cmdlet – Management Console\General Lowest
EX02\MSExchange Configuration Cmdlet – Management Console\RBAC Lowest
EX02\MSExchange Delegated Authentication Module\General Lowest
EX02\MSExchange LiveId Redirection Module\General Lowest
EX02\MSExchange Organization Redirection Module\General Lowest
EX02\MSExchange Certificate Authentication Module\General Lowest
EX02\MSExchange Control Panel\General Lowest
EX02\MSExchange Control Panel\Performance Lowest
EX02\MSExchange Control Panel\Redirect Lowest
EX02\MSExchange Control Panel\Proxy Lowest
EX02\MSExchange Extensibility\Transport Address Book Lowest
EX02\MSExchange Extensibility\MExRuntime Lowest
EX02\MSExchange EdgeSync\Synchronization Lowest
EX02\MSExchange EdgeSync\Topology Lowest
EX02\MSExchange EdgeSync\SyncNow Lowest
EX02\MSExchange TransportService\TransportService Lowest
EX02\MSExchange Web Services\Core Lowest
EX02\MSExchange IMAP4\General Lowest
EX02\MSExchange IMAP4 BE\General Lowest
EX02\MSExchange Messaging Policies\Journaling Lowest
EX02\MSExchange Messaging Policies\AttachFilter Lowest
EX02\MSExchange Messaging Policies\AddressRewrite Lowest
EX02\MSExchange Messaging Policies\Rules Lowest
EX02\MSExchange Messaging Policies\Prelicensing Lowest
EX02\MSExchange Messaging Policies\PolicyApplication Lowest
EX02\MSExchange Messaging Policies\JournalReportDecryption Lowest
EX02\MSExchange Messaging Policies\RightsManagement Lowest
EX02\MSExchange Messaging Policies\TransportDecryption Lowest
EX02\MSExchange Messaging Policies\RedirectionAgent Lowest
EX02\MSExchange Messaging Policies\Information Rights Management Lowest
EX02\MSExchange Anti-spam Update\HygieneUpdate Lowest
EX02\MSExchange Mailbox Replication\Service Lowest
EX02\MSExchange Mailbox Replication\Mailbox Move Lowest
EX02\MSExchange Mid-Tier Storage\Xtc Lowest
EX02\MSExchange Mid-Tier Storage\Audit Lowest
EX02\MSExchange Mid-Tier Storage\Discovery Lowest
EX02\MSExchange Mid-Tier Storage\Information Rights Management Lowest
EX02\MSExchange Mid-Tier Storage\CopyOnWrite Lowest
EX02\MSExchange Mid-Tier Storage\ResourceHealth Lowest
EX02\MSExchange Management Application\Shell Lowest
EX02\MSExchange Management Application\Console Lowest
EX02\MSExchange Management Application\ProvisioningAgent Lowest
EX02\MSExchange Management Application\ComponentInfoBasedTask Lowest
EX02\MSExchange Management Application\AdminAuditLog Lowest
EX02\MSExchange OWA\FormsRegistry Lowest
EX02\MSExchange OWA\Core Lowest
EX02\MSExchange OWA\Configuration Lowest
EX02\MSExchange OWA\Themes Lowest
EX02\MSExchange OWA\SmallIcons Lowest
EX02\MSExchange OWA\Proxy Lowest
EX02\MSExchange OWA\Transcoding Lowest
EX02\MSExchange OWA\ADNotifications Lowest
EX02\MSExchange OWA\InstantMessage Lowest
EX02\MSExchange POP3\General Lowest
EX02\MSExchange POP3 BE\General Lowest
EX02\MSExchange Process Manager\ProcessManager Lowest
EX02\MSExchange Repl\Service Lowest
EX02\MSExchange Repl\Exchange VSS Writer Lowest
EX02\MSExchange ReportingWebService\General Lowest
EX02\MSExchange Topology\Topology Discovery Lowest
EX02\MSExchange Unified Messaging\UMWorkerProcess Lowest
EX02\MSExchange Unified Messaging\UMCore Lowest
EX02\MSExchange Unified Messaging\UMManagement Lowest
EX02\MSExchange Unified Messaging\UMService Lowest
EX02\MSExchange Unified Messaging\UMClientAccess Lowest
EX02\MSExchange Unified Messaging\UMCallData Lowest
EX02\MSExchange Unified Messaging\MWI General Lowest
EX02\MSExchange Unified Messaging\UMCallRouter Lowest
EX02\MSExchange ADAccess\General Lowest
EX02\MSExchange ADAccess\Cache Lowest
EX02\MSExchange ADAccess\Topology Low
EX02\MSExchange ADAccess\Configuration Lowest
EX02\MSExchange ADAccess\LDAP Lowest
EX02\MSExchange ADAccess\Validation Low
EX02\MSExchange ADAccess\Recipient Update Service Lowest
EX02\MSExchange ADAccess\Site Update Lowest
EX02\MSExchange ADAccess\Exchange Topology Lowest
EX02\MSExchange ADAccess\MSERV Lowest
EX02\MSExchange ADAccess\GLS Lowest
EX02\MSExchangeADTopology\General Lowest
EX02\MSExchangeADTopology\Configuration Lowest
EX02\MSExchangeADTopology\Topology Low
EX02\MSExchangeApplicationLogic\TextMessaging Lowest
EX02\MSExchangeApplicationLogic\ServerPicker Lowest
EX02\MSExchangeApplicationLogic\Extension Lowest
EX02\MSExchangeApplicationLogic\E4E Lowest
EX02\MSExchangeApplicationLogic\DiagnosticHandlers Lowest
EX02\MSExchangeIS\General Lowest
EX02\MSExchangeIS\Physical Access Lowest
EX02\MSExchangeIS\Lazy Indexing Lowest
EX02\MSExchangeIS\Logical Data Model Lowest
EX02\MSExchangeIS\Directory Services Lowest
EX02\MSExchangeIS\MAPI Lowest
EX02\MSExchangeIS\High Availability Lowest
EX02\MSExchangeMailboxAssistants\Service Lowest
EX02\MSExchangeMailboxAssistants\OOF Assistant Lowest
EX02\MSExchangeMailboxAssistants\OOF Library Lowest
EX02\MSExchangeMailboxAssistants\Resource Booking Attendant Lowest
EX02\MSExchangeMailboxAssistants\Email_Lifecycle_Assistant Lowest
EX02\MSExchangeMailboxAssistants\Junk Email Options Assistant Lowest
EX02\MSExchangeMailboxAssistants\Conversations Assistant Lowest
EX02\MSExchangeMailboxAssistants\Approval Assistant Lowest
EX02\MSExchangeMailboxAssistants\ELC Library Lowest
EX02\MSExchangeGlobalLocatorCache\General Lowest
EX02\MSExchangeTransport\SmtpReceive Lowest
EX02\MSExchangeTransport\SmtpSend Lowest
EX02\MSExchangeTransport\DSN Lowest
EX02\MSExchangeTransport\Routing Lowest
EX02\MSExchangeTransport\Logging Lowest
EX02\MSExchangeTransport\Components Lowest
EX02\MSExchangeTransport\RemoteDelivery Lowest
EX02\MSExchangeTransport\Pickup Lowest
EX02\MSExchangeTransport\Categorizer Lowest
EX02\MSExchangeTransport\PoisonMessage Lowest
EX02\MSExchangeTransport\MessageSecurity Lowest
EX02\MSExchangeTransport\TransportService Lowest
EX02\MSExchangeTransport\Exch50 Lowest
EX02\MSExchangeTransport\Process Lowest
EX02\MSExchangeTransport\ResourceManager Lowest
EX02\MSExchangeTransport\Configuration Lowest
EX02\MSExchangeTransport\Storage Lowest
EX02\MSExchangeTransport\Agents Lowest
EX02\MSExchangeTransport\Transport Address Book Lowest
EX02\MSExchangeTransport\Orar Lowest
EX02\MSExchangeTransport\Unused Lowest
EX02\MSExchangeTransport\ShadowRedundancy Lowest
EX02\MSExchangeTransport\Approval Lowest
EX02\MSExchangeTransport\TransportSafetyNet Lowest
EX02\MSExchangeTransport\TransportTenantAttribution Lowest
EX02\MSExchangeTransportSyncCommon\General Lowest
EX02\MSExchangeTransportSyncManager\General Lowest
EX02\MSExchangeTransportSyncWorker\General Lowest
EX02\MSExchangeTransportSyncWorkerFramework\General Lowest
EX02\MSExchange OutlookProtectionRules\Outlook Protection Rules Lowest
EX02\MSExchange Provisioning MailboxAssistant\Provisioning Assistant General Lowest
EX02\MSExchangeThrottling\General Lowest
EX02\MSExchangeThrottlingClient\General Lowest
EX02\MSExchange FailFast Module\General Lowest
EX02\MSExchange Store Driver Delivery\MSExchangeStoreDriverDelivery Lowest
EX02\MSExchange Store Driver Delivery\MeetingMessageProcessing Lowest
EX02\MSExchange Store Driver Delivery\OofHistory Lowest
EX02\MSExchange Store Driver Delivery\Approval Lowest
EX02\MSExchange Store Driver Delivery\UnifiedMessaging Lowest
EX02\MSExchange Store Driver Submission\MSExchangeStoreDriverSubmission Lowest
EX02\MSExchangeSubmission\MSExchangeSubmission Lowest
EX02\MSExchange Antimalware\General Lowest
EX02\MSExchange Antimalware\Init Lowest
EX02\MSExchange Antimalware\ScanResults Lowest
EX02\MSExchange Antimalware\ScanError Lowest
EX02\MSExchange OAuth\Requests Lowest
EX02\MSExchange OAuth\Configuration Low
EX02\MSExchange OAuth\Server 2
EX02\MSExchange BackEndRehydration\Requests Lowest
EX02\MSExchange BackEndRehydration\Configuration Low
EX02\MSExchange BackEndRehydration\Server 2
EX02\MSExchange Front End HTTP Proxy\Core Lowest
EX02\MSExchange RemotePowershell BackendCmdletProxy Module\General Lowest
EX02\MSExchange Error Logging Module\General Lowest
EX02\MSExchange Client Diagnostics Module\General Lowest
EX02\MSExchangeFrontEndTransport\SmtpReceive Lowest
EX02\MSExchangeFrontEndTransport\SmtpSend Lowest
EX02\MSExchangeFrontEndTransport\DSN Lowest
EX02\MSExchangeFrontEndTransport\Routing Lowest
EX02\MSExchangeFrontEndTransport\Logging Lowest
EX02\MSExchangeFrontEndTransport\Components Lowest
EX02\MSExchangeFrontEndTransport\RemoteDelivery Lowest
EX02\MSExchangeFrontEndTransport\Pickup Lowest
EX02\MSExchangeFrontEndTransport\Categorizer Lowest
EX02\MSExchangeFrontEndTransport\PoisonMessage Lowest
EX02\MSExchangeFrontEndTransport\MessageSecurity Lowest
EX02\MSExchangeFrontEndTransport\TransportService Lowest
EX02\MSExchangeFrontEndTransport\Exch50 Lowest
EX02\MSExchangeFrontEndTransport\Process Lowest
EX02\MSExchangeFrontEndTransport\ResourceManager Lowest
EX02\MSExchangeFrontEndTransport\Configuration Lowest
EX02\MSExchangeFrontEndTransport\Storage Lowest
EX02\MSExchangeFrontEndTransport\Agents Lowest
EX02\MSExchangeFrontEndTransport\Transport Address Book Lowest
EX02\MSExchangeFrontEndTransport\Orar Lowest
EX02\MSExchangeFrontEndTransport\Unused Lowest
EX02\MSExchangeFrontEndTransport\ShadowRedundancy Lowest
EX02\MSExchangeFrontEndTransport\Approval Lowest
EX02\MSExchangeFrontEndTransport\TransportSafetyNet Lowest
EX02\MSExchangeFrontEndTransport\TransportTenantAttribution Lowest

Enable / Disable Windows Photoviewer in Windows 10

 

To enable / disable Windows Photoviewer in Windows 10

Use the .reg files below.

 

Enable

 

Windows Registry Editor Version 5.00

; Enable Windows Photoviewer in Win 10

[HKEY_CLASSES_ROOT\Applications\photoviewer.dll]

[HKEY_CLASSES_ROOT\Applications\photoviewer.dll\shell]

[HKEY_CLASSES_ROOT\Applications\photoviewer.dll\shell\open]
“MuiVerb”=”@photoviewer.dll,-3043”

[HKEY_CLASSES_ROOT\Applications\photoviewer.dll\shell\open\command]
@=hex(2):25,00,53,00,79,00,73,00,74,00,65,00,6d,00,52,00,6f,00,6f,00,74,00,25,\
00,5c,00,53,00,79,00,73,00,74,00,65,00,6d,00,33,00,32,00,5c,00,72,00,75,00,\
6e,00,64,00,6c,00,6c,00,33,00,32,00,2e,00,65,00,78,00,65,00,20,00,22,00,25,\
00,50,00,72,00,6f,00,67,00,72,00,61,00,6d,00,46,00,69,00,6c,00,65,00,73,00,\
25,00,5c,00,57,00,69,00,6e,00,64,00,6f,00,77,00,73,00,20,00,50,00,68,00,6f,\
00,74,00,6f,00,20,00,56,00,69,00,65,00,77,00,65,00,72,00,5c,00,50,00,68,00,\
6f,00,74,00,6f,00,56,00,69,00,65,00,77,00,65,00,72,00,2e,00,64,00,6c,00,6c,\
00,22,00,2c,00,20,00,49,00,6d,00,61,00,67,00,65,00,56,00,69,00,65,00,77,00,\
5f,00,46,00,75,00,6c,00,6c,00,73,00,63,00,72,00,65,00,65,00,6e,00,20,00,25,\
00,31,00,00,00

[HKEY_CLASSES_ROOT\Applications\photoviewer.dll\shell\open\DropTarget]
“Clsid”=”{FFE2A43C-56B9-4bf5-9A79-CC6D4285608A}”

[HKEY_CLASSES_ROOT\Applications\photoviewer.dll\shell\print]

[HKEY_CLASSES_ROOT\Applications\photoviewer.dll\shell\print\command]
@=hex(2):25,00,53,00,79,00,73,00,74,00,65,00,6d,00,52,00,6f,00,6f,00,74,00,25,\
00,5c,00,53,00,79,00,73,00,74,00,65,00,6d,00,33,00,32,00,5c,00,72,00,75,00,\
6e,00,64,00,6c,00,6c,00,33,00,32,00,2e,00,65,00,78,00,65,00,20,00,22,00,25,\
00,50,00,72,00,6f,00,67,00,72,00,61,00,6d,00,46,00,69,00,6c,00,65,00,73,00,\
25,00,5c,00,57,00,69,00,6e,00,64,00,6f,00,77,00,73,00,20,00,50,00,68,00,6f,\
00,74,00,6f,00,20,00,56,00,69,00,65,00,77,00,65,00,72,00,5c,00,50,00,68,00,\
6f,00,74,00,6f,00,56,00,69,00,65,00,77,00,65,00,72,00,2e,00,64,00,6c,00,6c,\
00,22,00,2c,00,20,00,49,00,6d,00,61,00,67,00,65,00,56,00,69,00,65,00,77,00,\
5f,00,46,00,75,00,6c,00,6c,00,73,00,63,00,72,00,65,00,65,00,6e,00,20,00,25,\
00,31,00,00,00

[HKEY_CLASSES_ROOT\Applications\photoviewer.dll\shell\print\DropTarget]
“Clsid”=”{60fd46de-f830-4894-a628-6fa81bc0190d}”

 

Disable

 

Windows Registry Editor Version 5.00

; Disable Windows Photoviewer in Win 10

[-HKEY_CLASSES_ROOT\Applications\photoviewer.dll]

 

Save the file as a .reg file.  Double click it.

image

Select Yes

image

Select Yes

image

Click OK

image

Right click an image file, select Open With –> Choose another app

image

Select More apps

image

Select Windows Photo Viewer, and tick Always use this app to open this type of file, and click Ok.

image

Powershell if file does not exist

Small gotcha that caught me recently, I needed to do a test-path but action if a file did NOT exist, and I had trouble getting it to work first go, so I’m writing this here:

$FileToCheck="c:\windows\system32\notepad.exe"
## check file exists
if (!(Test-Path $FileToCheck))
{
     throw "$FileToCheck not found"
}

This will throw the exception if the file can not be found.