JoeParticipantJanuary 22, 2018 at 4:40 pmPost count: 5
I am writing a PSAD script to detect the remote computers OU and that will then install the software and configuration for that site.
My problem is is that It is running the script perfectly on my (admin) maachine but not on a pilot users machine.
I have checked the C:\Windows\Logs\Software log files and getting the below.
[Post-Installation] :: Error Record:
Message : The term ‘get-adcomputer’ is not recognized as the name of a
cmdlet, function, script file, or operable program. Check the
spelling of the name, or if a path was included, verify that
the path is correct and try again.
I have added Import-Module ActiveDirectory at the top but it still doesnt work. does anyone have any thoughts to why? Below is the script.
<code> Import-Module ActiveDirectory $cname = $env:Computername $distname = Get-Adcomputer $cname | Select Name -ExpandProperty DistinguishedName</code>
From the code above I then set a variable for the Distinguished name, then I have IF statements to run through 20 OU variables and then If that computer matches one of the 20 it’ll have the specific configuration.
RichardParticipantJanuary 22, 2018 at 5:50 pmPost count: 2
Do you have the RSAT tools installed on the client device(s) so that when the Import-Module ActiveDirectory cmdlet is called, it can locate the required contents?
RichardParticipantJanuary 22, 2018 at 8:27 pmPost count: 2
Hi Joe, the Get-AD* cmdlets are not available unless the RSAT tools are installed.
Since you want to query AD from multiple client PC’s, RSAT needs to be installed on those systems in order to have access to the Get-ADComputer cmdlet.
Your statement “Dont think its good practice install admin tools for standard uses.” is correct and I agree, but you are attempting to perform an admin related task from a client PC therefore requiring the RSAT tools and associated PowerShell cmdlets.
Perhaps you need to redesign the solution in order to make this work?
What deployment method are you using?
Think about checking if clients meet certain criteria and then targeting them with a software deployment. This approach is essentially how deploying software to a collection of computers works in SCCM.
JoeParticipantJanuary 23, 2018 at 6:54 amPost count: 5
Yes you are right. I can always uninstall RSAT at the end of the script if needed anyway.
I cant think of another way to obtain the Distinguished name of a machine and then query it at a later stage so will include it in this script and the forum know the outcome.
I am using SCCM 2012 to deploy the PSAD script. I could have 20 different deployments for each targeted site but the 20 sites will increase and SCCM will get messy. Each ‘site’ has a specific configuration and a certificate to go with it so my script queries the computer and depending what OU they are in they get said config.
JoeParticipantJanuary 29, 2018 at 11:43 amPost count: 5
I have found that you will need to install RSAT on the client machine in order for the “Get-AdComputer” cmdlet to work. Below is what I used to obtain the information needed using WMI.
<code> $cname = $env:Computername $OU = ([adsisearcher]"(&(name=$env:computername)(objectClass=computer))").findall().path $OU = $OU -Replace "LDAP://" $distname = $OU</code>
using ([adsisearcher]”(&(name=$env:computername)(objectClass=computer))”).findall().path outputs the command with LDAP:// at the beginning so I used POSH to replace the “LDAP://” and set that as a variable.
_MikeCParticipantAugust 22, 2018 at 3:39 pmPost count: 2
VBScript can get this info. Note: I’m not the original author of this script but I did modify it years ago to suit my purposes.
‘Use VBScript to query Domain for the computer DN
‘ 1. you must include the computer name on the commandline
‘ example: cscript.exe //nologo GetDN.vbs computername
‘ output is the DN found or an error if it isn’t found or an
‘ error if the computer name is not provided on the commandline
‘ output can be redirected to a file using CMD redirection if needed
Dim objRootDSE, strDNSDomain, objTrans, strNetBIOSDomain, objArgs
Dim objFSO, strComputer, strComputerDN, RC
Const ForReading = 1
‘ Constants for the NameTranslate object.
Const ADS_NAME_INITTYPE_GC = 3
Const ADS_NAME_TYPE_NT4 = 3
Const ADS_NAME_TYPE_1779 = 1
‘Check for command line arg for the computername
Set objArgs = Wscript.Arguments
If objArgs.Count <> 1 then
wscript.echo “Missing Argument”
strComputer = objArgs(0)
‘ Determine DNS name of domain from RootDSE.
Set objRootDSE = GetObject(“LDAP://RootDSE”)
strDNSDomain = objRootDSE.Get(“defaultNamingContext”)
‘ Use the NameTranslate object to find the NetBIOS domain name from the DNS domain
Set objTrans = CreateObject(“NameTranslate”)
objTrans.Init ADS_NAME_INITTYPE_GC, “”
objTrans.Set ADS_NAME_TYPE_1779, strDNSDomain
strNetBIOSDomain = objTrans.Get(ADS_NAME_TYPE_NT4)
‘ Remove trailing backslash.
strNetBIOSDomain = Left(strNetBIOSDomain, Len(strNetBIOSDomain) – 1)
‘ Use Set method to specify NT format name.
‘ sAMAccountName of computer is NetBIOS name with “$” appended.
‘ Trap error if computer not found.
On Error Resume Next
objTrans.Set ADS_NAME_TYPE_NT4, strNetBIOSDomain & “\” & strComputer & “$”
If (Err.Number <> 0) Then
Wscript.Echo “Computer not found”
RC = 2
On Error GoTo 0
On Error GoTo 0
‘ Retrieve Distinguished Name.
strComputerDN = objTrans.Get(ADS_NAME_TYPE_1779)
RC = 0
You must be logged in to reply to this topic.