i am looking for a way to take a script that I have created. And simply run it against the individual printers all at once. I do not care about returning any information other than success or failure if that is possible.
so far this is what I have come up with:
$scriptBlock = {
param($PRINTSERVER,$PRINTER)
. \\rictx-script-p2\Scripts\Module\OS\Print Server\Set-Permissions\Apply-PrinterPermissions3.ps1
Apply-PrinterPermissions -PrintServers $PRINTSERVER -PrinterName_Single $PRINTER
}
$PSERVER = "MTHOH-PRINT-P06"
$MyPrinter = "WILPA0P30"
#Async
Start-Job -ScriptBlock $scriptBlock -ArgumentList @($PSERVER,$MyPrinter)
The Script works great in parallel. But I am trying to speed up a 12 to 13 hour run on over 900 different printers in the environment. By applying the script async. The script is already configured to work on a print server as a whole and on a printer individually. To ensure there is a consistant permissions assigned to them all according to corporate policy. On average the script takes about 1 to 1.5 minutes per printer to apply the printer ACL Changes.
My Thoughts was to have a script block load the printer permissions script, call the printers individually per job with the print server. And run about 50 to 100 jobs at once. This would require sending 2 paramaters to the script block for the function to be called.
What would be the best way to do this? Currently the script does nothing when I start the job. but works if I call the apply-printerpermissions3 script directly.
Other things I have tried:
$scriptBlock = {
param($P)
. \\rictx-script-p2\Scripts\Module\OS\Print Server\Set-Permissions\Apply-PrinterPermissions3.ps1
Apply-PrinterPermissions -PrintServers $P[0] -PrinterName_Single $P[1]
}
$PSERVER = "MTHOH-PRINT-P06"
$MyPrinter = "WILPA0P30"
#Async
Start-Job -ScriptBlock $scriptBlock -ArgumentList @($PSERVER,$MyPrinter)
#Syncroneous
& $scriptBlock -PRINTSERVER $PServer -PRINTER $MyPrinter
The Sycroneous process works but the async does not.
Sorry I am not sure how to add my comment with code blocks as a reply: I have tried this:
$s = New-PSSession -ComputerName mthoh-print-p06
$scriptBlock = { param($PRINTSERVER,$PRINTER)
Write-Host "$PRINTSERVER"
Write-Host "------------"
Write-Host "$Printer"
. \\rictx-script-p2\Scripts\Module\OS\Print Server\Set-Permissions\Apply-PrinterPermissions3.ps1
Apply-PrinterPermissions -PrintServers $PRINTSERVER -PrinterName_Single $PRINTER }
$ArgumentList = "PSERVER", "Wilpa0p30"
Invoke-Command -Session $s -ScriptBlock $scriptBlock -AsJob -ArgumentList $ArgumentList
$s = New-PSSession -ComputerName mthoh-print-p06
$scriptBlock = { param($P)
Write-Host "$PRINTSERVER"
Write-Host "------------"
Write-Host "$Printer"
. \\rictx-script-p2\Scripts\Module\OS\Print Server\Set-Permissions\Apply-PrinterPermissions3.ps1
Apply-PrinterPermissions -PrintServers $P[0] -PrinterName_Single $P[1]
}
$ArgumentList = "PSERVER", "Wilpa0p30"
Invoke-Command -Session $s -ScriptBlock $scriptBlock -AsJob -ArgumentList $ArgumentList
My Problem is this completes but does not appear to do anything. The script works if I call it locally just not working with Invoke-command.
I am not worried about the process of passing each printer name. I can eaisly do:
foreach ( $Printer in ((Get-Printer -Computername $Server).Name) )
{do something to pass each command to my Printer ACL Script...}
My Printer ACL Script is configured to do a printer individually and process a server as a whole.
I think I have found something that works. Thanks for your help:
$parameters = @{
ComputerName = "mthoh-print-p06"
ScriptBlock = { param($PRINTSERVER,$PRINTER)
Write-host "$($env:COMPUTERNAME) --- $($env:USERNAME)"
Write-Host "$PRINTSERVER"
Write-Host "------------"
Write-Host "$Printer"
$item = "\\rictx-script-p2\Scripts\Module\OS\Print Server\Set-Permissions\Apply-PrinterPermissions3.ps1"
([System.IO.File]::Exists($Item))
. "\\rictx-script-p2\Scripts\Module\OS\Print Server\Set-Permissions\Apply-PrinterPermissions3.ps1"
Apply-PrinterPermissions -PrintServers $PRINTSERVER -PrinterName_Single $PRINTER }
ArgumentList = "mthoh-print-p06", "Wilpa0p30"
}
Invoke-Command @parameters -EnableNetworkAccess -AsJob
$j = Get-Job
$j | Format-List -Property *
$results = $j | Receive-Job
get-job | Where {$_state -ne "Running"} | Remove-Job
Invoke-Command?$PServer='';$MyPrinter=''; & $ScriptBlock...; the solution to your problem is going to rely on how you're managing the list of devices.