08-18-2023 07:45 AM
Hi,
Does anyone know of way to get the domain from a server through PowerShell using the UCS PowerTool?
I have a lot of domains, so I'm using code bellow to connect to UCS central, and search for a server. The idea is connect the domain and clean the SEL logs, but I need the domain where the server is.
$ucscred=Get-Credential
$UCSCentral="ucs_central_url"
Connect-UcsCentral -credential $ucscred $UCSCentral
$servers=Get-UcsCentralServer
Disconnect-UcsCentral
foreach($srv in $servers){
if ($srv.UsrLbl -eq "server_name"){
Write-Host "Found!"
}
}
Solved! Go to Solution.
08-29-2023 09:55 AM
It looks like
Dn : compute/sys-1001/chassis-1/blade-8
Get-UcsCentralUcsDomain | select Name,Id | sort Name
Get-UcsCentralServiceProfile | ? { $_.Name -eq "SP_name" }| select Name, UsrLbl, Domain
$SPs = Get-UcsCentralServiceProfile
foreach ( $SP in $SPs ) {
if ( $_.UsrLbl -eq "server_label") {
$domain = $_.Domain
Write-Host "The domain for the server is $domain"
}
}
Note: Our Service Profile names and our VMware host names are aligned, which makes it very easy to combine PowerTool and PowerCLI commands against the same objects ( UCS SPs and VMware hosts).
08-18-2023 07:59 AM
- Try this :
$ucscred = Get-Credential
$UCSCentral = "ucs_central_url"
Connect-UcsCentral -credential $ucscred $UCSCentral
$servers = Get-UcsCentralServer
Disconnect-UcsCentral
foreach ($srv in $servers) {
if ($srv.UsrLbl -eq "server_name") {
$domain = $srv.AssignedToDn
Write-Host "The domain for the server is $domain"
}
}
M.
08-18-2023 08:10 AM
Unfortunately, that field doesn't get me the domain name:
AssignedToDn : org-root/org-test/ls-servername
08-29-2023 09:55 AM
It looks like
Dn : compute/sys-1001/chassis-1/blade-8
Get-UcsCentralUcsDomain | select Name,Id | sort Name
Get-UcsCentralServiceProfile | ? { $_.Name -eq "SP_name" }| select Name, UsrLbl, Domain
$SPs = Get-UcsCentralServiceProfile
foreach ( $SP in $SPs ) {
if ( $_.UsrLbl -eq "server_label") {
$domain = $_.Domain
Write-Host "The domain for the server is $domain"
}
}
Note: Our Service Profile names and our VMware host names are aligned, which makes it very easy to combine PowerTool and PowerCLI commands against the same objects ( UCS SPs and VMware hosts).
Discover and save your favorite ideas. Come back to expert answers, step-by-step guides, recent topics, and more.
New here? Get started with these tips. How to use Community New member guide