Nota
L'accesso a questa pagina richiede l'autorizzazione. È possibile provare ad accedere o modificare le directory.
L'accesso a questa pagina richiede l'autorizzazione. È possibile provare a modificare le directory.
Il modulo PowerShell UniversalPrintManagement supporta i modelli di scripting di PowerShell stabiliti. Questo articolo illustra alcuni modelli come punto di partenza del modo in cui i cmdlet possono essere combinati per affrontare i casi d'uso selezionati.
Connessione Stampa universale non interattiva
Uno dei valori principali dell'uso di PowerShell consiste nel creare script non interattivi che possono essere eseguiti più volte. La necessità di immettere le credenziali utente per stabilire la connessione a Stampa universale va contro questa idea. Un'opzione per risolvere questo problema consiste nell'archiviare in modo sicuro il segreto della password dell'utente e recuperarlo quando necessario.
- Archiviare in modo sicuro il segreto della password in un file
- Recuperare la password subito prima di chiamare
Connect-UPService
$Secure = Read-Host -AsSecureString
$Encrypted = ConvertFrom-SecureString -SecureString $Secure -Key (1..16)
$Encrypted | Set-Content Encrypted.txt
...
$Secure2 = Get-Content Encrypted.txt | ConvertTo-SecureString -Key (1..16)
Connect-UPService -UserPrincipalName username@tenantname.com -Password $Secure2
Nota
Altre informazioni su ConvertFrom-SecureString e ConvertTo-SecureString sono disponibili qui.
Annullare la registrazione in blocco delle stampanti di un connettore
Supponendo di conoscere già il nome del connettore registrato usato per registrare le stampanti. Fare riferimento al cmdlet Get-UPConnector per recuperare l'elenco dei connettori registrati.
- Connettersi a Stampa universale
- Ottenere l'elenco delle stampanti registrate tramite il connettore specifico
- Rimuovere la stampante registrata
Connect-UPService
$ConnectorPrinters = Get-UPPrinter -IncludeConnectorDetails
$ConnectorPrinters.Results | Where-Object {$_.Connectors.DisplayName -Contains "<Connector Name>"} | Remove-UPPrinter
Identificazione della stampante registrata dietro un nome di stampante condivisa
- Connettersi a Stampa universale
- Recuperare l'elenco delle stampanti e usare il computer locale per filtrare i risultati
Connect-UPService
$Printers = Get-UPPrinter
$Printer = $Printers.Results | Where-Object {$_.Shares.DisplayName -eq "<Share Name>"}
Annulla la condivisione delle stampanti in blocco
- Connettersi a Stampa universale
- Ottenere l'elenco delle stampanti di interesse
- Annullare la condivisione della raccolta di stampanti
Nota
Questo esempio mostra la rimozione della condivisione di tutte le stampanti condivise. Per annullare la condivisione solo di stampanti selezionate, è possibile aggiungere filtri aggiuntivi durante il recupero delle stampanti.
Connect-UPService
$Printers = Get-UPPrinter
$Printers.Results.Shares | Remove-UPPrinterShare
Concedere in blocco a tutti gli utenti l'accesso alle stampanti condivise
- Connettersi a Stampa universale
- Ottieni l'elenco delle condivisioni di stampanti di interesse
- Concedere all'utente l'accesso alla raccolta di stampanti
Connect-UPService
$PrinterShares = Get-UPPrinterShare
$PrinterShares.Results | Grant-UPAccess -AllUsersAccess
Concessione in blocco dell'accesso alle stampanti condivise per utenti o gruppi di utenti
- Prerequisito: recuperare gli ID utente e gli ID dei gruppi di utenti
- Connettersi a Stampa universale
- Ottieni l'elenco delle condivisioni di stampanti di interesse
- Concedere a utenti o gruppi specifici l'accesso alla raccolta di stampanti
Connect-AzAccount
$Users = Get-AzADUser -First 10
$UserGroups = Get-AzADGroup -SearchString Contoso
Connect-UPService
$PrinterShares = Get-UPPrinterShare
$Users | ForEach-Object {$PrinterShares.Results | Grant-UPAccess -UserID $_.Id}
$UserGroups | ForEach-Object {$PrinterShares.Results | Grant-UPAccess -GroupID $_.Id}
Impostare in batch le proprietà della posizione della stampante
- Connettersi a Stampa universale
- Ottenere l'elenco delle stampanti di interesse
- Concedere all'utente l'accesso alla raccolta di stampanti
Connect-UPService
$Printers = Get-UPPrinter
$Printers.Results | Set-UPPrinterProperty -Latitude 47.642391 -Longitude -122.137001 -Organization "Contoso" -Site "Main Campus" -City "Redmond" -Building "101"
Uso del ContinuationToken
- Connettersi a Stampa universale
- Ottenere l'elenco delle stampanti di interesse
- Se viene rilevato un errore intermittente, verranno restituiti risultati parziali, insieme a un token di continuazione.
Connect-UPService
$Printers = Get-UPPrinter
"Get-UPPrinter :
At line:1 char:13
+ $Printers = Get-UPPrinter
+ ~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (System.Collecti...Models.Printer]:List`1) [Get-UPPrinter], FailedCmdletException
+ FullyQualifiedErrorId : Rerun with -ContinuationToken to continue from last cutoff: MyZRVkZCUVVGQlFVRXZMeTh2THk4dkx5OHZMMGxCUVVGQk5IQTRiR
EY0YWpOdU1DdEtPSG94T1dwUWNHWm5kejA5,Microsoft.UPManagement.Cmdlets.GetPrinter"
$Printers.Results
"(Partial results list of printers)"
$Printers.ContinuationToken
"MyZRVkZCUVVGQlFVRXZMeTh2THk4dkx5OHZMMGxCUVVGQk5IQTRiREY0YWpOdU1DdEtPSG94T1dwUWNHWm5kejA5"
$MorePrinters = Get-UPPrinter -ContinuationToken $Printers.ContinuationToken
$MorePrinters.Results
"(Printer results list continued from previously left off)"
- ContinuationToken effettua chiamate per ottenere risultati più affidabili. È possibile aggiungere nuovi tentativi e accodarli tra loro. Si noti che ciò è necessario solo per i tenant con un numero elevato (~8000+) di stampanti/connettori/condivisioni/ecc. registrati e che riscontrano errori ricorrenti durante l’iterazione dell’intero elenco.
do
{
$i = Get-UPPrinter -ContinuationToken $i.ContinuationToken
$allprinters += $i.Results
}
while (![string]::IsNullOrEmpty($i.ContinuationToken))
$allprinters.Results
Scaricare i report sull'utilizzo di utenti e stampanti estesi per l'ultimo mese
- Assicurarsi che il modulo di Microsoft Graph corretto sia installato
- Accedere a Microsoft Graph
- Richiedere l'ambito di autorizzazione "Reports.Read.All" richiesto
- Raccogli ed esporta il report della stampante
- Raccogliere & esportare il report dell'utente
Param (
# Date should be in this format: 2020-09-01
# Default is the first day of the previous month at 00:00:00 (Tenant time zone)
$StartDate = "",
# Date should be in this format: 2020-09-30
# Default is the last day of the previous month 23:59:59 (Tenant time zone)
$EndDate = "",
# Set if only the Printer report should be generated
[switch]$PrinterOnly,
# Set if only the User report should be generated
[switch]$UserOnly
)
#############################
# INSTALL & IMPORT MODULES
#############################
if(-not (Get-Module Microsoft.Graph.Reports -ListAvailable)){
Write-Progress -Activity "Installing Universal Print dependencies..." -PercentComplete 60
Install-Module Microsoft.Graph.Reports -Scope CurrentUser -Force
}
Import-Module Microsoft.Graph.Reports
#############################
# SET DATE RANGE
#############################
if ($StartDate -eq "") {
$StartDate = (Get-Date -Day 1).AddMonths(-1).ToString("yyyy-MM-ddT00:00:00Z")
} else {
$StartDate = ([DateTime]$StartDate).ToString("yyyy-MM-ddT00:00:00Z")
}
if ($EndDate -eq "") {
$EndDate = (Get-Date -Day 1).AddDays(-1).ToString("yyyy-MM-ddT23:59:59Z")
} else {
$EndDate = ([DateTime]$EndDate).ToString("yyyy-MM-ddT23:59:59Z")
}
echo "Gathering reports between $StartDate and $EndDate."
########################################
# SIGN IN & CONNECT TO MICROSOFT GRAPH
########################################
# These scopes are needed to get the list of users, list of printers, and to read the reporting data.
Connect-MgGraph -Scopes "Reports.Read.All"
##########################
# GET PRINTER REPORT
##########################
if (!$UserOnly)
{
Write-Progress -Activity "Gathering Printer usage..." -PercentComplete -1
# Get the printer usage report
$printerReport = Get-MgReportMonthlyPrintUsageByPrinter -All -Filter "completedJobCount gt 0 and usageDate ge $StartDate and usageDate lt $EndDate"
## Join extended printer info with the printer usage report
$reportWithPrinterNames = $printerReport |
Select-Object (
@{Name = "UsageMonth"; Expression = {$_.Id.Substring(0,8)}},
@{Name = "PrinterId"; Expression = {$_.PrinterId}},
@{Name = "DisplayName"; Expression = {$_.PrinterName}},
@{Name = "TotalJobs"; Expression = {$_.CompletedJobCount}},
@{Name = "ColorJobs"; Expression = {$_.CompletedColorJobCount}},
@{Name = "BlackAndWhiteJobs"; Expression = {$_.CompletedBlackAndWhiteJobCount}},
@{Name = "ColorPages"; Expression = {$_.ColorPageCount}},
@{Name = "BlackAndWhitePages"; Expression = {$_.BlackAndWhitePageCount}},
@{Name = "TotalSheets"; Expression = {$_.MediaSheetCount}})
# Write the aggregated report CSV
$printerReport | Export-Csv -Path .\printerReport.csv
}
##################
# GET USER REPORT
##################
if (!$PrinterOnly)
{
Write-Progress -Activity "Gathering User usage..." -PercentComplete -1
# Get the user usage report
$userReport = Get-MgReportMonthlyPrintUsageByUser -All -Filter "completedJobCount gt 0 and usageDate ge $StartDate and usageDate lt $EndDate"
$reportWithUserInfo = $userReport |
Select-Object (
@{Name = "UsageMonth"; Expression = {$_.Id.Substring(0,8)}},
@{Name = "UserPrincipalName"; Expression = {$_.UserPrincipalName}},
@{Name = "TotalJobs"; Expression = {$_.CompletedJobCount}},
@{Name = "ColorJobs"; Expression = {$_.CompletedColorJobCount}},
@{Name = "BlackAndWhiteJobs"; Expression = {$_.CompletedBlackAndWhiteJobCount}},
@{Name = "ColorPages"; Expression = {$_.ColorPageCount}},
@{Name = "BlackAndWhitePages"; Expression = {$_.BlackAndWhitePageCount}},
@{Name = "TotalSheets"; Expression = {$_.MediaSheetCount}})
$reportWithUserInfo | Export-Csv -Path .\userReport.csv
}
echo "Reports were written to 'printerReport.csv' and 'userReport.csv'."