简体   繁体   English

在登录脚本中使用$ env:username无效

[英]Using $env:username in a logon script is not working

I have this setup with a GPO to run as a logon script, obviously to map a drive for clients. 我使用GPO进行此设置,以作为登录脚本运行,显然是为客户端映射驱动器。

net use H: \\server1\share\$env:username

Dead simple. 死了很简单。 If I put in a specific username in place of the variable then it works. 如果我在变量中放置了一个特定的用户名,那么它将起作用。 Also, if I run this script directly on a client machine it works. 另外,如果我直接在客户端计算机上运行此脚本,它将起作用。

Do you get an error? 收到错误消息吗? Does it helps if you wrap the path in double quotes? 如果将路径用双引号引起来,是否有帮助?

"\\server1\share\$env:username"

That should work with or without the quotation marks. 不管有没有引号,它都可以工作。 Are the clients all Windows 7? 客户端都是Windows 7吗? I believe that Powershell logon/startup scripts don't work on earlier versions, even if you have Powershell installed, because it's an add-on rather than a native shell. 我相信即使安装了Powershell,Powershell登录/启动脚本也无法在较早版本上运行,因为它是附加组件,而不是本机Shell。 If you're using downlevel clients, you can invoke the powershell script from a cmd batch file. 如果使用的是下层客户端,则可以从cmd批处理文件中调用powershell脚本。 But if you're going to do that, might as well skip Powershell and just run net use H:\\\\server1\\share\\%username% from your batch file. 但是,如果要执行此操作,则最好跳过Powershell并仅从批处理文件中运行net use H:\\\\server1\\share\\%username%

Run this in a .bat file as a login script (use a FQDN for the server name): 在.bat文件中将其作为登录脚本运行(使用FQDN作为服务器名称):

net use H: \\server.example.com\share\%USERNAME%

If that not works, your GPO is just not yet applied. 如果这不起作用,则您的GPO尚未应用。 You can force that by running on the machine gpupdate /force . 您可以通过在机器上运行gpupdate /force来强制执行该操作。 For testing make sure that the GPO is applied to the right OU to the group "Authenticated Users" (computers are in the group too). 为了进行测试,请确保将GPO应用于“经过身份验证的用户”组的正确OU(计算机也在该组中)。 And if that is not working, you can also "Enforce" the GPO. 并且,如果这不起作用,您还可以“强制执行” GPO。 Don't forget to do a gpupdate /force after any change to the GPO or it settings. 对GPO或其设置进行任何更改后,请不要忘记执行gpupdate /force

You can also try a .js logon script like: 您还可以尝试.js登录脚本,例如:

var WSH = new ActiveXObject("WScript.Shell");

    // Map share
    WSH.Run("net use H: \\\\server.example.com\\share");

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM