简体   繁体   中英

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. When i log on in the server with my user (not admin) the scripts works perfectly. 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:

Import-Module ActiveDirectory

Typically, PowerShell loads modules automatically when required, but sometimes you need to explicitly tell it to.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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