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 Thursday, September 10, 2015 3:02 PM
September 10th, 2015 3:00pm

First of all, you are using Set-ADUser at the wrong place, you should use it within your ForEach-Object loop. Second of all, as far as I know, you can't use Set-ADUser for your TerminalServices settings. So I don't know why that was brought up as a suggestion (correct me if I am wrong). Third and last of all, it is generally a good idea to not use empty / $null values to set attributes (because in most cases, like jrv already pointed out, you can't do that / it will fail). In this case though, you can perfectly do it if you would use the Invokeset term on your code.

This worked for me in my lab:

ImportModule ActiveDirectory
Get-ADUser wiam | foreach-object {
  $user = [ADSI]"LDAP://$($_.DistinguishedName)"
  $user.psbase.Invokeset("TerminalServicesProfilePath", "")
  $user.psbase.Invokeset("TerminalServicesHomeDrive", "J:")
  $user.psbase.Invokeset("TerminalServicesHomeDirectory", "\\mnajdhjkstor1\wiam")
  $user.SetInfo()
}


  • Edited by HicanNL 19 hours 32 minutes ago
Free Windows Admin Tool Kit Click here and download it now
September 11th, 2015 4:24am

Hello and thanks for your Message..... Yes if i do this in the Server directly will be run like me first script :-)

But if i will do this Task running remotly from me lokal machine that are member from the same Domain

and me powershell open with Admin - right's but i become alway the same error message back.

"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

"

me gool to have are to runn this from me machine and not from the Server powershell.
Thanks Regards
mauri

September 11th, 2015 7:24am

You haven't made it clear anywhere that you wanted to run this remotely on a different machine. Next time please state in your question what you actually want to achieve.

Having that said: running this 'remotely' is a bit strange, since your AD is Domain wide available. It doesn't matter on which machine you run it (there is no need to remotely run it), as long as you have (access) rights to the Active Directory, you should be able to talk / script against it!

Do you, on the machine you want to run this from, have the ActiveDirectory module available? Since I can imagine if you don't run this from a server, you wouldn't have, by default, the Module / Cmdlets available.

Next to that, I see in your error the following: Zugriff verweigert. If my German is correct, that means you have a lack of permissions somewhere. I don't think it has something to do with the script in that case.


  • Edited by HicanNL 19 hours 32 minutes ago
Free Windows Admin Tool Kit Click here and download it now
September 11th, 2015 7:38am

First of all, you are using Set-ADUser at the wrong place, you should use it within your ForEach-Object loop. Second of all, as far as I know, you can't use Set-ADUser for your TerminalServices settings. So I don't know why that was brought up as a suggestion (correct me if I am wrong). Third and last of all, it is generally a good idea to not use empty / $null values to set attributes (because in most cases, like jrv already pointed out, you can't do that / it will fail). In this case though, you can perfectly do it if you would use the Invokeset term on your code.

This worked for me in my lab:

ImportModule ActiveDirectory
Get-ADUser wiam | foreach-object {
  $user = [ADSI]"LDAP://$($_.DistinguishedName)"
  $user.psbase.Invokeset("TerminalServicesProfilePath", "")
  $user.psbase.Invokeset("TerminalServicesHomeDrive", "J:")
  $user.psbase.Invokeset("TerminalServicesHomeDirectory", "\\mnajdhjkstor1\wiam")
  $user.SetInfo()
}


  • Edited by HicanNL Friday, September 11, 2015 11:40 AM
September 11th, 2015 8:22am

You haven't made it clear anywhere that you wanted to run this remotely on a different machine. Next time please state in your question what you actually want to achieve.

Having that said: running this 'remotely' is a bit strange, since your AD is Domain wide available. It doesn't matter on which machine you run it (there is no need to remotely run it), as long as you have (access) rights to the Active Directory, you should be able to talk / script against it!

Do you, on the machine you want to run this from, have the ActiveDirectory module available? Since I can imagine if you don't run this from a server, you wouldn't have, by default, the Module / Cmdlets available.

Next to that, I see in your error the following: Zugriff verweigert. If my German is correct, that means you have a lack of permissions somewhere. I don't think it has something to do with the script in that case.


  • Edited by HicanNL Friday, September 11, 2015 11:39 AM
Free Windows Admin Tool Kit Click here and download it now
September 11th, 2015 11:37am

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

Other recent topics Other recent topics