简体   繁体   English

Powershell脚本从本地服务器运行,但不在活动目录中的客户端运行

[英]powershell script running from local server but not from client in active directory

i have this simple powershell script, that gets info from AD and stores them on a file on the desktop at logon It is in the logon Group Policy. 我有这个简单的Powershell脚本,该脚本从AD获取信息,并将其存储在登录时的桌面文件中。这在登录组策略中。 When i log on in the server with my user (not admin) the scripts works perfectly. 当我用我的用户(不是admin)登录服务器时,脚本可以完美运行。 When i log in from a client machine it runs, creates the file, but no info in it. 当我从客户端计算机登录时,它会运行,创建文件,但其中没有任何信息。 any ideas? 有任何想法吗?

$strName = $env:username
$ObjUser = Get-ADUser  -Properties * -Filter {sAMAccountName -eq $strName} | select displayName, title, telephoneNumber, mail, sAMAccountName, fullname

$strtitle = $objuser.Title
$strphone = $objuser.telephoneNumber
$stremail = $objUser.mail

$folderlocation = [Environment]::GetFolderPath("Desktop")

$Filenam  = "$folderLocation\\test.txt"
$SigName  = $normalName + "-" + $strtitle + "-" + $strphone + "-" + $stremail | Out-File $Filenam

Be sure that the RSAT is installed n the target system and that the "Active Directory Module For Windows PowerShell" is enabled in Control Panel, then add the following to top of your script: 确保在目标系统中安装了RSAT ,并且在“控制面板”中启用了“用于Windows PowerShell的Active Directory模块”,然后将以下内容添加到脚本顶部:

Import-Module ActiveDirectory

Typically, PowerShell loads modules automatically when required, but sometimes you need to explicitly tell it to. 通常,PowerShell会在需要时自动加载模块,但是有时您需要明确告知它。

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

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