0
我使用Windows PowerShell獲取下面的錯誤。有誰知道如何改正它?Obj.SetInfo()錯誤obj沒有方法SetInfo()
ERROR: Method invocation failed because [Microsoft.ActiveDirectory.Management.ADObject]
doesn't contain a method named 'SetInfo'.
No.psf (97, 25): ERROR: At Line: 97 char: 25
ERROR: + $computerObject.SetInfo <<<<()
ERROR: + CategoryInfo : InvalidOperation: (SetInfo:String) [], RuntimeException
ERROR: + FullyQualifiedErrorId : MethodNotFound
我很抱歉沒有發佈代碼。我仍然有這個錯誤的問題。
$No_Load = {
# Load the ActiveDirectory module if it's available
# Check if the ActiveDirectory module is installed
if ((Get-Module -ListAvailable | where { $_.Name -eq 'ActiveDirectory' }) -eq $null) {
$labelDialogRedNewNo.Text += "You need to install the ActiveDirectory module!`n"
} else {
# Check if the ActiveDirectory module is allready Imported
if ((Get-Module ActiveDirectory) -eq $null) {
Import-Module ActiveDirectory -ErrorAction 'SilentlyContinue'
$labelDialogGreenNewNo.Text += "ActiveDirectory module imported`n"
} else {
$labelDialogGreenNewNo.Text += "ActiveDirectory already imported`n"
}
}
#Initialize variables
$dateTime = Get-Date -Format G
$computerName = (Get-WmiObject -Class Win32_ComputerSystem -Property Name).Name
$userName = (Get-WmiObject -Class Win32_ComputerSystem -Property UserName).UserName
#These Varables for display
$companyComputer = (Get-ADOrganizationalUnit -Filter 'Name -like "*Computers*"' | select name -ExpandProperty name)
$distinguishedName = (Get-ADComputer ($computerName) -Property DistinguishedName).DistinguishedName
$computerObject = (Get-ADObject ($distinguishedName))
$location = (Get-ADObject ($distinguishedName) -Properties Location).Location
$departmentNumber = (Get-ADObject ($distinguishedName) -Properties DepartmentNumber).DepartmentNumber
$company = (Get-ADObject ($distinguishedName) -Properties Company).Company
$accountType = (Get-ADObject ($distinguishedName) -Properties ExtensionAttribute15).ExtensionAttribute15
#Initialize Form Controls
$txtBillingCodeNewNo.Text = $departmentNumber
$lblComputerNameNewNo.Text = $computerName
$lblUserNameNewNo.Text = $userName
$lblPhysicalLocationNewNo.Text = $location
$comboboxATNewNo.Text = $accountType
$comboboxOUNewNo.Text = $company
#$comboboxATNewNo.Text = $companyComputer
Load-ComboBox -ComboBox $comboboxOUNewNo (Get-ADOrganizationalUnit -SearchScope OneLevel -SearchBase 'OU=Agencies,DC=state,DC=in,DC=us' -Filter * -Properties Name | select name -ExpandProperty name)
#Load-ComboBox -ComboBox $comboboxOUNewNo (Get-ADOrganizationalUnit -Filter 'Name -like "*Computers*"' | select name -ExpandProperty name)
}
#region Control Helper Functions
function Load-ComboBox {
Param (
[ValidateNotNull()]
[Parameter(Mandatory=$true)]
[System.Windows.Forms.ComboBox]$ComboBox,
[ValidateNotNull()]
[Parameter(Mandatory=$true)]
$Items,
[Parameter(Mandatory=$false)]
[string]$DisplayMember,
[switch]$Append
)
if (-not $Append) {
$ComboBox.Items.Clear()
}
if ($Items -is [Object[]]) {
$ComboBox.Items.AddRange($Items)
} elseif ($Items -is [Array]) {
$ComboBox.BeginUpdate()
foreach ($obj in $Items) {
$ComboBox.Items.Add($obj)
}
$ComboBox.EndUpdate()
} else {
$ComboBox.Items.Add($Items)
}
$ComboBox.DisplayMember = $DisplayMember
}
$btnSubmitNewNo_Click = {
$computerObject.name = 'IOT'
$computerObject.company = 'IOT'
$computerObject.departmentNumber = $departmentNumber
$computerObject.extensionAttribute15 = $accountType
$computerObject.SetInfo()
}
當我設置一個斷點,我讓所有的相關的值,最重要的是computerObject
。但是,當我嘗試SetInfo()
時出現錯誤。有人能幫忙嗎?再次,所有的computerObject.properties
都有值,但我得到SetInfo()
(第97行)的錯誤。
對不起,但我的問題是沒有人知道如何糾正這個錯誤 – Irwin
向我們展示您正在運行的命令 –
我已將它放入代碼標記中,因爲它使錯誤消息更清晰。我試過報價標籤,但看起來和以前一樣糟糕。我將OP的評論轉移到帖子中:他們正在尋找任何可能解決此錯誤的想法。 – TwoStraws