2.Check_key&get_serialnumber

####key 
salt '*' license.info
#if license shows false, activate it

####get serialnumber
salt '*' cmd.run 'wmic bios get serialnumber'

####get information by command,output file in C:\ , and edit in excel 
salt '*' cmd.run 'Powershell -NoProfile -ExecutionPolicy Bypass -Command D:\software\system_inspection.ps1'

system_inspection.ps1
$Out_Object = New-Object PSObject
$Out_Object | Add-Member Noteproperty Info $null
$Out_Object | Add-Member Noteproperty CurrentValue $null
$Out_Object | Add-Member Noteproperty PolicyValue $null
#$out_path = "C:\test.csv"
#$out_path = "C:\{0}.csv" -f $env:computername
$datepath= Get-Date -Format \I\n\s\p\e\c\t\i\o\n\_\L\o\g\_yyyy_MM_dd
$timepath= Get-Date -Format yyyy_MM_dd_HHmmss
$dirpath = "D:\{0}" -f $datepath
$filename = "{0}_{1}.csv" -f $env:computername, $timepath
 
 
new-item $dirpath -itemtype directory -ErrorAction SilentlyContinue
 
$out_path = $dirpath+"\"+$filename
 
$new_out = 1
 
function NewInfoOut
{
    param( [string]$str, [Object]$obj )
    $obj.Info = $null
    $obj.CurrentValue = $null
    if($new_out -eq 1){
        #Export-Csv -InputObject $obj -Path $out_path -NoTypeInformation -Encoding UTF8
        ''|Out-File $out_path -Encoding UTF8
        $str|Out-File $out_path -Encoding UTF8
    }
    else {
        #Export-Csv -InputObject $obj -Path $out_path -NoTypeInformation -Encoding UTF8
        ''|Out-File $out_path -append -Encoding UTF8
        $str|Out-File $out_path -append -Encoding UTF8
    }
    $obj.Info = $str
    #Export-Csv -InputObject $obj -Path $out_path -NoTypeInformation -Encoding UTF8
    write-host $null
    write-host $str -ForegroundColor Yellow
}
 function addOutLine
{
    param( [Object]$obj, [string]$str, [string]$c_value, [string]$p_value )
    $obj.Info = $str
    $obj.CurrentValue = $c_value
    $obj.PolicyValue = $p_value
   
    if($obj.PolicyValue -eq ""){
        #Export-Csv -InputObject $obj -Path $out_path -NoTypeInformation
        $sss = "{0,-30} : {1,-50} {2,-30}" -f $str,$c_value,$p_value
        "$($str),$($c_value)"|Out-File $out_path -append -Encoding UTF8
        write-host  $sss
    }
    else{
        #Export-Csv -InputObject $obj -Path $out_path -NoTypeInformation
        #$sss = "{0,-30} : {1,-50} {2,-30}" -f $str,$c_value,$p_value
        #$sss = "{0,-30} : {1,-50}" -f $str,$c_value
        $sss = "{0,-30} : " -f $str
        if($c_value -eq $p_value){
            write-host  $sss -NoNewline
            $v1="{0,-50} {1}" -f $c_value,$p_value
            write-host $v1 -f Green
        }
        else{
            write-host  $sss -NoNewline
            $v1="{0,-50} {1}" -f $c_value,$p_value
            write-host $v1 -f Red
        }
    }
}
 
NewInfoOut "[System Information]" $Out_Object
$new_out = 0
foreach ($os in Get-Wmiobject -class win32_operatingsystem) {
    addOutLine $Out_Object "HostName" $os.csname
    addOutLine $Out_Object "Operating System" $os.caption
}
 
foreach ($bios in Get-WmiObject -class win32_bios) {
    addOutLine $Out_Object "Vendor" $bios.manufacturer
    addOutLine $Out_Object "Serial" $bios.serialnumber.Trim()
}
foreach ($sys in Get-Wmiobject -class win32_computersystem) {
    addOutLine $Out_Object "Model" $sys.model
}
 
 
NewInfoOut "[CPU Information]" $Out_Object
$cpu_cnt=0
$total_pcore=0
$total_lcore=0
foreach ($processor in Get-WmiObject -class win32_processor) {
    addOutLine $Out_Object "CPU" $processor.name
    addOutLine $Out_Object "Physical Cores" "$($processor.numberofcores) core"
    addOutLine $Out_Object "Logical Processors" "$($processor.NumberOfLogicalProcessors) core"
    $total_pcore+=$processor.numberofcores
    $total_lcore+=$processor.NumberOfLogicalProcessors
    $cpu_cnt++
}
addOutLine $Out_Object "Total Physical Cores" "$($total_pcore) cores"
addOutLine $Out_Object "Total Logical Processors" "$($total_lcore) processors"
addOutLine $Out_Object "Number of Sockets" "$($cpu_cnt) sockets"
 
 
NewInfoOut "[Memory Information]" $Out_Object
$mem_cnt=0
$mem_total=0
foreach ($memory in Get-WmiObject -class win32_physicalmemory) {
    $mem_cnt++
    $mem_total=$mem_total + ($memory.capacity)/1GB
    addOutLine $Out_Object "Slot $($mem_cnt)" "$($memory.capacity/1GB)GB / $($memory.speed) MHz"
}
addOutLine $Out_Object "Number of Slots" "$($mem_cnt) slot"
addOutLine $Out_Object "Total Size" "$($mem_total) GB"
 
 
NewInfoOut "[Disk Information]" $Out_Object
$volume_cnt=0
foreach ($disk in Get-WmiObject -class win32_logicaldisk) {
    addOutLine $Out_Object "Volume $($volume_cnt) ($($disk.Caption))" "$([math]::Round($disk.size/1GB,2)) GB"
    $volume_cnt++
}
 
 
NewInfoOut "[Pagefile Setting]" $Out_Object
foreach ($page in Get-WmiObject -class win32_pagefile) {
    addOutLine $Out_Object "Page" "$($page.name)"
    addOutLine $Out_Object "Start" "$($page.initialSize) MB"
    addOutLine $Out_Object "End" "$($page.maximumsize) MB"
}
 
NewInfoOut "[Power Option Setting]" $Out_Object
$my_scheme=powercfg -getactivescheme
addOutLine $Out_Object "Power setting" "$($my_scheme.split(": ")[6]) $($my_scheme.split(": ")[7]) $($my_scheme.split(": ")[8]) $($my_scheme.split(": ")[9])"
 
 
NewInfoOut "[TCP Global Variable]" $Out_Object
$tcp=netsh int tcp show global
addOutLine $Out_Object "RSS" $tcp[4].split(":")[1].trim()
addOutLine $Out_Object "Chim." $tcp[5].split(":")[1].trim()
addOutLine $Out_Object "NetDMA" $tcp[6].split(":")[1].trim()
addOutLine $Out_Object "DCA" $tcp[7].split(":")[1].trim()
addOutLine $Out_Object "Auto" $tcp[8].split(":")[1].trim()
addOutLine $Out_Object "Con." $tcp[9].split(":")[1].trim()
addOutLine $Out_Object "ECN" $tcp[10].split(":")[1].trim()
addOutLine $Out_Object "Time" $tcp[11].split(":")[1].trim()
 
 
NewInfoOut "[Firewall Setting]" $Out_Object
 
$f_status = netsh advfirewall show allprofiles|Select-String -pattern "상ío태A"
$f_status = $f_status|Out-String
$f_status = $f_status.trim()
$f_status = $f_status -replace '\s\s+',':'
 
 
addOutLine $Out_Object "Domain Profile" $f_status.split(':')[1]
addOutLine $Out_Object "Private Profile" $f_status.split(':')[3]
addOutLine $Out_Object "Public Profile" $f_status.split(':')[5]
 
#$FwList=get-netfirewallprofile|findstr /B "Name Enabled"
#addOutLine $Out_Object "$($FwList[0].split(":")[1].trim()) Profile" $FwList[1].split(":")[1]
#addOutLine $Out_Object "$($FwList[2].split(":")[1].trim()) Profile" $FwList[3].split(":")[1]
#addOutLine $Out_Object "$($FwList[4].split(":")[1].trim()) Profile" $FwList[5].split(":")[1]
 
 
NewInfoOut "[Remote Desktop Setting]" $Out_Object
$port_reg1 = Get-ItemProperty -Path HKLM:'\system\currentcontrolset\control\terminal server\wds\rdpwd\tds\tcp' -Name PortNumber
$port_reg2 = Get-ItemProperty -Path HKLM:'\system\currentcontrolset\control\terminal server\winstations\rdp-tcp' -Name PortNumber
addOutLine $Out_Object "Remote Portnumber" $port_reg2.PortNumber
$L_port = netstat -na |findstr :$($port_reg2.PortNumber)
 
if($L_port -ne $null){
    addOutLine $Out_Object "Remote Port Status" "$($L_port[0].Substring(55))"
}
else{
    addOutLine $Out_Object "Remote Port Status" "Closed"
}
 
$reg_name = 'fDenyTSConnections', 'fInheritMaxDisconnectionTime','fInheritMaxIdleTime', 'fInheritMaxSessionTime', 'fInheritResetBroken', 'fSingleSessionPerUser', 'UserAuthentication'
$reg = New-Object System.Collections.ArrayList
$reg += (Get-ItemProperty -Path HKLM:'\System\CurrentControlSet\Control\Terminal Server' -Name fDenyTSConnections).fDenyTSConnections
$reg += (Get-ItemProperty -Path HKLM:'\system\currentcontrolset\control\terminal server\WinStations\RDP-Tcp' -Name fInheritMaxDisconnectionTime).fInheritMaxDisconnectionTime
$reg += (Get-ItemProperty -Path HKLM:'\system\currentcontrolset\control\terminal server\WinStations\RDP-Tcp' -Name fInheritMaxIdleTime).fInheritMaxIdleTime
$reg += (Get-ItemProperty -Path HKLM:'\system\currentcontrolset\control\terminal server\WinStations\RDP-Tcp' -Name fInheritMaxSessionTime).fInheritMaxSessionTime
$reg += (Get-ItemProperty -Path HKLM:'\system\currentcontrolset\control\terminal server\WinStations\RDP-Tcp' -Name fInheritResetBroken).fInheritResetBroken
 
#2012
if($os.Caption -eq 'Microsoft Windows Server 2012 R2 Standard'){
    $reg += (Get-ItemProperty -Path HKLM:'\system\currentcontrolset\control\terminal server' -Name fSingleSessionPerUser).fSingleSessionPerUser
    $reg += (Get-ItemProperty -Path HKLM:'\SYSTEM\CurrentControlSet\Control\Terminal Server\WinStations\RDP-Tcp' -Name UserAuthentication).UserAuthentication
}
 
$regcnt=0
foreach ($regval in $reg){
    if($regval -eq 0){
        addOutLine $Out_Object $reg_name[$regcnt] Off
    }
    else{
        addOutLine $Out_Object $reg_name[$regcnt] On
    }
    $regcnt++
}
 
NewInfoOut "[OS License Status]" $Out_Object
$license_status = cscript C:\Windows\System32\slmgr.vbs /dli | Select-String -pattern "License"
$license_status = $license_status|Out-String
$license_status = $license_status.trim().split(":")[1].trim()
addOutLine $Out_Object "License Status" $license_status
 
#$license_status = Get-CimInstance -ClassName SoftwareLicensingProduct | where PartialProductKey | select Name, ApplicationID, LicenseStatus
#addOutLine $Out_Object "Name" $license_status.Name
#if($license_status.LicenseStatus -eq 1) {addOutLine $Out_Object "LicenseStatus" "Licensed"}
#elseif($license_status.LicenseStatus -eq 0) {addOutLine $Out_Object "LicenseStatus" "Unlicensed"}
 
NewInfoOut "[System Locale Information]" $Out_Object
$loc = wmic os get locale /value |findstr /c:"Locale"
addOutLine $Out_Object "System Locale" $loc.split("=")[1]
#$loc = Get-WinSystemLocale
#addOutLine $Out_Object "LCID (Decimal)" $loc.LCID
#addOutLine $Out_Object "Name" $loc.Name
 
 
NewInfoOut "[SCSI Information]" $Out_Object
foreach ($scsi in get-WmiObject -query "select * from win32_pnpsigneddriver where DeviceClass='SCSIADAPTER'" ){
   
    addOutLine $Out_Object SCSI "$($scsi.description) - $($scsi.driverVersion)"
}
 
Try{
    $NetListArray=Get-NetAdapter | findstr "Up"
    if ($NetListArray.count -eq 0) {
    }
    elseif ($NetListArray.count -eq 1) {
        $NetNameArray=$NetListArray.split(" ")[0]
        $NetRSSArray=get-netadapterrss -name $NetNameArray|findstr /B "Name Enabled NumberOfReceiveQueues Profile BaseProcessor MaxProcessors"
        $outstr = "[{0} - NetAdapter Information]" -f $NetRSSArray[0].split(":")[1].trim()
        NewInfoOut $outstr $Out_Object
        addOutline $Out_object "Enabled" $NetRSSArray[1].split(":")[1].trim()
        addOutline $Out_object "RSSQ" $NetRSSArray[2].split(":")[1].trim()
        addOutline $Out_object "Prof" $NetRSSArray[3].split(":")[1].trim()
        addOutline $Out_object "BaseGroup" $NetRSSArray[4].split(":")[3].trim()
        addOutline $Out_object "BaseProc" $NetRSSArray[4].split(":")[4].trim()
        addOutline $Out_object "MaxProc" $NetRSSArray[5].split(":")[1].trim()  
    }
    else {
        $NetNameArray="NONE","NONE","NONE","NONE"
        for ($i=0; $i -lt $NetListArray.count; $i=$i+1) {$NetNameArray[$i]=$NetListArray[$i].split(" ")[0]}
        for ($i=0; $i -lt $NetListArray.count; $i=$i+1) {
            $NetRSSArray=get-netadapterrss -name $NetNameArray[$i]|findstr /B "Name Enabled NumberOfReceiveQueues Profile BaseProcessor MaxProcessors"
            $outstr = "[{0} - NetAdapter Information]" -f $NetRSSArray[0].split(":")[1].trim()
            NewInfoOut $outstr $Out_Object
            addOutline $Out_object "Enabled" $NetRSSArray[1].split(":")[1].trim()
            addOutline $Out_object "RSSQ" $NetRSSArray[2].split(":")[1].trim()
            addOutline $Out_object "Prof" $NetRSSArray[3].split(":")[1].trim()
            addOutline $Out_object "BaseGroup" $NetRSSArray[4].split(":")[3].trim()
            addOutline $Out_object "BaseProc" $NetRSSArray[4].split(":")[4].trim()
            addOutline $Out_object "MaxProc" $NetRSSArray[5].split(":")[1].trim()
        }
    }
}
Catch{
}
 
 
NewInfoOut "[NIC Information]" $Out_Object
$nic_cnt=0
foreach ($nic in Get-WmiObject -query "select * from win32_pnpsigneddriver where DeviceClass='NET' AND NOT description like '%WAN%'") {
   
    addOutLine $Out_Object "NIC $($nic_cnt)" "$($nic.description) - $($nic.driverversion)"
    $nic_cnt+=1
}
$net_cnt=0
 
foreach ($net in Get-WmiObject -query "select * from win32_networkadapterconfiguration where IPEnabled=true") {
   
    NewInfoOut "[Network Interface $($net_cnt)]" $Out_Object
    addOutLine $Out_Object "Interface Name" $net.description
    addOutLine $Out_Object "MAC address" $net.macaddress
    addOutLine $Out_Object "IP Address" $net.IPAddress[0]
    addOutLine $Out_Object Subnet $net.ipsubnet
    addOutLine $Out_Object GateWay $net.defaultipgateway
   
    if($net.DNSServerSearchOrder -ne $null) {
        if($net.DNSServerSearchOrder[1] -ne $null){
            addOutLine $Out_Object DNS "$($net.DNSServerSearchOrder[0]) / $($net.DNSServerSearchOrder[1])"
        }
        else{
            addOutLine $Out_Object DNS $net.DNSServerSearchOrder
        }       
    }
    else {
        addOutLine $Out_Object DNS $net.DNSServerSearchOrder
    }
    $net_cnt+=1
}
Write-Host "Inspection Log : $($dirpath)\$($filename)"

Last updated