From 0a274b787e225d20a90e8050a1700920fe2cd42d Mon Sep 17 00:00:00 2001 From: "Jan Ketil Skanke [MVP]" Date: Sun, 14 Nov 2021 20:24:57 +0100 Subject: [PATCH] Delete Invoke-CustomInventoryV2.ps1 --- .../Invoke-CustomInventoryV2.ps1 | 431 ------------------ 1 file changed, 431 deletions(-) delete mode 100644 Firmware/Intune BIOS Update Control/CustomInventory_PR/Invoke-CustomInventoryV2.ps1 diff --git a/Firmware/Intune BIOS Update Control/CustomInventory_PR/Invoke-CustomInventoryV2.ps1 b/Firmware/Intune BIOS Update Control/CustomInventory_PR/Invoke-CustomInventoryV2.ps1 deleted file mode 100644 index e5519f5..0000000 --- a/Firmware/Intune BIOS Update Control/CustomInventory_PR/Invoke-CustomInventoryV2.ps1 +++ /dev/null @@ -1,431 +0,0 @@ -<# -.SYNOPSIS - Collect custom device inventory and upload to Log Analytics for further processing. - -.DESCRIPTION - This script will collect device hardware and / or app inventory and upload this to a Log Analytics Workspace. This allows you to easily search in device hardware and installed apps inventory. - The script is meant to be runned on a daily schedule either via Proactive Remediations (RECOMMENDED) in Intune or manually added as local schedule task on your Windows 10 Computer. - -.EXAMPLE - Invoke-CustomInventory.ps1 (Required to run as System or Administrator) - -.NOTES - FileName: Invoke-CustomInventory.ps1 - Author: Jan Ketil Skanke - Contributor: Sandy Zeng/Maurice Daly - Contact: @JankeSkanke - Created: 2021-01-02 - Updated: 2021-04-05 - - Version history: - 0.9.0 - (2021-01-02) Script created - 1.0.0 - (2021-01-02) Script polished cleaned up. - 1.0.1 - (2021-04-05) Added NetworkAdapter array and fixed typo - 1.1.0 - (2021-09-01) Removed all location information for privacy reasons - 2.0.0 - (2021-09-08) Added section to cater for BIOS release version information, for HP, Dell and Lenovo and general bugfixes - 2.0.1 - (2021-21-10) Added MACAddress to the inventory for each NIC. -#> -#region initialize -# Enable TLS 1.2 support -[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 -# Replace with your Log Analytics Workspace ID -$CustomerId = "" - -# Replace with your Primary Key -$SharedKey = "" - -#Control if you want to collect App or Device Inventory or both (True = Collect) -$CollectAppInventory = $true -$CollectDeviceInventory = $true - -# You can use an optional field to specify the timestamp from the data. If the time field is not specified, Azure Monitor assumes the time is the message ingestion time -# DO NOT DELETE THIS VARIABLE. Recommened keep this blank. -$TimeStampField = "" - -#endregion initialize - -#region functions -# Function to download files (speedtest) -function Start-DownloadFile { - param( - [parameter(Mandatory=$true)] - [ValidateNotNullOrEmpty()] - [string]$URL, - - [parameter(Mandatory=$true)] - [ValidateNotNullOrEmpty()] - [string]$Path, - - [parameter(Mandatory=$true)] - [ValidateNotNullOrEmpty()] - [string]$Name - ) - Begin { - # Construct WebClient object - $WebClient = New-Object -TypeName System.Net.WebClient - } - Process { - # Create path if it doesn't exist - if (-not(Test-Path -Path $Path)) { - New-Item -Path $Path -ItemType Directory -Force | Out-Null - } - - # Start download of file - $WebClient.DownloadFile($URL, (Join-Path -Path $Path -ChildPath $Name)) - } - End { - # Dispose of the WebClient object - $WebClient.Dispose() - } -}#endfunction -# Function to get all Installed Application -function Get-InstalledApplications() { - param( - [string]$UserSid - ) - - New-PSDrive -PSProvider Registry -Name "HKU" -Root HKEY_USERS | Out-Null - $regpath = @("HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\*") - $regpath += "HKU:\$UserSid\Software\Microsoft\Windows\CurrentVersion\Uninstall\*" - if (-not ([IntPtr]::Size -eq 4)) { - $regpath += "HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\*" - $regpath += "HKU:\$UserSid\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\*" - } - $propertyNames = 'DisplayName', 'DisplayVersion', 'Publisher', 'UninstallString' - $Apps = Get-ItemProperty $regpath -Name $propertyNames -ErrorAction SilentlyContinue | . { process { if ($_.DisplayName) { $_ } } } | Select-Object DisplayName, DisplayVersion, Publisher, UninstallString, PSPath | Sort-Object DisplayName - Remove-PSDrive -Name "HKU" | Out-Null - Return $Apps -} - -# Function to create the authorization signature -Function New-Signature ($customerId, $sharedKey, $date, $contentLength, $method, $contentType, $resource) { - $xHeaders = "x-ms-date:" + $date - $stringToHash = $method + "`n" + $contentLength + "`n" + $contentType + "`n" + $xHeaders + "`n" + $resource - - $bytesToHash = [Text.Encoding]::UTF8.GetBytes($stringToHash) - $keyBytes = [Convert]::FromBase64String($sharedKey) - - $sha256 = New-Object System.Security.Cryptography.HMACSHA256 - $sha256.Key = $keyBytes - $calculatedHash = $sha256.ComputeHash($bytesToHash) - $encodedHash = [Convert]::ToBase64String($calculatedHash) - $authorization = 'SharedKey {0}:{1}' -f $customerId, $encodedHash - return $authorization -} - -# Function to create and post the request -Function Send-LogAnalyticsData($customerId, $sharedKey, $body, $logType) { - $method = "POST" - $contentType = "application/json" - $resource = "/api/logs" - $rfc1123date = [DateTime]::UtcNow.ToString("r") - $contentLength = $body.Length - $signature = New-Signature ` - -customerId $customerId ` - -sharedKey $sharedKey ` - -date $rfc1123date ` - -contentLength $contentLength ` - -method $method ` - -contentType $contentType ` - -resource $resource - $uri = "https://" + $customerId + ".ods.opinsights.azure.com" + $resource + "?api-version=2016-04-01" - - #validate that payload data does not exceed limits - if ($body.Length -gt (31.9 *1024*1024)) - { - throw("Upload payload is too big and exceed the 32Mb limit for a single upload. Please reduce the payload size. Current payload size is: " + ($body.Length/1024/1024).ToString("#.#") + "Mb") - } - - $payloadsize = ("Upload payload size is " + ($body.Length/1024).ToString("#.#") + "Kb ") - - $headers = @{ - "Authorization" = $signature; - "Log-Type" = $logType; - "x-ms-date" = $rfc1123date; - "time-generated-field" = $TimeStampField; - } - - $response = Invoke-WebRequest -Uri $uri -Method $method -ContentType $contentType -Headers $headers -Body $body -UseBasicParsing - $statusmessage = "$($response.StatusCode) : $($payloadsize)" - return $statusmessage -} -function Start-PowerShellSysNative { - param ( - [parameter(Mandatory = $false, HelpMessage = "Specify arguments that will be passed to the sysnative PowerShell process.")] - [ValidateNotNull()] - [string]$Arguments - ) - - # Get the sysnative path for powershell.exe - $SysNativePowerShell = Join-Path -Path ($PSHOME.ToLower().Replace("syswow64", "sysnative")) -ChildPath "powershell.exe" - - # Construct new ProcessStartInfo object to run scriptblock in fresh process - $ProcessStartInfo = New-Object -TypeName System.Diagnostics.ProcessStartInfo - $ProcessStartInfo.FileName = $SysNativePowerShell - $ProcessStartInfo.Arguments = $Arguments - $ProcessStartInfo.RedirectStandardOutput = $true - $ProcessStartInfo.RedirectStandardError = $true - $ProcessStartInfo.UseShellExecute = $false - $ProcessStartInfo.WindowStyle = "Hidden" - $ProcessStartInfo.CreateNoWindow = $true - - # Instatiate the new 64-bit process - $Process = [System.Diagnostics.Process]::Start($ProcessStartInfo) - - # Read standard error output to determine if the 64-bit script process somehow failed - $ErrorOutput = $Process.StandardError.ReadToEnd() - if ($ErrorOutput) { - Write-Error -Message $ErrorOutput - } -}#endfunction -#endregion functions - -#region script -#Get Common data for App and Device Inventory: -#Get Intune DeviceID and ManagedDeviceName -if (@(Get-ChildItem HKLM:SOFTWARE\Microsoft\Enrollments\ -Recurse | Where-Object { $_.PSChildName -eq 'MS DM Server' })) { - $MSDMServerInfo = Get-ChildItem HKLM:SOFTWARE\Microsoft\Enrollments\ -Recurse | Where-Object { $_.PSChildName -eq 'MS DM Server' } - $ManagedDeviceInfo = Get-ItemProperty -LiteralPath "Registry::$($MSDMServerInfo)" -} -$ManagedDeviceName = $ManagedDeviceInfo.EntDeviceName -$ManagedDeviceID = $ManagedDeviceInfo.EntDMID -#Get Computer Info -$ComputerInfo = Get-ComputerInfo -$ComputerName = $ComputerInfo.CsName -$ComputerManufacturer = $ComputerInfo.CsManufacturer - -#region DEVICEINVENTORY -if ($CollectDeviceInventory) { - #Set Name of Log - $DeviceLog = "DeviceInventory" - - #Get Intune DeviceID and ManagedDeviceName - if (@(Get-ChildItem HKLM:SOFTWARE\Microsoft\Enrollments\ -Recurse | Where-Object { $_.PSChildName -eq 'MS DM Server' })) { - $MSDMServerInfo = Get-ChildItem HKLM:SOFTWARE\Microsoft\Enrollments\ -Recurse | Where-Object { $_.PSChildName -eq 'MS DM Server' } - $ManagedDeviceInfo = Get-ItemProperty -LiteralPath "Registry::$($MSDMServerInfo)" - } - $ManagedDeviceName = $ManagedDeviceInfo.EntDeviceName - $ManagedDeviceID = $ManagedDeviceInfo.EntDMID - - #Get Windows Update Service Settings - $DefaultAUService = (New-Object -ComObject "Microsoft.Update.ServiceManager").Services | Where-Object { $_.isDefaultAUService -eq $True } | Select-Object Name - $AUMeteredNetwork = (Get-ItemProperty -Path HKLM:\Software\Microsoft\WindowsUpdate\UX\Settings\).AllowAutoWindowsUpdateDownloadOverMeteredNetwork - if ($AUMeteredNetwork -eq "0") { - $AUMetered = "false" - } - else { $AUMetered = "true" } - -#Bandwitdh Checker -$SpeedTestExe = "$($env:SystemRoot)\temp\speedtest.exe" -if ((Test-Path -Path $SpeedTestExe) -eq $false){ - #Download and extract Speedtest Cli - try{ - $SpeedtestURL = "https://www.speedtest.net/apps/cli" - $WebResponseURL = ((Invoke-WebRequest -Uri $SpeedtestURL -UseBasicParsing -ErrorAction Stop -Verbose:$false).links | Where-Object { $_.outerHTML -like "*Download for Windows*" }).href - $SpeedtestcliFilename = Split-Path -Path $WebResponseURL -Leaf - Start-DownloadFile -URL $WebResponseURL -Path "$($env:SystemRoot)\temp" -Name $SpeedtestcliFilename - Expand-Archive "$($env:SystemRoot)\temp\$($SpeedtestcliFilename)" -DestinationPath "$($env:SystemRoot)\temp" -Force -ErrorAction Stop - } - catch{ - #Failed to download - $SpeedTestExe = $null - } -} -if ($SpeedTestExe -ne $null){ - $SpeedtestResults = & $SpeedTestExe --format=json --accept-license --accept-gdpr | ConvertFrom-Json - if (-not ([string]::IsNullOrEmpty($SpeedtestResults.download))){ - $DownloadSpeedMbps = [math]::Round($SpeedtestResults.download.bandwidth / 1000000 * 8, 2) - $UploadSpeedSpeedMbps = [math]::Round($SpeedtestResults.upload.bandwidth / 1000000 * 8, 2) - $NetLatencySec = [math]::Round($SpeedtestResults.ping.latency) - }else { - $DownloadSpeedMbps = 0 - $UploadSpeedSpeedMbps = 0 - $NetLatencySec = 0 - } -}else{ - $DownloadSpeedMbps = 0 - $UploadSpeedSpeedMbps = 0 - $NetLatencySec = 0 -} - - #Get Device Location - $ComputerPublicIP = (Invoke-WebRequest -UseBasicParsing -Uri "http://ifconfig.me/ip").Content - $Computerlocation = Invoke-RestMethod -Method Get -Uri "http://ip-api.com/json/$ComputerPublicIP" - $ComputerCountry = $Computerlocation.country - $ComputerCity = $Computerlocation.city - - # Get Computer Inventory Information - $ComputerModel = $ComputerInfo.CsModel - $ComputerUptime = [int]($ComputerInfo.OsUptime).Days - $ComputerLastBoot = $ComputerInfo.OsLastBootUpTime - $ComputerInstallDate = $ComputerInfo.OsInstallDate - $ComputerWindowsVersion = (Get-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\" -Name "DisplayVersion").DisplayVersion - $ComputerSystemSkuNumber = $ComputerInfo.CsSystemSKUNumber - $ComputerSerialNr = $ComputerInfo.BiosSeralNumber - $ComputerBiosUUID = Get-WmiObject Win32_ComputerSystemProduct | Select-Object -ExpandProperty UUID - $ComputerBiosVersion = $ComputerInfo.BiosSMBIOSBIOSVersion - $ComputerBiosDate = $ComputerInfo.BiosReleaseDate - $ComputerFirmwareType = $ComputerInfo.BiosFirmwareType - $ComputerPCSystemType = $ComputerInfo.CsPCSystemType - $ComputerPCSystemTypeEx = $ComputerInfo.CsPCSystemTypeEx - $ComputerPhysicalMemory = [Math]::Round(($ComputerInfo.CsTotalPhysicalMemory / 1GB)) - $ComputerOSBuild = (Get-ItemProperty 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion' -Name CurrentBuild).CurrentBuild - $ComputerOSRevision = (Get-ItemProperty 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion' -Name UBR).UBR - $ComputerCPU = Get-CimInstance win32_processor | Select-Object Name, Manufacturer, NumberOfCores, NumberOfLogicalProcessors - $ComputerProcessorManufacturer = $ComputerCPU.Manufacturer | Get-Unique - $ComputerProcessorName = $ComputerCPU.Name | Get-Unique - $ComputerNumberOfCores = $ComputerCPU.NumberOfCores | Get-Unique - $ComputerNumberOfLogicalProcessors = $ComputerCPU.NumberOfLogicalProcessors | Get-Unique - $TPMValues = Get-Tpm -ErrorAction SilentlyContinue | Select-Object -Property TPMReady, TPMPresent, TPMEnabled, TPMActivated, ManagedAuthLevel - $BitLockerInfo = Get-BitLockerVolume -MountPoint C: | Select-Object -Property * - $ComputerTPMReady = $TPMValues.TPMReady - $ComputerTPMPresent = $TPMValues.TPMPresent - $ComputerTPMEnabled = $TPMValues.TPMEnabled - $ComputerTPMActivated = $TPMValues.TPMActivated - $ComputerTPMThumbprint = (Get-TpmEndorsementKeyInfo).AdditionalCertificates.Thumbprint - $ComputerBitlockerCipher = $BitLockerInfo.EncryptionMethod - $ComputerBitlockerStatus = $BitLockerInfo.VolumeStatus - $ComputerBitlockerProtection = $BitLockerInfo.ProtectionStatus - $ComputerDefaultAUService = $DefaultAUService.Name - $ComputerAUMetered = $AUMetered - - #$timestamp = Get-Date -Format "yyyy-MM-DDThh:mm:ssZ" - - #Get network adapters - $NetWorkArray = @() - - $CurrentNetAdapters = Get-NetAdapter | Where-Object { $_.Status -eq 'Up' } - - foreach ($CurrentNetAdapter in $CurrentNetAdapters) { - $IPConfiguration = Get-NetIPConfiguration -InterfaceIndex $CurrentNetAdapter[0].ifIndex - $ComputerNetInterfaceDescription = $CurrentNetAdapter.InterfaceDescription - $ComputerNetProfileName = $IPConfiguration.NetProfile.Name - $ComputerNetIPv4Adress = $IPConfiguration.IPv4Address.IPAddress - $ComputerNetInterfaceAlias = $CurrentNetAdapter.InterfaceAlias - $ComputerNetIPv4DefaultGateway = $IPConfiguration.IPv4DefaultGateway.NextHop - - $tempnetwork = New-Object -TypeName PSObject - $tempnetwork | Add-Member -MemberType NoteProperty -Name "NetInterfaceDescription" -Value "$ComputerNetInterfaceDescription" -Force - $tempnetwork | Add-Member -MemberType NoteProperty -Name "NetProfileName" -Value "$ComputerNetProfileName" -Force - $tempnetwork | Add-Member -MemberType NoteProperty -Name "NetIPv4Adress" -Value "$ComputerNetIPv4Adress" -Force - $tempnetwork | Add-Member -MemberType NoteProperty -Name "NetInterfaceAlias" -Value "$ComputerNetInterfaceAlias" -Force - $tempnetwork | Add-Member -MemberType NoteProperty -Name "NetIPv4DefaultGateway" -Value "$ComputerNetIPv4DefaultGateway" -Force - $NetWorkArray += $tempnetwork - } - [System.Collections.ArrayList]$NetWorkArrayList = $NetWorkArray - - # Create JSON to Upload to Log Analytics - $Inventory = New-Object System.Object - $Inventory | Add-Member -MemberType NoteProperty -Name "ManagedDeviceName" -Value "$ManagedDeviceName" -Force - $Inventory | Add-Member -MemberType NoteProperty -Name "ManagedDeviceID" -Value "$ManagedDeviceID" -Force - $Inventory | Add-Member -MemberType NoteProperty -Name "ComputerName" -Value "$ComputerName" -Force - $Inventory | Add-Member -MemberType NoteProperty -Name "Model" -Value "$ComputerModel" -Force - $Inventory | Add-Member -MemberType NoteProperty -Name "Manufacturer" -Value "$ComputerManufacturer" -Force - $Inventory | Add-Member -MemberType NoteProperty -Name "PCSystemType" -Value "$ComputerPCSystemType" -Force - $Inventory | Add-Member -MemberType NoteProperty -Name "PCSystemTypeEx" -Value "$ComputerPCSystemTypeEx" -Force - $Inventory | Add-Member -MemberType NoteProperty -Name "ComputerUpTime" -Value "$ComputerUptime" -Force - $Inventory | Add-Member -MemberType NoteProperty -Name "LastBoot" -Value "$ComputerLastBoot" -Force - $Inventory | Add-Member -MemberType NoteProperty -Name "InstallDate" -Value "$ComputerInstallDate" -Force - $Inventory | Add-Member -MemberType NoteProperty -Name "WindowsVersion" -Value "$ComputerWindowsVersion" -Force - $Inventory | Add-Member -MemberType NoteProperty -Name "DefaultAUService" -Value "$ComputerDefaultAUService" -Force - $Inventory | Add-Member -MemberType NoteProperty -Name "AUMetered" -Value "$ComputerAUMetered" -Force - $Inventory | Add-Member -MemberType NoteProperty -Name "SystemSkuNumber" -Value "$ComputerSystemSkuNumber" -Force - $Inventory | Add-Member -MemberType NoteProperty -Name "SerialNumber" -Value "$ComputerSerialNr" -Force - $Inventory | Add-Member -MemberType NoteProperty -Name "SMBIOSUUID" -Value "$ComputerBiosUUID" -Force - $Inventory | Add-Member -MemberType NoteProperty -Name "BiosVersion" -Value "$ComputerBiosVersion" -Force - $Inventory | Add-Member -MemberType NoteProperty -Name "BiosDate" -Value "$ComputerBiosDate" -Force - $Inventory | Add-Member -MemberType NoteProperty -Name "FirmwareType" -Value "$ComputerFirmwareType" -Force - $Inventory | Add-Member -MemberType NoteProperty -Name "Memory" -Value "$ComputerPhysicalMemory" -Force - $Inventory | Add-Member -MemberType NoteProperty -Name "OSBuild" -Value "$ComputerOSBuild" -Force - $Inventory | Add-Member -MemberType NoteProperty -Name "OSRevision" -Value "$ComputerOSRevision" -Force - $Inventory | Add-Member -MemberType NoteProperty -Name "CPUManufacturer" -Value "$ComputerProcessorManufacturer" -Force - $Inventory | Add-Member -MemberType NoteProperty -Name "CPUName" -Value "$ComputerProcessorName" -Force - $Inventory | Add-Member -MemberType NoteProperty -Name "CPUCores" -Value "$ComputerNumberOfCores" -Force - $Inventory | Add-Member -MemberType NoteProperty -Name "CPULogical" -Value "$ComputerNumberOfLogicalProcessors" -Force - $Inventory | Add-Member -MemberType NoteProperty -Name "TPMReady" -Value "$ComputerTPMReady" -Force - $Inventory | Add-Member -MemberType NoteProperty -Name "TPMPresent" -Value "$ComputerTPMPresent" -Force - $Inventory | Add-Member -MemberType NoteProperty -Name "TPMEnabled" -Value "$ComputerTPMEnabled" -Force - $Inventory | Add-Member -MemberType NoteProperty -Name "TPMActived" -Value "$ComputerTPMActivated" -Force - $Inventory | Add-Member -MemberType NoteProperty -Name "TPMThumbprint" -Value "$ComputerTPMThumbprint" -Force - $Inventory | Add-Member -MemberType NoteProperty -Name "BitlockerCipher" -Value "$ComputerBitlockerCipher" -Force - $Inventory | Add-Member -MemberType NoteProperty -Name "BitlockerVolumeStatus" -Value "$ComputerBitlockerStatus" -Force - $Inventory | Add-Member -MemberType NoteProperty -Name "BitlockerProtectionStatus" -Value "$ComputerBitlockerProtection" -Force - $Inventory | Add-Member -MemberType NoteProperty -Name "ComputerCountry" -Value "$ComputerCountry" -Force - $Inventory | Add-Member -MemberType NoteProperty -Name "ComputerCity" -Value "$ComputerCity" -Force - $Inventory | Add-Member -MemberType NoteProperty -Name "NetworkAdapters" -Value $NetWorkArrayList -Force - $Inventory | Add-Member -MemberType NoteProperty -Name "DownloadSpeedMbps" -Value $DownloadSpeedMbps -Force - $Inventory | Add-Member -MemberType NoteProperty -Name "UploadSpeedSpeedMbps" -Value $UploadSpeedSpeedMbps -Force - $Inventory | Add-Member -MemberType NoteProperty -Name "NetLatencySec" -Value $NetLatencySec -Force - - $Devicejson = $Inventory | ConvertTo-Json - - # Submit the data to the API endpoint - $ResponseDeviceInventory = Send-LogAnalyticsData -customerId $customerId -sharedKey $sharedKey -body ([System.Text.Encoding]::UTF8.GetBytes($Devicejson)) -logType $DeviceLog -}#endregion DEVICEINVENTORY - -#region APPINVENTORY -if ($CollectAppInventory) { - $AppLog = "AppInventory" - - #Get SID of current interactive users - $CurrentLoggedOnUser = (Get-WmiObject -Class win32_computersystem).UserName - $AdObj = New-Object System.Security.Principal.NTAccount($CurrentLoggedOnUser) - $strSID = $AdObj.Translate([System.Security.Principal.SecurityIdentifier]) - $UserSid = $strSID.Value - #Get Apps for system and current user - $MyApps = Get-InstalledApplications -UserSid $UserSid - $UniqueApps = ($MyApps | Group-Object Displayname | Where-Object { $_.Count -eq 1 } ).Group - $DuplicatedApps = ($MyApps | Group-Object Displayname | Where-Object { $_.Count -gt 1 } ).Group - $NewestDuplicateApp = ($DuplicatedApps | Group-Object DisplayName) | ForEach-Object { $_.Group | Sort-Object [version]DisplayVersion -Descending | Select-Object -First 1 } - $CleanAppList = $UniqueApps + $NewestDuplicateApp | Sort-Object DisplayName - - $AppArray = @() - foreach ($App in $CleanAppList) { - $tempapp = New-Object -TypeName PSObject - $tempapp | Add-Member -MemberType NoteProperty -Name "ComputerName" -Value "$ComputerName" -Force - $tempapp | Add-Member -MemberType NoteProperty -Name "ManagedDeviceName" -Value "$ManagedDeviceName" -Force - $tempapp | Add-Member -MemberType NoteProperty -Name "ManagedDeviceID" -Value "$ManagedDeviceID" -Force - $tempapp | Add-Member -MemberType NoteProperty -Name "AppName" -Value $App.DisplayName -Force - $tempapp | Add-Member -MemberType NoteProperty -Name "AppVersion" -Value $App.DisplayVersion -Force - $tempapp | Add-Member -MemberType NoteProperty -Name "AppInstallDate" -Value $App.InstallDate -Force -ErrorAction SilentlyContinue - $tempapp | Add-Member -MemberType NoteProperty -Name "AppPublisher" -Value $App.Publisher -Force - $tempapp | Add-Member -MemberType NoteProperty -Name "AppUninstallString" -Value $App.UninstallString -Force - $tempapp | Add-Member -MemberType NoteProperty -Name "AppUninstallRegPath" -Value $app.PSPath.Split("::")[-1] - $AppArray += $tempapp - } - - $Appjson = $AppArray | ConvertTo-Json - - # Submit the data to the API endpoint - $ResponseAppInventory = Send-LogAnalyticsData -customerId $customerId -sharedKey $sharedKey -body ([System.Text.Encoding]::UTF8.GetBytes($Appjson)) -logType $AppLog -} -#endregion APPINVENTORY - -#Report back status -$date = Get-Date -Format "dd-MM HH:mm" -$OutputMessage = "InventoryDate:$date " - -if ($CollectDeviceInventory) { - if ($ResponseDeviceInventory -match "200 :") { - - $OutputMessage = $OutPutMessage + "DeviceInventory:OK " + $ResponseDeviceInventory - } - else { - $OutputMessage = $OutPutMessage + "DeviceInventory:Fail " - } -} -if ($CollectAppInventory) { - if ($ResponseAppInventory -match "200 :") { - - $OutputMessage = $OutPutMessage + " AppInventory:OK " + $ResponseAppInventory - } - else { - $OutputMessage = $OutPutMessage + " AppInventory:Fail " - } -} -Write-Output $OutputMessage -Exit 0 - - - -#endregion script \ No newline at end of file