forked from djust270/Intune-Scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmap-printers-scheduledtask.ps1
More file actions
32 lines (27 loc) · 1.47 KB
/
Copy pathmap-printers-scheduledtask.ps1
File metadata and controls
32 lines (27 loc) · 1.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#Tests Connection to Print Server
$tpscript= '$fp01 = Test-Connection -ComputerName printserver.domain.com -ErrorAction SilentlyContinue
#Checks if driver is installed. Installed via win32 intune app using pnputil.exe
$toshiba= test-path C:\Windows\System32\DriverStore\FileRepository\esf6u.inf_amd64_10e58d367838d6a3
if ($toshiba -eq $true -and $fp01 -eq $true)
{add-printer -ConnectionName "\\printserver.domain.com\Printer Share Name 1"
add-printer -ConnectionName "\\printserver.domain.com\Printer Share Name 2"
add-printer -ConnectionName "\\printserver.domain.com\Printer Share Name 3" }'
#create mapping script
new-item c:\automation -ItemType directory -force
set-content c:\automation\addprinters.ps1 $tpscript
if( -Not (Get-ScheduledTask -TaskName "Map Printers" -ErrorAction SilentlyContinue -OutVariable task) )
{
$Params = @{
Action = (New-ScheduledTaskAction -Execute 'powershell' -Argument '-NoProfile -WindowStyle Hidden -ExecutionPolicy Bypass c:\automation\addprinters.ps1')
Trigger = (New-ScheduledTaskTrigger -AtLogOn)
Principal = (New-ScheduledTaskPrincipal -UserId (Get-CimInstance –ClassName Win32_ComputerSystem | Select-Object -expand UserName))
TaskName = 'Map Printers'
Description = 'Map Printers'
}
Register-ScheduledTask @Params
Start-ScheduledTask -TaskName "Map Printers"
}
else
{
Start-ScheduledTask -TaskName "Map Printers"
}