Public/Get-Windows10HashUploadToAzure.ps1
function Get-Windows10HashUploadToAzure { <# .SYNOPSIS Capture Windows 10 Hashes and upload to Azure Blob automatically .DESCRIPTION Capture Windows 10 Hashes and upload to Azure Blob automatically It's meant to be used for BULK on multiple Windows 10 devices MUST need a dekstop management system to push the script (ex. KACE, SCCM, etc..) .REQUIREMENTS Download the CMD file (Get-Windows10HashUploadToAzure_batchfile.cmd) Define the values inside the batch file before running this script: BlobContainerUrl = Storage Account Blob URL BlobContainerResources = Blob Container name for the resources BlobContainerHashes = Blob Container name for the Windows 10 hashes BlobKey = Blob Storage Account Key .RECOMMENDED Encapsulate the script to run as an Scheduled Task $User = "NT AUTHORITY\SYSTEM" $Trigger = New-ScheduledTaskTrigger -At 12:00PM –Daily $Action = New-ScheduledTaskAction -Execute 'C:\Scripts\Get-Windows10HashUploadToAzure_batchfile.cmd' Register-ScheduledTask -TaskName "COREBTS_Collect_Upload_AzureBlob" -Trigger $Trigger -User $User -Action $Action -RunLevel Highest –Force .EXAMPLE As PowerShell Get-Windows10HashUploadToAzure -BlobContainerUrl "https://autopilothashes.blob.core.windows.net" -BlobContainerResources resources -BlobContainerHashes windows10hashes -BlobKey "86o5YE3VeWz1xADmRKBJFYfPoeRy9LQAsx8UYct7+KtpGF+Nk4dRMCxQS3G1vwG0lDqUfJfxC9kUlfzML74WUQ==" .EXAMPLE As CMD powershell.exe -ExecutionPolicy Bypass -Command ". C:\Scripts\Get-Windows10HashUploadToAzure.ps1 ; Get-Windows10HashUploadToAzure -BlobContainerUrl 'https://autopilothashes.blob.core.windows.net' -BlobContainerResources 'resources' -BlobContainerHashes 'windows10hashes' -BlobKey '86o5YE3VeWz1xADmRKBJFYfPoeRy9LQAsx8UYct7+KtpGF+Nk4dRMCxQS3G1vwG0lDqUfJfxC9kUlfzML74WUQ=='" .NOTES General notes #> param ( [Parameter(Mandatory)] $BlobContainerUrl, [Parameter(Mandatory)] $BlobContainerResources, [Parameter(Mandatory)] $BlobContainerHashes, [Parameter(Mandatory)] $BlobKey ) # Defining $fileName = "$env:computername" + "_" + "$env:username" + "_" + ".csv" $outputPath = Join-Path $env:windir "temp\AutoPilotScript" $azCopyExe = Join-Path $outputPath "AzCopy\AzCopy.exe" $outputFile = Join-Path $outputPath $fileName $autoPilotScript = Join-Path $PSScriptRoot "Get-WindowsAutoPilotInfo.ps1" # Creating directory if (-not (Test-Path $outputPath)) { $null = New-Item -Path $outputPath -ItemType Directory } # Downloading resources (Get-WindowsAutoPilotInfo.ps1 + AZCopy) from Azure Blob if (-not (Test-Path $autoPilotScript)) { Start-BitsTransfer -Source "$BlobContainerUrl/$BlobContainerResources/Get-WindowsAutoPilotInfo.ps1" -Destination $outputPath } if (-not (Test-Path $azCopyExe)) { Start-BitsTransfer -Source "$BlobContainerUrl/$BlobContainerResources/AzCopy.zip" -Destination $outputPath Add-Type -assembly "system.io.compression.filesystem" [io.compression.zipfile]::ExtractToDirectory($(Join-Path $outputPath "AzCopy.zip"), $(Join-Path $outputPath "AzCopy")) } # Collecting the Computer Hashes Start-Command -Command "powershell.exe" -Arguments "-ExecutionPolicy Bypass -File `"$autoPilotScript`" -ComputerName $env:computername -OutputFile `"$outputFile`"" | Out-Null #Start-Command -Command "powershell.exe" -Arguments ('-ExecutionPolicy Bypass -File "{0}" -ComputerName "{1}" -OutputFile "{2}"' -f $autoPilotScript, $env:computername, $outputFile) # Uploading the Computer Hashes to Azure Blob $url = "$BlobContainerUrl/$BlobContainerHashes" Start-Command -Command "`"$azCopyExe`"" -Arguments "/Source:`"$outputPath`" /Dest:$url /Pattern:$fileName /Y /Z:`"$(Join-Path $outputPath "AzCopy")`" /DestKey:`"$blobKey`"" | Out-Null # Results Write-Host -ForegroundColor Green "Locate Windows10Hash file under: " -NoNewline Write-Host -ForegroundColor Cyan $outputFile # Cleanup Remove-Item -Path $(Join-Path $outputPath "AzCopy.zip") -Force -ErrorAction SilentlyContinue | Out-Null Remove-Item -Path $(Join-Path $outputPath "AzCopy") -Recurse -Force -ErrorAction SilentlyContinue | Out-Null Remove-Item -Path $(Join-Path $outputPath "Get-WindowsAutoPilotInfo.ps1") -Recurse -Force -ErrorAction SilentlyContinue | Out-Null } # HELPER Function Start-Command { Param( [Parameter (Mandatory)] [string] $Command, [Parameter (Mandatory)] [string] $Arguments ) $pinfo = New-Object System.Diagnostics.ProcessStartInfo $pinfo.FileName = $Command $pinfo.RedirectStandardError = $true $pinfo.RedirectStandardOutput = $true $pinfo.CreateNoWindow = $true $pinfo.UseShellExecute = $false $pinfo.Arguments = $Arguments $p = New-Object System.Diagnostics.Process $p.StartInfo = $pinfo $p.Start() | Out-Null $p.WaitForExit() [pscustomobject]@{ stdout = $p.StandardOutput.ReadToEnd() stderr = $p.StandardError.ReadToEnd() ExitCode = $p.ExitCode } } |