Script with SetInfo failure

Hello Together

I'am new to this Forum and i need help to solve me Problem, i will connect with me Poweshell Session to me AD and do any possible changes.

   -- >  Get-ADUser -Identity macalo | fl *

This command will be run without Problem.

But if i will Run this Command "tsp.ps1" i will become this following error:

c:\>c:\tsp.ps1

$Credentials = Get-Credential
Import-Module ActiveDirectory Get-ADUser wiam | ForEach-Object { $User = [ADSI]"LDAP://$($_.DistinguishedName)" $User.psbase.invokeset("TerminalServicesProfilePath","") $User.psbase.invokeset("TerminalServicesHomeDrive","J:") $User.psbase.invokeset("TerminalServicesHomeDirectory","\\alnmjst01\wiam") $User.setinfo() }

---

ErrorMessage:

Ausnahme beim Aufrufen von "setinfo" mit 0 Argument(en):  "Zugriff verweigert
"
In C:\Temp\tsp.ps1:8 Zeichen:1
+ $User.setinfo()
+ ~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : CatchFromBaseAdapterMethodInvokeTI

thanks for any Help
Mauri


  • Edited by maui72 16 hours 4 minutes ago
September 10th, 2015 11:01am

Hi,

Use Set-ADUser instead:

http://ss64.com/ps/set-aduser.html

Free Windows Admin Tool Kit Click here and download it now
September 10th, 2015 11:04am

You cannot set an attribute to blank or null.  You can set a new value or you can clear a value.

You don't need to use Invoke.

Mike is correct.  Use Set-AdUser as it resolves all of this for you.

September 10th, 2015 11:08am

Thanks for your quick answer ... WOW!!

After i Change my Script now, nothing Error will be apair but me "TerminalSettings" Input are not here !?

Import-Module ActiveDirectory
Set-ADUser wiam | ForEach-Object { $User = [ADSI]"LDAP://$($_.DistinguishedName)"
$User.psbase("TerminalServicesProfilePath","")
$User.psbase("TerminalServicesHomeDrive","J:")
$User.psbase("TerminalServicesHomeDirectory","\\mnajdhjkstor1\wiam")
$User.setinfo()
}

Thanks

Regards

Mauri




Free Windows Admin Tool Kit Click here and download it now
September 10th, 2015 11:23am

Please read the help for set-aduser.  Follow the examples.
September 10th, 2015 11:32am

You cannot assign a blank string or null to any AD attribute. You should use the -Clear parameter of Set-ADUser.
Free Windows Admin Tool Kit Click here and download it now
September 10th, 2015 11:55am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics