Quantcast
Channel: Windows PowerShell forum
Viewing all articles
Browse latest Browse all 21975

Assistance with bringing two scripts together

$
0
0

Hello,

I have the following script that will successfully give me the IP address, DNS, Netmask, MAC Address etc for my VM's.  I want to add to this script the following:

  1. To show free space for each drive for each VM in my input list (I have a script that will show me the space available for one VM only).
  2. To show if a MAC Address is static or not from VMM (I don't have a script for this).

Here is my script to find free space:

$hostname=Read-host "Enter the computer name"
get-wmiobject -computer $hostname win32_logicaldisk -filter "drivetype=3" | ForEach-Object { Write-Host  Device name : $_.deviceid; write-host Total space : ($_.size/1GB).tostring("0.00")GB; write-host Free Spce : ($_.freespace/1GB).tostring("0.00")GB; write-host " " }
#Write-Host "Press any key to Continue..."

Here is my script to give me networking details for a list of VM's:

#param (
    $inputFile = "C:\Apps\Powershell_Scripts\IP_Mac\FullList.txt"
    $csvFile = "C:\Apps\Powershell_Scripts\IP_Mac\FullList_results.csv"
#    ) 

 $report = @()

 foreach($Computer in (gc -Path $inputFile)){
  if(Test-Connection -ComputerName $Computer -Count 1 -ea 0) {
   $Networks = Get-WmiObject Win32_NetworkAdapterConfiguration -ComputerName $Computer | ? {$_.IPEnabled}
   foreach ($Network in $Networks) {
    $IPAddress  = $Network.IpAddress[0]
    $SubnetMask  = $Network.IPSubnet[0]
    $DefaultGateway = $Network.DefaultIPGateway
    $DNSServers  = $Network.DNSServerSearchOrder
    }
    $MACAddress  = $Network.MACAddress
    $OutputObj  = New-Object -Type PSObject
    $OutputObj | Add-Member -MemberType NoteProperty -Name ComputerName -Value $Computer.ToUpper()
    $OutputObj | Add-Member -MemberType NoteProperty -Name IPAddress -Value $IPAddress
    $OutputObj | Add-Member -MemberType NoteProperty -Name SubnetMask -Value $SubnetMask
    $OutputObj | Add-Member -MemberType NoteProperty -Name Gateway -Value ($DefaultGateway -join “,”)
    $OutputObj | Add-Member -MemberType NoteProperty -Name DNSServers -Value ($DNSServers -join ",")
    $OutputObj | Add-Member -MemberType NoteProperty -Name MACAddress -Value $MACAddress
    #$OutputObj
    $report += ,$OutputObj
   }
  }
 }
     Write-Output $report
#}  

$report | Select-Object -Property $properties | Export-Csv -Path $csvFile -NoTypeInformation

How do I put these two scripts together, add in the ability to check if the MAC address is static from VMM and write all the results to a .csv file?

Thank you.


Viewing all articles
Browse latest Browse all 21975

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>