Powershell script to collect OS details
##################################################
$ipaddress=Get-Content -Path C:\ry\ansible\ip.txt
#$ErrorActionPreference='silentlycontinue'
$results = @()
ForEach ($i in $ipaddress)
{
$sess = New-PSSession -ComputerName $i
$osname=Invoke-Command -Session $sess -ScriptBlock {(gwmi win32_operatingsystem).caption}
$osbit=Invoke-Command -Session $sess -ScriptBlock {(Get-WmiObject Win32_OperatingSystem).OSArchitecture}
$hostname=Invoke-Command -Session $sess -ScriptBlock {(Get-WmiObject Win32_OperatingSystem).CSName}
$hItemDetails=[pscustomobject]@{
Hostname=$hostname
OS_Name=$osname
OS_bit=$osbit
}
$results +=$hItemDetails
}
$results | Export-Csv C:\ry\ansible\machinenames.csv
#############################################################
No comments:
Post a Comment