Hi,
I am unable to validate and get the failed VM Name in the file.
Please help.
$computers = Get-Content -path ".\computers3.txt"
$report = foreach ($Computer in $Computers) {
$Computer = $Computer.toupper()
$Isonline = "OFFLINE"
$StatsError ="Failed"
if((Test-Connection -ComputerName $Computer -count 1 -ErrorAction 0)) {
$Isonline = "ONLINE"
} else { $StatsError= "`t$Computer is OFFLINE" }
try {
Add-Type -assemblyname system.DirectoryServices.accountmanagement
$DS = New-Object System.DirectoryServices.AccountManagement.PrincipalContext([System.DirectoryServices.AccountManagement.ContextType]::Machine)
$StatsError = $DS.ValidateCredentials("admin", "Password@123")
}
catch {
$StatsError="$_"
}
$ipv6 = Get-NetAdapterBinding -ComponentID ms_tcpip6 -CimSession $Computer
$obj = New-Object -TypeName PSObject -Property @{
ComputerName = $Computer
"ETH_Name" = $ipv6.Name
"ETH_DisplayName" = $ipv6.DisplayName
"IPv6_Status" = $ipv6.Enabled
}
$obj | Select ComputerName, "ETH_Name", "ETH_DisplayName", "IPv6_Status"
$obj | Select ComputerName, "ETH_Name", "ETH_DisplayName", "IPv6_Status" | Export-Csv -Append -Path $reportlocation -NoTypeInformation -UseCulture
}
$report | ft -auto
Error : I would like to get the hostname in the output file and screen, how can I get that. Please help
Get-NetAdapterBinding : APP10: Cannot connect to CIM server. The WinRM client cannot process the request because the server name cannot be resolved.
At D:\myreports\IPv6_info\get_ipv6_info.ps1:39 char:9
+ $ipv6 = Get-NetAdapterBinding -ComponentID ms_tcpip6 -CimSession $Com ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ResourceUnavailable: (MSFT_NetAdapterBindingSettingData:String) [Get-NetAdapterBinding], CimJobException
+ FullyQualifiedErrorId : CimJob_BrokenCimSession,Get-NetAdapterBinding
You do have $Computer in the output.
So what do you mean by 'hostname'
Further, there is no VM involved in this script, so how would you get the VMName in the output?
Or do you intend to search all your VMs if that FQDN ($Computer ?) is present in any of the VMs?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
LucD,
hostname is the computername.
I have used the below script to gather the VM Info
Get-VM | Where {$_.PowerState -eq 'PoweredOn' -and $_.Guest.OSFullName -match 'Microsoft'} | Select Name -Expandproperty Name | out-file D:\computer30.txt
I am unable to get the computername which fails to get the information from.
I see the value from $Computer in the output property ComputerName
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
LucD,
how can I get the computer name captured for failed one in a text file ?
You could do something like the other script we are discussing.
Use a $failed variable, which you set in the try or catch block.
Then depending on the value in $failed, you write the object the one file or the other.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
LucD,
the problem here is there are few powered of VMs, they are not getting captured in the output. I think, there is something issue with if statement below
$Isonline = "OFFLINE"
#$Status = "SUCCESS"
$StatsError ="Failed"
if((Test-Connection -ComputerName $Computer -count 1 -ErrorAction 0)) {
$Isonline = "ONLINE"
} else { $StatsError= "`t$Computer is OFFLINE" }
try {
Add-Type -assemblyname system.DirectoryServices.accountmanagement
$DS = New-Object System.DirectoryServices.AccountManagement.PrincipalContext([System.DirectoryServices.AccountManagement.ContextType]::Machine)
$StatsError = $DS.ValidateCredentials("admin", "P@ssword")
}
catch {
$StatsError="$_"
}
Try adding the Quiet switch to the Test-Connection cmdlet.
That will actually return $true or $false.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference