Quantcast
Viewing all articles
Browse latest Browse all 15370

Powershell 'Cannot bind paramater 'Identity' error

I have written a script for automatically configuring a users Outlook signature as well as adding their managers information by pulling this through Active Directory using Get-ADUser.

It works properly on my account but when run through our test account we receive the following error for every Get-ADUser call for manager information:

Get-ADUser : Cannot bind parameter 'Identity'. Cannot convert value "CN=Robert XXX,CN=Users,DC=XXX,DC=com" to t
ype "Microsoft.ActiveDirectory.Management.ADUser". Error: "The type initializer for 'Microsoft.ActiveDirectory.Manageme
nt.ADUser' threw an exception."
At C:\Users\testread.XXX\Desktop\Set-Signature.ps1:54 char:36
+ $strManName = (Get-ADuser -Identity <<<< "$strManager" | foreach { $_.name } )
+ CategoryInfo : InvalidArgument: (:) [Get-ADUser], ParameterBindingException
+ FullyQualifiedErrorId : CannotConvertArgumentNoMessage,Microsoft.ActiveDirectory.Management.Commands.GetADUser

Here is a copy of the script:

#Import ActiveDirectory module for Get-ADUser method
Import-Module ActiveDirectory

#Get location of users appdata folder
$strAppData = $env:appdata

#Set path of signature folder
$strSigFolder = $strAppData + '\Microsoft\Signatures'

#Set path for signature file
$strSigFile = $strSigFolder + '\default.htm'

#Get logged in users account name
$strName = $env:username

#Create LDAP search filter based on users account name
$strFilter = "(&(objectCategory=User)(samAccountName=$strName))"

#Create an instance of the System.DirectoryServices.DirectorySearcher object
#and assign the LDAP search filter to it
$objSearcher = New-Object System.DirectoryServices.DirectorySearcher
$objSearcher.Filter = $strFilter

#Use FindOne method to locate user account with specified login name
$objPath = $objSearcher.FindOne()

#Call GetDirectoryEntry method to bind AD info to $objUser
$objUser = $objPath.GetDirectoryEntry()

#Assign Primary AD attributes to strings
$strFullName = $objUser.name
$strEmail = $objUser.mail
$strOffice = $objUser.physicalDeliveryOfficeName
$strTitle = $objUser.title
$strCompany = $objUser.company
$strTelephone = $objUser.telephoneNumber

#Set Manager name to string
$strManager = $objUser.manager

#Assign Manager AD attributes to strings
$strManName = (Get-ADuser -Identity "$strManager" | foreach { $_.name } )
$strManEmail = (Get-ADuser -Identity "$strManager" -Properties EmailAddress | foreach { $_.emailaddress } )
$strManOffice = (Get-ADuser -Identity "$strManager" -Properties Office | foreach { $_.office } )
$strManTitle = (Get-ADuser -Identity "$strManager" -Properties Title | foreach { $_.title } )
$strManCompany = (Get-ADuser -Identity "$strManager" -Properties Company | foreach { $_.company } )
$strManTelephone = (Get-ADuser -Identity "$strManager" -Properties TelephoneNumber | foreach { $_.telephoneNumber } )

#Write signature to file
$stream = [System.IO.StreamWriter] $strSigFile
$stream.WriteLine("")
$stream.WriteLine("

")
$stream.WriteLine("")
$stream.WriteLine("")
$stream.WriteLine("")
$stream.WriteLine("

")
$stream.WriteLine("$strFullName | $strTitle | $strCompany | $strOffice Office

")
$stream.WriteLine("

")
$stream.WriteLine("Telephone # $strTelephone | $strEmail

")
$stream.WriteLine("

")
$stream.WriteLine(" 

")
$stream.WriteLine("

")
$stream.WriteLine("$strManName | $strManTitle | $strManCompany | $strManOffice Office

")
$stream.WriteLine("

")
$stream.WriteLine("Telephone # $strManTelephone | $strManEmail

")
$stream.WriteLine("")
$stream.WriteLine("")
$stream.close()

#Remove First-Run registry entry
Remove-ItemProperty -Path hkcu:\software\microsoft\office\14.0\Outlook\Setup -Name First-Run -ErrorAction SilentlyContinue

#Add registry entry for default signature
New-ItemProperty -Path hkcu:\Software\Microsoft\Office\14.0\Common\MailSettings -Name NewSignature -PropertyType ExpandString -Value default -ErrorAction SilentlyContinue
New-ItemProperty -Path hkcu:\Software\Microsoft\Office\14.0\Common\MailSettings -Name ReplySignature -PropertyType ExpandString -Value default -ErrorAction SilentlyContinue


Viewing all articles
Browse latest Browse all 15370

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>