我有一个很大的脚本正在执行,它正在做一些事情,包括更新一些UPNs
,连接到MYSQL
,提取数据,然后更新活动目录中与mysql
不匹配的帐户信息。数据
在我的测试中,一个用户帐户不断抛出错误,请参见下文(我从以下错误中删除了用户名,并将其替换为userid)
Set-ADUser:在C:\ Untitled1.ps1:93 char:11处替换
+ Set-ADUser $ user.sAMAccountName -Replace @ {l =“ $($ sqlquery。” city“)”; pos ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo:InvalidOperation:(userid:ADUser)[Set-ADUser],ADInvalidOperationException
+ FullyQualifiedErrorId:ActiveDirectoryServer:0,Microsoft.ActiveDirectory.Management.Commands.SetADUser *
我的错误被抛出的代码如下。我的猜测是MYSQL DB中的某个问题导致此帐户出现问题,但想知道这是否是我的代码。再次,这是我脚本的下半部分,上半部分设置了mysql连接的变量,并且只有10个帐户中的一个帐户抛出错误。
$sqlquery = Invoke-MySqlQuery -Connection $oConnection -Query "select * from ActiveDirectoryImport where login='$($USER.SAMACCOUNTNAME)'"
$userproperties = @("City","ST","StreetAddress","postalCode","Company", "Department", "TelephoneNumber", "facsimileTelephoneNumber","Country")
foreach ($property in $userproperties) {
if ($sqlquery.$userproperties -eq $null -or $user.$userproperties -ne $sqlquery.$userproperties) {
Set-ADUser $user.sAMAccountName -Replace @{l="$($sqlquery."city")";postalcode="$($sqlquery."zipcode")";St="$($sqlquery."state")";StreetAddress="$($sqlquery."address_1")";Company="$($sqlquery."company_name")";Department="$($sqlquery."department_name")";facsimileTelephoneNumber="$($sqlquery."fax")";telephonenumber="$($sqlquery."phone")"}
最佳答案
想通了。在mysql DB中,问题用户帐户的值为空。我们已更正它,并且脚本可以正常工作。
看来我将不得不多编辑一些脚本。
关于mysql - Powershell InvalidOperation错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52004796/