Привет, ребята! пытаюсь локально расшарить скрипт на работе по установке драйверов и деплоя принтера с параметрами на машину.....все выходит кроме установки драйвера получаю вечно отказ в доступе
Делал через Powershell
» Нажмите, чтобы показать спойлер - нажмите опять, чтобы скрыть... «
# Get the ID and security principal of the current user account
$myWindowsID = [System.Security.Principal.WindowsIdentity]::GetCurrent();
$myWindowsPrincipal = New-Object System.Security.Principal.WindowsPrincipal($myWindowsID);
# Get the security principal for the administrator role
$adminRole = [System.Security.Principal.WindowsBuiltInRole]::Administrator;
# Check to see if we are currently running as an administrator
if ($myWindowsPrincipal.IsInRole($adminRole))
{
# We are running as an administrator, so change the title and background colour to indicate this
$Host.UI.RawUI.WindowTitle = $myInvocation.MyCommand.Definition + "(Elevated)";
$Host.UI.RawUI.BackgroundColor = "DarkBlue";
Clear-Host;
}
else {
# We are not running as an administrator, so relaunch as administrator
# Create a new process object that starts PowerShell
$newProcess = New-Object System.Diagnostics.ProcessStartInfo "PowerShell";
# Specify the current script path and name as a parameter with added scope and support for scripts with spaces in it's path
$newProcess.Arguments = "& '" + $script:MyInvocation.MyCommand.Path + "'"
# Indicate that the process should be elevated
$newProcess.Verb = "runas";
# Start the new process
[System.Diagnostics.Process]::Start($newProcess);
# Exit from the current, unelevated, process
Exit;
}
# Run your code that needs to be elevated here...
Write-Host
Write-Host ″Menu″ -BackgroundColor White -ForegroundColor Red
Write-Host
Write-Host ″1. Kyocera TR1 in a center″ -ForegroundColor Green
Write-Host ″2. Kyocera TR2 near exit″ -ForegroundColor Green
Write-Host ″3. HP Color M477 in a center″ -ForegroundColor Green
Write-Host ″4. Exit″ -ForegroundColor Green
Write-Host
$choice = Read-Host ″Select the menu item″
Switch($choice){
1{$driver = "Kyocera Ecosys M2540dn KX"
$address = "10.252.128.18"
$name = "Kyocera TR1"
$sleep = "3"
$DriverLocation = Join-Path $pwd "\KX_Universal_Printer_Driver\64bit\OEMSETUP.INF"
# The invoke command can be added to specify a remote computer by adding -computername. You would need to copy the .inf file to the remote computer first though.
# This script has it configured to run on the local computer that needs the printer.
# The pnputil command imports the .inf file into the Windows driverstore.
# The .inf driver file has to be physically on the local or remote computer that the printer is being installed on.
$DriverLocation2 = Join-Path $pwd "\KX_Universal_Printer_Driver\"
Get-ChildItem $DriverLocation2 -Recurse -Filter "*inf" | ForEach-Object { PNPUtil.exe /add-driver $_.FullName /install }
#Invoke-Command {pnputil.exe /add-driver (Join-Path $pwd "\KX_Universal_Printer_Driver\64bit\OEMSETUP.INF") /install }
#Add-PrinterDriver -Name $driver
Start-Sleep $sleep
# This creates the TCP\IP printer port. It also will not use the annoying WSD port type that can cause problems.
# WSD can be used by using a different command syntax though if needed.
Add-PrinterPort -Name $address -PrinterHostAddress $address
start-sleep $sleep
Add-Printer -DriverName $driver -Name $name -PortName $address
Start-Sleep $sleep
# This prints a list of installed printers on the local computer. This proves the newly added printer works.
get-printer |Out-Printer -Name $name }
2{$driver = "Kyocera Ecosys M2540dn KX"
$address = "10.120.4.5"
$name = "Kyocera TR2 NE"
$sleep = "3"
# The invoke command can be added to specify a remote computer by adding -computername. You would need to copy the .inf file to the remote computer first though.
# This script has it configured to run on the local computer that needs the printer.
# The pnputil command imports the .inf file into the Windows driverstore.
# The .inf driver file has to be physically on the local or remote computer that the printer is being installed on.
$DriverLocation2 = Join-Path $pwd "\KX_Universal_Printer_Driver\"
Get-ChildItem $DriverLocation2 -Recurse -Filter "*inf" | ForEach-Object { PNPUtil.exe /add-driver $_.FullName /install }
#Invoke-Command {pnputil.exe /add-driver (Join-Path $pwd "\KX_Universal_Printer_Driver\64bit\OEMSETUP.INF") /install}
#Add-PrinterDriver -Name $driver
Start-Sleep $sleep
# This creates the TCP\IP printer port. It also will not use the annoying WSD port type that can cause problems.
# WSD can be used by using a different command syntax though if needed.
Add-PrinterPort -Name $address -PrinterHostAddress $address
start-sleep $sleep
Add-Printer -DriverName $driver -Name $name -PortName $address
# This prints a list of installed printers on the local computer. This proves the newly added printer works.
get-printer |Out-Printer -Name $name }
3{$driver = "Kyocera Ecosys M2540dn KX"
$address = "10.120.4.5"
$name = "Kyocera TR2 NE"
$sleep = "3"
# The invoke command can be added to specify a remote computer by adding -computername. You would need to copy the .inf file to the remote computer first though.
# This script has it configured to run on the local computer that needs the printer.
# The pnputil command imports the .inf file into the Windows driverstore.
# The .inf driver file has to be physically on the local or remote computer that the printer is being installed on.
Invoke-Command {pnputil.exe /add-driver (Join-Path $pwd "\KX_Universal_Printer_Driver\64bit\OEMSETUP.INF") /install}
#Add-PrinterDriver -Name $driver
Start-Sleep $sleep
# This creates the TCP\IP printer port. It also will not use the annoying WSD port type that can cause problems.
# WSD can be used by using a different command syntax though if needed.
Add-PrinterPort -Name $address -PrinterHostAddress $address
start-sleep $sleep
Add-Printer -DriverName $driver -Name $name -PortName $address
# This prints a list of installed printers on the local computer. This proves the newly added printer works.
get-printer |Out-Printer -Name $name $driver = "HP Color LaserJet MFP M477 PCL6"
$address = "10.252.128.17"
$name = "HP Color TR"
$sleep = "3"
# The invoke command can be added to specify a remote computer by adding -computername. You would need to copy the .inf file to the remote computer first though.
# This script has it configured to run on the local computer that needs the printer.
# The pnputil command imports the .inf file into the Windows driverstore.
# The .inf driver file has to be physically on the local or remote computer that the printer is being installed on.
Invoke-Command {pnputil.exe /add-driver (Join-Path $pwd "\KX_Universal_Printer_Driver\64bit\OEMSETUP.INF") /install}
#Add-PrinterDriver -Name $driver
Start-Sleep $sleep
# This creates the TCP\IP printer port. It also will not use the annoying WSD port type that can cause problems.
# WSD can be used by using a different command syntax though if needed.
Add-PrinterPort -Name $address -PrinterHostAddress $address
start-sleep $sleep
Add-Printer -DriverName $driver -Name $name -PortName $address
# This prints a list of installed printers on the local computer. This proves the newly added printer works.
get-printer |Out-Printer -Name $name
}
4{Write-Host ″Exit″; exit}
default {Write-Host ″Wrong choice, try again.″ -ForegroundColor Red}
}
Write-Host -NoNewLine "Press any key to continue...";
$null = $Host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown");
когда проводишь это с правами админа, принтер не сетапит, а если без, то драйвер....я уже устал читать одно и тоже и может кто-то тыкнет пальцем мне что я не так сделал
Сообщение отредактировал Sub Focus - Nov 4 2021, 19:55