# Version 1.0 - 2017/09/13
###########################################
# Disclaimer
#
# The sample script is not supported under any standard support program or service. The sample script is provided
# AS IS without warranty of any kind.
#
# Examples:
# CMDL Args:
# .\TestDriverPathExist.ps1 -SiteServer "Computer01"
# .\TestDriverPathExist.ps1
#
Param (
[string] $SiteServer = "."
)
#=================================================
# Declaring Functions
#=================================================
function GetSiteCode($server) {
$wqlQuery = "SELECT * FROM SMS_ProviderLocation"
Get-WmiObject -Query $wqlQuery -Namespace "root\sms" -ComputerName $server | ForEach-Object {
If ($_.ProviderForLocalSite)
{$siteCode = $_.SiteCode}
}
return $siteCode.ToLower()
}
#=================================================
# Validating Parameters and Values
#=================================================
#=================================================
# Main Script
#=================================================
#Get Site Code
$SiteCode = GetSiteCode($SiteServer)
#Import the CM Powershell cmdlets
if (-not (Test-Path -Path $SiteCode)) {
Write-Verbose "$(Get-Date): CM12 module has not been imported yet, will import it now."
Import-Module ($env:SMS_ADMIN_UI_PATH.Substring(0, $env:SMS_ADMIN_UI_PATH.Length - 5) + '\ConfigurationManager.psd1') | Out-Null
}
#CM cmdlets need to be run from the CM drive
Set-Location "$($SiteCode):" | Out-Null
if (-not (Get-PSDrive -Name $SiteCode)) {
Write-Error "There was a problem loading the Configuration Manager powershell module and accessing the sites PSDrive."
exit 1
}
# Drivers
Write-Host "########### --- Check DRIVER Path - START --- ###########" -ForegroundColor Yellow
$CMObjects = Get-WmiObject -Namespace "root\sms\site_$sitecode" -Class SMS_Driver
foreach ($CMObject in $CMObjects) {
$DrvSrcPath = $CMObject.ContentSourcePath.ToLower()
$DrvSrcPath = "filesystem::$DrvSrcPath"
if (!(Test-Path -Path $DrvSrcPath -PathType Container)) {
Write-Host "Not existing Path found: " $DrvSrcPath -ForegroundColor Red
Write-Host "Driver Name : " $CMObject.LocalizedDisplayName -ForegroundColor White
Write-Host "Driver Version : " $CMObject.DriverVersion -ForegroundColor White
}
}
Write-Host "########### --- Check DRIVER Path - END --- ###########" -ForegroundColor Yellow
Set-Location C: