Computer: Rename computer is incorrectly triggered - requires conditional in Set-TargetResource
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 2/5
- Thời gian dự kiến
- 1-3 giờ
- Mức phù hợp với người mới
- 35/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức độ hoạt động
- Đình trệ
- Công nghệ
- powershell
- Lĩnh vực
- operating-systems
Hướng nghiên cứu
Bắt đầu bằng cách đọc các hàm Set-TargetResource và Test-TargetResource xung quanh các nhánh đổi tên domain và workgroup được xác định ở dòng 234 và 327. So sánh các kiểm tra tên hiện có với điều kiện được đề xuất, đồng thời xác minh rằng việc áp dụng cấu hình cho một tên máy tính khớp không còn gọi Rename-Computer, nhưng vẫn cập nhật các thuộc tính khác như Description.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Problem description
Issue:
The Computer resource is forcing a Rename-Computer command when the computer name is already correctly set, causing an error.
Details:
The Test-TargetResource function is checking multiple attributes:
Computer Name
Description
Workgroup or Domain
However, the Set-TargetResource function will always attempt to rename the computer, regardless of the current name, as referenced on line 234 (for domain) and line 327 (for workgroup). If the computer already has the correct name, this results in an error from Rename-Computer.
Impact:
While this may seem like a minor issue, it causes the status check to show as failed on the first run. This can be misleading, particularly during server deployments.
Additionally, Infrastructure as Code (IaC) cloud providers often set the computer name during VM deployments. Our Desired State Configuration (DSC) setups are targeted at server roles rather than individual servers, so we typically use "localhost" as the computer name.
Verbose logs
VERBOSE: Perform operation 'Invoke CimMethod' with following parameters, ''methodName' = SendConfigurationApply,'className' = MSFT_DSCLocalConfiguratio
nManager,'namespaceName' = root/Microsoft/Windows/DesiredStateConfiguration'.
VERBOSE: An LCM method call arrived from computer MVUDEVTST001 with user sid S-1-5-21-**************.
VERBOSE: [MVUDEVTST001]: LCM: [ Start Set ]
VERBOSE: [MVUDEVTST001]: LCM: [ Start Resource ] [[Computer]DomainJoin]
VERBOSE: [MVUDEVTST001]: LCM: [ Start Test ] [[Computer]DomainJoin]
VERBOSE: [MVUDEVTST001]: [[Computer]DomainJoin] Testing computer state for 'localhost'.
VERBOSE: [MVUDEVTST001]: [[Computer]DomainJoin] Checking if computer description is 'Windows Automation Worker node'.
VERBOSE: [MVUDEVTST001]: [[Computer]DomainJoin] Perform operation 'Enumerate CimInstances' with following parameters, ''name
spaceName' = root\cimv2,'className' = Win32_OperatingSystem'.
VERBOSE: [MVUDEVTST001]: [[Computer]DomainJoin] Operation 'Enumerate CimInstances' complete.
VERBOSE: [MVUDEVTST001]: LCM: [ End Test ] [[Computer]DomainJoin] in 0.4690 seconds.
VERBOSE: [MVUDEVTST001]: LCM: [ Start Set ] [[Computer]DomainJoin]
VERBOSE: [MVUDEVTST001]: [[Computer]DomainJoin] Setting computer state for 'localhost'.
VERBOSE: [MVUDEVTST001]: [[Computer]DomainJoin] Setting computer description to 'Windows Automation Worker node'.
VERBOSE: [MVUDEVTST001]: [[Computer]DomainJoin] Perform operation 'Enumerate CimInstances' with following parameters, ''name
spaceName' = root\cimv2,'className' = Win32_OperatingSystem'.
VERBOSE: [MVUDEVTST001]: [[Computer]DomainJoin] Operation 'Enumerate CimInstances' complete.
VERBOSE: [MVUDEVTST001]: [[Computer]DomainJoin] Perform operation 'Modify CimInstance' with following parameters, ''namespac
eName' = root/cimv2,'instance' = Win32_OperatingSystem: Microsoft Windows Server 2019 Datacenter'.
VERBOSE: [MVUDEVTST001]: [[Computer]DomainJoin] Operation 'Modify CimInstance' complete.
VERBOSE: [MVUDEVTST001]: [[Computer]DomainJoin] Perform operation 'Enumerate CimInstances' with following parameters, ''name
spaceName' = root\cimv2,'className' = Win32_ComputerSystem'.
VERBOSE: [MVUDEVTST001]: [[Computer]DomainJoin] Operation 'Enumerate CimInstances' complete.
Skip computer 'mvudevtst001' with new name 'MVUDEVTST001' because the new name is the same as the current name.
+ CategoryInfo : InvalidArgument: (MVUDEVTST001:) [], CimException
+ FullyQualifiedErrorId : NewNameIsOldName,Microsoft.PowerShell.Commands.RenameComputerCommand
+ PSComputerName : localhost
VERBOSE: [MVUDEVTST001]: [[Computer]DomainJoin] Renamed computer to 'MVUDEVTST001'.
VERBOSE: [MVUDEVTST001]: LCM: [ End Set ] [[Computer]DomainJoin] in 0.7350 seconds.
The PowerShell DSC resource '[Computer]DomainJoin' with SourceInfo '::35::9::Computer' threw one or more non-terminating errors while running the
Set-TargetResource functionality. These errors are logged to the ETW channel called Microsoft-Windows-DSC/Operational. Refer to this channel for more
details.
+ CategoryInfo : InvalidOperation: (:) [], CimException
+ FullyQualifiedErrorId : NonTerminatingErrorFromProvider
+ PSComputerName : localhost
VERBOSE: [MVUDEVTST001]: LCM: [ End Set ]
The SendConfigurationApply function did not succeed.
+ CategoryInfo : NotSpecified: (root/Microsoft/...gurationManager:String) [], CimException
+ FullyQualifiedErrorId : MI RESULT 1
+ PSComputerName : localhost
VERBOSE: Operation 'Invoke CimMethod' complete.
VERBOSE: Time taken for configuration job to complete is 6.048 seconds
DSC configuration
# real domain replaced with testdomain
Computer DomainJoin
{
Name = "localhost" # IaC providers always set the computername
Description = "Test Server"
DomainName = "testdomain.local"
Credential = $Cred
JoinOU = "CN=Computers,DC=testdomain,DC=local"
}
Suggested solution
Add the same conditional check around the Rename-Computer command from the Test-TargetResource. This way, if the Set is triggered due to the description not matching, it won't force the rename as well.
Example Code:
Line 234:
if ($DomainName -eq (Get-ComputerDomain))
{
if (($Name -ne 'localhost') -and ($Name -ne $env:COMPUTERNAME))
{
# Rename the computer, but stay joined to the domain.
Rename-Computer -NewName $Name -DomainCredential $Credential -Force
Write-Verbose -Message ($script:localizedData.RenamedComputerMessage -f $Name)
}
}...
Line 327:
if ($WorkGroupName -eq (Get-CimInstance -Class 'Win32_ComputerSystem').Workgroup)
{
if (($Name -ne 'localhost') -and ($Name -ne $env:COMPUTERNAME))
{
# Rename the computer, but stay in the same workgroup.
Rename-Computer `
-NewName $Name
Write-Verbose -Message ($script:localizedData.RenamedComputerMessage -f $Name)
}
}
As the rename at line 300 there to address a known issue I'm not sure if you would just leave that as is.
Operating system the target node is running
OsName : Microsoft Windows Server 2019 Datacenter
OsOperatingSystemSKU : DatacenterServerEdition
OsArchitecture : 64-bit
WindowsVersion : 1809
WindowsBuildLabEx : 17763.1.amd64fre.rs5_release.180914-1434
OsLanguage : en-US
OsMuiLanguages : {en-US}
PowerShell version and build the target node is running
Name Value
---- -----
PSVersion 5.1.17763.5933
PSEdition Desktop
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
BuildVersion 10.0.17763.5933
CLRVersion 4.0.30319.42000
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
ComputerManagementDsc version
Name Version Path
---- ------- ----
ComputerManagementDsc 9.1.0 C:\Program Files\WindowsPowerShell\Modules\ComputerManagementDsc\9.1.0\ComputerManagementDsc.psd1
- Ngôn ngữ chính
- PowerShell
- Star
- 338
- Fork
- 80
- Chỉ số merge pull request
- Không có pull request nào được merge trong 30 ngày
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của dsccommunity/ComputerManagementDsc
-
chore
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
-
chore
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 68/100
-
chore
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 64/100
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 55/100
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 35/100
Tất cả issue của dsccommunity/ComputerManagementDsc
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 84/100
-
compiler/runtime
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
golang/go#81836 · 2 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100
ComplianceAsCode/content#15152 ·
Maintainer thường phản hồi trong vòng 2 ngày
-
Area: Browsers bug report needs triage OS: Windows
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
actions/runner-images#14810 ·
Maintainer thường phản hồi trong vòng 3 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
Maintainer thường phản hồi trong vòng 1 ngày