2

I have the following Powershell script:

# Check if the script is running as admin
$IsAdmin = ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")
if (-not $IsAdmin) {
    # Display an error message and exit
    Write-Output "Dieses Programm muss als Administrator ausgeführt werden. Bitte Rechtsklicke diese datei und wähle 'Als Administrator' ausführen."
    Start-Sleep -Seconds 50
    break
}

$PortName = Read-Host -Prompt "Gib deine Druckeradresse ein"
Invoke-WebRequest -Uri "https://dl.konicaminolta.eu/de?tx_kmdownloadcentersite_downloadproxy%5bfileId%5d=7f86746b8a2082a5152d3dd65a48292d&tx_kmdownloadcentersite_downloadproxy%5bdocumentId%5d=135985&tx_kmdownloadcentersite_downloadproxy%5bsystem%5d=KonicaMinolta&tx_kmdownloadcentersite_downloadproxy%5blanguage%5d=DE&type=1558521685" -OutFile "C:\printer.zip"
Expand-Archive -Path "C:\printer.zip" -DestinationPath "C:\printerAksa"
pnputil.exe /add-driver "C:\printer\UPD4PCL6Win81P_2101MU\driver\x64\PCL6\KOBxxK__01.inf" /install
Add-PrinterDriver -Name “KONICA MINOLTA Universal V4 PCL”
Add-Printer -PortName $PortName -DriverName "KONICA MINOLTA Universal V4 PCL" -Name "Printer"
Remove-Item -Path "C:\printer.zip" -Force
Remove-Item -Path "C:\printer" -Recurse -Force`

It is meant to install the printers for our school because at the moment the school's solution is to install is manually, but many people aren't tech savvy enough to do that, even with a step-by-step guide. So i created this script in which one only has to enter their own printer address provided by the school and the rest is done for them. The problem now is that you cant really just share PowerShell scripts, because you'd have to change a policy to execute it (at least to my knowledge). What I tried is converting it to an exe file using PS2EXE which worked but when others downloaded it, Windows blocked the download as it was identified as a virus. So here is the Question: How do I bring my little program to others from the school without it getting flagged? Maybe there is even a completely different approach than mine to the problem altogether. Thanks for your suggestions!

Santiago Squarzon
  • 41,465
  • 5
  • 14
  • 37
Angency
  • 21
  • 1
  • 3
    you could have a shortcut together with your `.ps1` and have the shortcut run `powershell.exe -File myscript.ps1 -ExecutionPolicy ByPass`. would also recommend to stay away from that PS2EXE nonsense. – Santiago Squarzon Feb 16 '23 at 14:09
  • Try zip the exe file to download. Then unzip after download. – jdweng Feb 16 '23 at 14:21
  • If you're a sysadmin at the school who is going to be officially supporting this across your entire student base then the answer might be different to if you're a student sharing the script with a few friends as a convenience - if it's just the latter then simply rename the *.ps1 file to *.txt and email it with instructions for the receiver to cut&paste the contents into a powershell console :-) – mclayton Feb 16 '23 at 14:29
  • My organization has a print server set up, with all the printers "directly" (by IP) connected, and the workstations get the printers deployed through Group Policy. This might be a better solution for you, though not an immediate one... – Jeff Zeitlin Feb 16 '23 at 14:47
  • The proper way to do this is Group Policy. The easiest other way is to get the end user to open the script in Powershell ISE. They can then simply "Select All" (Ctrl-A) and "Run Selection" (F8) as this will not trigger the need to bypass the execution policy. – Scepticalist Feb 16 '23 at 14:53
  • For the UAC part, you might make your script "self-elevating", see: https://stackoverflow.com/a/60216595/1701026. Meaning, instead of a message "*Dieses Programm muss als Administrator ausgeführt...*", it will just prompt the user for the UAC. – iRon Feb 16 '23 at 15:25

0 Answers0