CmdLets/ConvertTo-LibraryCapture.ps1

Function ConvertTo-LibraryCapture 
 {

    [CmdletBinding()]
    Param(
        [Parameter(Mandatory=$True)]
            [System.Management.Automation.PSCredential]$LocalUser
    )
    New-LocalUser -name $LocalUser.UserName -password $LocalUser.Password -PasswordNeverExpires -UserMayNotchangePassword
    Add-LocalGroupMember -group "Administrators" -Member $LocalUser.UserName

    Get-AppxPackage -AllUsers | Where-Object { $_.Name -like "*Teams*"} | Remove-AppxPackage -AllUsers
    Get-AppxProvisionedPackage -Online | Where-Object { $_.DisplayName -like "*Teams*" } | Remove-AppxProvisionedPackage -Online

    $Paths = @(
        "hklm:\\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall",
        "hklm:\\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall"
    )

    $Keys = $Paths | Get-Childitem | Where-Object { $_.Property -Contains "DisplayName" -and $_.Property -NotContains "SystemComponent" }
    
    $Uninstall = @()

    $MSIs = @(
        "Omnissa Horizon Agent",
        "Omnissa Dynamic Environment Manager Enterprise"
    )

    ForEach ($MSI in $MSIs) {
        $Command = $Keys | Where-Object { ($_ | Get-ItemPropertyValue -Name DisplayName) -eq $MSI } | Get-ItemPropertyValue -Name UninstallString
        If ($Command) {
            $Command = $Command.Split(" ")
            $Uninstall += [PSCustomObject]@{
                Name = $MSI
                FilePath = "c:\Windows\System32\"+$Command[0]
                ArgumentList = $Command[1].Replace('/I','/X')+" /qn /norestart REBOOT=R"
            }
        }
    }

    $OneDrive = (Get-ChildItem (Join-Path $env:LocalAppData "Microsoft\OneDrive\*\OneDriveSetup.exe")).FullName
    If ($OneDrive) {
        $Uninstall+= [PSCustomObject]@{
            Name = "OneDrive"
            FilePath = $OneDrive
            ArgumentList = "/uninstall"
        }
    }

    $FSLogix = $Keys | Where-Object { ($_ | Get-ItemPropertyValue -Name DisplayName) -eq "Microsoft FSlogix Apps" } | Get-ItemPropertyValue -Name UninstallString
    If ($FSLogix) { 
        $Command = $FSLogix.Split('"')
        $Uninstall += [PSCustomObject]@{
            Name = "FSLogix"
            FilePath = $Command[1]
            ArgumentList = $Command[2].Trim()+" /quiet /norestart"
        }
    }

    Write-Host "Begining Uninstalls" -ForegroundColor Cyan
    $Uninstall | ForEach-Object {
        $_ | Format-List
        Watch-Process -Process (Start-Process -FilePath $_.FilePath -ArgumentList $_.ArgumentList -PassThru)
        Start-Sleep -Seconds 1
    }


}