Quantcast
Channel: PowerShell.com – PowerShell Scripts, Tips, Forums, and Resources
Viewing all articles
Browse latest Browse all 6937

Trying to find the model of the machines

$
0
0

Hello Good Afternoon everyone 

Im currently upgrading machine at my job i wrote a script that will tell me which machines are offline but i also want it to tell me what model the machine currently is, Can you please take some time and look at my script and see how it can be modified to give me the name of the machine and the model .

Thank you for all the help 

Import-Module activedirectory

$rtn = $null

$time = (Get-Date).AddDays(-30)

$erroractionpreference = 'SilentlyContinue'  #default is 'Continue' #St 

$debugpreference = 'Continue' #silentlycontinue

 

del C:\Capstone\dacto.txt

 

Get-ADComputer -Filter {modified -lt $time -and OperatingSystem -like 'Windows 7*'} |ForEach-Object {

 

    $rtn = Test-Connection -CN $_.dnshostname -Count 1 -BufferSize 16 -Quiet

 

    if($rtn -eq $True) {

        #Write-Debug "Test-Connection returns true"

        $wmiinfo = get-wmiobject -computername $_.dnshostname -Class Win32_computersystem

        #Write-Debug "wmi: $($wmiinfo.name)"

        #Write-Debug "AD: $($_.name)"

 

        if($wmiinfo.name -eq $_.name) {

             Write-Debug "Wmi name eq name $($wmiinfo.name) -eq $($_.name)"

             write-host -ForegroundColor green $_.dnshostname

        }       

        else {

             Write-Debug "Wmi else"

             Write-host -ForegroundColor red $_.dnshostname

             "$($_.name)" | out-file -File 'c:\capstone\dacto.txt' -Append

        }

    }  

    else { 

        Write-host -ForegroundColor red $_.dnshostname

        "$($_.name)" | out-file -File 'c:\capstone\dacto.txt' -Append

 

    }

    $wmiinfo = $null

 

}


Viewing all articles
Browse latest Browse all 6937

Trending Articles