Knowledge Base

Search Our Knowlegde Base

Find your answers by searching below.

How do I delete unused drivers in bulk?

Print article Email to friend
0.00

Using PowerShell to delete unused drivers.

Run the following PowerShell script on your smartImager server to delete all unused drivers.

This will delete all drivers which are not in a driver pack.  To delete a Driver Pack, open your smartImager console and go to Components | Driver Packs and delete a driver pack by clicking on the name of the driver pack and choosing the delete (trash can) icon.

NOTE: This script can be run in "logging mode only" by changing both variables on top to "false".
Example:
$bolDeleteConfigurations = $false
$bolDeleteData = $false

Copy/Paste the following code into your PowerShell ISE on your smartImager server to run.

# *************************
# *************************

$bolDeleteConfigurations = $true #delete the item from the smartImager configuration
$bolDeleteData = $true #delete the folder and files from the server

$installationPath = (get-itemproperty "HKLM:SoftwareSirckssmartimager").Path

$currentPrincipal = New-Object Security.Principal.WindowsPrincipal([Security.Principal.WindowsIdentity]::GetCurrent())
$currentUser = $currentPrincipal.Identity.Name

if(-not ($currentPrincipal.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)))
{
write-error "Please run this script as an administrator on the system."
exit -1
}

if(-not (test-path $(join-path $installationPath "WebServicesbinSI-Console.dll")))
{
Write-Error "Unable to find smartImager installation information, please make sure you run this on the server as an administrator"
exit -1
}

add-type -Path $(join-path $installationPath "WebServicesbinSI-Console.dll")


$sibi = new-object SI_Console.App_Code.SmartImagerBIO($currentUser)

$sibi.LoadFromDatabase()

$driverFolderPath = $sibi.DriverRepositoryPath

$orphanedDrivers = $sibi.Drivers | ?{$_.ReferencedBy.Rows.Count -eq 0}

Write-Host "Not Used Drivers: $($orphanedDrivers.Count)"

$orphanedDrivers | select displayName,folderName,driverpacks | ft

if($bolDeleteConfigurations)
{
foreach($oDriver in $orphanedDrivers)
{
Write-host "Deleting Configuration: $($oDriver.DisplayName)" -NoNewline
if($oDriver.Delete($currentUser,"CLA",$false))
{
write-host "`tSuccess"
if($bolDeleteData)
{
write-host "Deleting Data: $(Join-Path $driverFolderPath $oDriver.FolderName)" -NoNewline

if(test-path $(Join-Path $driverFolderPath $oDriver.FolderName))
{
remove-item -path $(Join-Path $driverFolderPath $oDriver.FolderName) -Recurse -Force
write-host "`tDELETED"

}
else
{
write-host "`tDOESN'T EXIST"
}
}
}
else
{
write-host "`tFailed: $($oDriver.Errors[0])"
}
}
}

$sibi.LoadFromDatabase()


$existingFolders = Get-ChildItem -Path $driverFolderPath -Exclude "VendorCache","ADSIx64","ADSIx86"

foreach($existingFolder in $existingFolders)
{
if(-not ($sibi.Drivers | ?{$_.FolderName -eq $existingFolder.Name}))
{
write-host "Orphaned Driver Folder: $($existingFolder.FullName)" -NoNewline
if($bolDeleteData)
{
remove-item -path $($existingFolder.FullName) -Recurse -Force
write-host "`tDELETED"
}
else
{
write-host ""
}

}
}

# *************************
# *************************

 

How do I delete unused drivers in bulk?

Using PowerShell to delete unused drivers.

Run the following PowerShell script on your smartImager server to delete all unused drivers.

This will delete all drivers which are not in a driver pack.  To delete a Driver Pack, open your smartImager console and go to Components | Driver Packs and delete a driver pack by clicking on the name of the driver pack and choosing the delete (trash can) icon.

NOTE: This script can be run in "logging mode only" by changing both variables on top to "false".
Example:
$bolDeleteConfigurations = $false
$bolDeleteData = $false

Copy/Paste the following code into your PowerShell ISE on your smartImager server to run.

# *************************
# *************************

$bolDeleteConfigurations = $true #delete the item from the smartImager configuration
$bolDeleteData = $true #delete the folder and files from the server

$installationPath = (get-itemproperty "HKLM:SoftwareSirckssmartimager").Path

$currentPrincipal = New-Object Security.Principal.WindowsPrincipal([Security.Principal.WindowsIdentity]::GetCurrent())
$currentUser = $currentPrincipal.Identity.Name

if(-not ($currentPrincipal.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)))
{
write-error "Please run this script as an administrator on the system."
exit -1
}

if(-not (test-path $(join-path $installationPath "WebServicesbinSI-Console.dll")))
{
Write-Error "Unable to find smartImager installation information, please make sure you run this on the server as an administrator"
exit -1
}

add-type -Path $(join-path $installationPath "WebServicesbinSI-Console.dll")


$sibi = new-object SI_Console.App_Code.SmartImagerBIO($currentUser)

$sibi.LoadFromDatabase()

$driverFolderPath = $sibi.DriverRepositoryPath

$orphanedDrivers = $sibi.Drivers | ?{$_.ReferencedBy.Rows.Count -eq 0}

Write-Host "Not Used Drivers: $($orphanedDrivers.Count)"

$orphanedDrivers | select displayName,folderName,driverpacks | ft

if($bolDeleteConfigurations)
{
foreach($oDriver in $orphanedDrivers)
{
Write-host "Deleting Configuration: $($oDriver.DisplayName)" -NoNewline
if($oDriver.Delete($currentUser,"CLA",$false))
{
write-host "`tSuccess"
if($bolDeleteData)
{
write-host "Deleting Data: $(Join-Path $driverFolderPath $oDriver.FolderName)" -NoNewline

if(test-path $(Join-Path $driverFolderPath $oDriver.FolderName))
{
remove-item -path $(Join-Path $driverFolderPath $oDriver.FolderName) -Recurse -Force
write-host "`tDELETED"

}
else
{
write-host "`tDOESN'T EXIST"
}
}
}
else
{
write-host "`tFailed: $($oDriver.Errors[0])"
}
}
}

$sibi.LoadFromDatabase()


$existingFolders = Get-ChildItem -Path $driverFolderPath -Exclude "VendorCache","ADSIx64","ADSIx86"

foreach($existingFolder in $existingFolders)
{
if(-not ($sibi.Drivers | ?{$_.FolderName -eq $existingFolder.Name}))
{
write-host "Orphaned Driver Folder: $($existingFolder.FullName)" -NoNewline
if($bolDeleteData)
{
remove-item -path $($existingFolder.FullName) -Recurse -Force
write-host "`tDELETED"
}
else
{
write-host ""
}

}
}

# *************************
# *************************