#Onedrive Checkor
#Made by Kieren Anderson

cls

write-host
Write-Host Onedrive for Business - Check Requirements
write-host

start-sleep -s 5

$path = Read-Host -Prompt 'Type the location to Onedrive'

#Item Count
write-host ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
write-host
write-host Item Count -ForegroundColor Red -BackgroundColor white
write-host
Write-Warning 'Under 20,000 items?'
write-host
Get-ChildItem -Recurse -Path $path | Measure-Object | %{$\_.Count} > C:\\Count.txt
write-host items
Get-Content C:\\Count.txt
Remove-Item C:\\Count.txt
Start-Sleep -s 5
Write-Host "Press any key to continue ..."
$x = $host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")

#Characters Count
write-host ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
write-host
Write-host Characters Count -ForegroundColor Red -BackgroundColor white
write-host
write-warning 'Character limit of under 256'
write-host
start-sleep -s 3

$pathToScan = $path  
$outputFilePath = 'C:\\CountCharacter.txt' 
$writeToConsoleAsWell = $true   

# Open a new file stream (nice and fast) and write all the paths and their lengths to it.
$outputFileDirectory = Split-Path $outputFilePath -Parent
if (!(Test-Path $outputFileDirectory)) { New-Item $outputFileDirectory -ItemType Directory }
$stream = New-Object System.IO.StreamWriter($outputFilePath, $false)
Get-ChildItem -Path $pathToScan -Recurse -Force | Select-Object -Property FullName, @{Name="FullNameLength";Expression={($\_.FullName.Length)}} | Sort-Object -Property FullNameLength -Descending | ForEach-Object {
    $filePath = $\_.FullName
    $length = $\_.FullNameLength
    $string = "$length : $filePath"

    # Write to the Console.
    if ($writeToConsoleAsWell) { Write-Host $string }

    #Write to the file.
    $stream.WriteLine($string)
}
$stream.Close()

cls
write-host
write-host
write-host Largest character: -ForegroundColor Red -BackgroundColor white
Get-Content 'C:\\CountCharacter.txt' -totalcount 1
write-host
start-sleep -s 5
Remove-Item 'C:\\CountCharacter.txt'

Write-Host "Press any key to continue ..."
$x = $host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")

#Search for Special Characters
write-host ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
write-host
write-host Search Special Characters -ForegroundColor Red -BackgroundColor white
write-host
$chars = "\[~&#%&\*{}\\:<>?/+|\`“\]"
Get-ChildItem -Recurse -Path $path | ?{$\_.Name -match $chars} | %{$\_.fullname} > C:\\Special\_Chars.txt 
Get-Content C:\\Special\_Chars.txt
Remove-Item C:\\Special\_Chars.txt
Write-Host "Press any key to continue ..."
$x = $host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")
 
#Check file extention
write-host ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
write-host 
Write-host Check File Extention -ForegroundColor Red -BackgroundColor white
write-host
Get-ChildItem -Recurse -Path $path -include \*.ashx,\*.asmx,\*.json,\*.soap,\*.svc,\*.xamlx,\*.ade,\*.adp,\*.asa,\*.ashx,\*.asmx,\*.asp,\*.bas,\*.bat,\*.cdx,\*.cer,\*.chm,\*.class,\*.cmd,\*.com,\*.config,\*.cnt,\*.cpl,\*.crt,\*.csh,\*.der,\*.dll,\*.exe,\*.fxp,\*.gadget,\*.grp,\*.hlp,\*.hpj,\*.hta,\*.htr,\*.htw,\*.ida,\*.idc,\*.idq,\*.ins,\*.isp,\*.its,\*.jse,\*.ksh,\*.lnk,\*.mad,\*.maf,\*.mag,\*.mam,\*.maq,\*.mar,\*.mas,\*.mat,\*.mau,\*.mav,\*.maw,\*.mcf,\*.mda,\*.mdb,\*.mde,\*.mdt,\*.mdw,\*.mdz,\*.ms-one-stub,\*.msc,\*.msh,\*.msh1,\*.msh1xml,\*.msh2,\*.msh2xml,\*.mshxml,\*.msi,\*.msp,\*.mst,\*.ops,\*.pcd,\*.pif,\*.pl,\*.prf,\*.prg,\*.printer,\*.ps1,\*.ps1xml,\*.ps2,\*.ps2xml,\*.psc1,\*.pst,\*.reg,\*.rem,\*.scf,\*.scr,\*.sct,\*.shb,\*.shs,\*.shtm,\*.shtml,\*.soap,\*.stm,\*.svc,\*.url,\*.vb,\*.vbe,\*.vbs,\*.vsix,\*.ws,\*.wsc,\*.wsf,\*.wsh,\*.xamlx,\*.xamlx | Format-Table -auto Directory, Name | Out-File -FilePath C:\\File\_ext.txt  
Get-Content C:\\File\_ext.txt
Remove-Item C:\\File\_ext.txt
Write-Host "Press any key to continue ..."
$x = $host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")

$strFileName="c:\\log.txt"
If (Test-Path $strFileName){
  # // File exists
  cmtrace.exe 'c:\\log.txt'
}Else{
  # // File does not exist
  exit
}