I need to change the name of my printer to be recognized in a function for my system. I'm not very good at programming, but with AI I managed to execute this command within PowerShell:
att. Language code-comment portuguese-Brazil.
PS C:\WINDOWS\system32> # Defina a parte do nome que você deseja identificar na impressora
>> $parteDoNome = "TECTOY"
>>
>> # Defina o novo nome que você deseja atribuir às impressoras
>> $novoNome = "TESTE"
>>
>> # Obtenha todas as impressoras cujos nomes contêm a parte específica
>> $impressoras = Get-Printer | Where-Object { $_.Name -like "*$parteDoNome*" }
>>
>> # Percorra cada impressora e renomeie-a conforme necessário
>> foreach ($impressora in $impressoras) {
>> $novoNomeImpressora = $impressora.Name -replace $parteDoNome, $novoNome
>> Rename-Printer -Name $impressora.Name -NewName $novoNomeImpressora
>> Write-Host "Impressora $($impressora.Name) renomeada para $($novoNomeImpressora)."
>> }
>>
Impressora TECTOY - Q4 renomeada para TESTE - Q4.
PS C:\WINDOWS\system32>,
When I use it on my own computer it works fine, but when I take it to a Terminal Server, it returns this:
PS C:\Users\Administrator>
PS C:\Users\Administrator> # Define the part of the name you want to identify on the printer
>> $partofName = "TECTOY"
>>
>> # Set the new name you want to assign to the printers
>> $newName = "TEST"
>>
>> # Get all printers whose names contain the specific part
>> $printers = Get-Printer | Where-Object { $_.Name -like "*$partofName*" }
>>
>> # Cycle through each printer and rename it as needed
>> foreach ($printer in $printers) {
>> $newPrinterName = $printer.Name -replace $partofName, $newName
>> Rename-Printer -Name $printer.Name -NewName $newPrinterName
>> Write-Host "Printer $($printer.Name) renamed to $($newPrinterName)."
>> }
>>
Rename-Printer : Access is denied for the specified resource.
On line:13 character:5
+ Rename-Printer -Name $printer.Name -NewName $newPrinterName ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~
+ CategoryInfo : PermissionDenied: (MSFT_Printer:ROOT/StandardCimv2/MSFT_Printer) [Rename-Printer], CimEx
ception
+ FullyQualifiedErrorId : HRESULT 0x80070005,Rename-Printer
TECTOY printer - Q4 (2 redirected) renamed to TEST - Q4 (2 redirected).
Rename-Printer : Access is denied for the specified resource.
On line:13 character:5
+ Rename-Printer -Name $printer.Name -NewName $newPrinterName ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~
+ CategoryInfo : PermissionDenied: (MSFT_Printer:ROOT/StandardCimv2/MSFT_Printer) [Rename-Printer], CimEx
ception
+ FullyQualifiedErrorId : HRESULT 0x80070005,Rename-Printer
TECTOY Q4 (Copy 3) printer (2 redirected) renamed to TEST Q4 (Copy 3) (2 redirected).
PS C:\Users\Administrator>
My question would be: it seems to be a denied permission but where do I authorize this issue? it's possible? I really need this function to be able to change her name when she is redirected to the TS.
My question would be: it seems to be a denied permission but where do I authorize this issue? it's possible? I really need this function to be able to change her name when she is redirected to the TS.