简体   繁体   English

允许 Win 10 用户在没有 UAC 的情况下通过 PS 脚本重置网络适配器

[英]Allow Win 10 user to reset network adaptor via PS script without UAC

Firstly: I have found a number of questions answered that do everything but allow me to bypass UAC.首先:我发现了许多问题的答案,它们可以做任何事情,但允许我绕过 UAC。 I am IT for a small business, but it is not my primary responsibility.我是一家小型企业的 IT,但这不是我的主要职责。

I have two machines in my domain that on startup often fail to correctly connect to the domain network.我的域中有两台机器在启动时经常无法正确连接到域网络。 Restarting the network adapter fixes the issue until the machine restarts.重新启动网络适配器可修复该问题,直到机器重新启动。 Unfortunately, one of the machines is used by a non-admin, and a technically illiterate one at that.不幸的是,其中一台机器由非管理员使用,并且是技术文盲。

I hoped to use a powershell script to do this.我希望使用 powershell 脚本来做到这一点。 Using this website, I created script and batch files to solve the issue.使用这个网站,我创建了脚本和批处理文件来解决这个问题。 Since the computer only has one network adaptor, I went simple: internet.ps1由于电脑只有一个网卡,我就简单了:internet.ps1

    Get-NetAdapter | Restart-NetAdapter

internet.cmd网络命令

    @ECHO OFF
    SET ThisScriptsDirectory=%~dp0
    SET PowerShellScriptPath=%ThisScriptsDirectory%internet.ps1
    PowerShell -NoProfile -ExecutionPolicy Bypass -Command "& {Start-Process PowerShell -ArgumentList '-NoProfile -ExecutionPolicy Bypass -File ""%PowerShellScriptPath%""' -Verb RunAs}";

Unfortunately, I don't fully understand the last command in the batch file.不幸的是,我不完全理解批处理文件中的最后一个命令。 As such I struggle to research the command to pass some form of user credential.因此,我努力研究传递某种形式的用户凭据的命令。 This environment is not very secure.这种环境不是很安全。 But I don't want to give this user domain admin permissions generally, or provide them with some admin credentials which would end up on a sticky note.但我一般不想给这个用户域管理员权限,或者向他们提供一些最终会出现在便利贴上的管理员凭据。 Either option is just inviting trouble from my older, technically illiterate colleagues.任何一种选择都只会给我那些技术文盲的年长同事带来麻烦。 And going over to punch in credentials every day is time consuming.每天都过去打卡凭据非常耗时。

I am looking for a script that cycles the network adaptor and provides the necessary credentials to make that change so a non-admin user can fix their domain and internet access without having admin credentials on a post-it note.我正在寻找一个脚本来循环网络适配器并提供必要的凭据来进行更改,以便非管理员用户可以修复他们的域和 Internet 访问,而无需在便利贴上提供管​​理员凭据。

You could schedule a task using the Task Scheduler in Windows.您可以使用 Windows 中的任务计划程序来安排任务。 When scheduling a task, you can specify credentials for the task to use when it runs.计划任务时,您可以指定任务运行时要使用的凭据。 You can add a trigger for this task to have it run when the computer starts, or you can simply allow the user to manually start it.您可以为此任务添加触发器以使其在计算机启动时运行,或者您可以简单地允许用户手动启动它。

If you decide to go this route, there is a check box you can check that runs the program with the highest possible privileges.如果您决定走这条路线,您可以选中一个复选框,该复选框以尽可能高的权限运行程序。 The entire point of that last line is to start a new PowerShell window that runs as administrator so it actually has permission to restart the adapter.最后一行的重点是启动一个以管理员身份运行的新 PowerShell 窗口,因此它实际上有权重新启动适配器。 This means that you can get rid of almost your entire script, and just keep the part that actually restarts the adapter.这意味着您几乎可以去掉整个脚本,而只保留实际重新启动适配器的部分。

For example, when you go to create a new task in Task Scheduler, under the Actions tab, you can create a new action and enter the following:例如,当您在任务计划程序中创建新任务时,在操作选项卡下,您可以创建新操作并输入以下内容:

Program/script:程序/脚本:

PowerShell

Add arguments:添加参数:

-Command "Get-NetAdapter | Restart-NetAdapter"

Note: I'm not sure if this is still the case, but in my past experience, sometimes it will try to run before Windows is fully loaded. 注意:我不确定是否仍然如此,但根据我过去的经验,有时它会尝试在 Windows 完全加载之前运行。 If it doesn't seem to be doing anything on startup, you may need to add a delay to it. 如果它在启动时似乎没有做任何事情,您可能需要为其添加延迟。 You can do this by running the Start-Sleep command. 您可以通过运行Start-Sleep命令来执行此操作。 You can add it to the arguments field by doing the following: 您可以通过执行以下操作将其添加到参数字段:
\n-Command "Start-Sleep 5; Get-NetAdapter | Restart-NetAdapter" - 命令“开始-睡眠 5;获取-NetAdapter | 重新启动-NetAdapter”\n
Replace the number 5 with how many seconds you would like it to wait. 将数字 5 替换为您希望它等待的秒数。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Windows网络适配器通过Powershell禁用启用 - Windows Network adaptor disable enable via Powershell 通过 CMD 的 PS 脚本 - PS script via CMD 通过PS注销特定的断开连接的用户的脚本 - Script to Log Off Specific Disconnected User via PS Powershell v4脚本无法作为exe触发(通过PS2EXE)以重置会话 - Powershell v4 script doesn't fire as exe (via PS2EXE) to reset sessions 通过Win-PS2EXE转换为EXE的Powershell脚本可以手动运行,但作为计划任务运行时会出错 - Powershell Script converted to EXE via Win-PS2EXE can be run manually but errors out when run as a scheduled task Windows 10:获得远程访问权限后,以.\Administrator无UAC远程启动Quick Assist,或暂时禁用UAC - Windows 10: after gaining remote access, remotely start Quick Assist as .\Administrator without UAC, or temporarily disable UAC 翻译没有 psd1 文件的 PS 脚本 - Translating PS script without psd1 file 使用ps1脚本向AD用户添加组 - Adding groups to AD user with a ps1 script 标准用户以管理员身份自动运行 PS 脚本 - Standard user running PS script automatically as admin 启动后重新启动后,无法通过PS登录到网络共享 - Logging to network share not working via PS post reboot at startup
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM