diff --git a/Powershell/From Evernote/Connect_To_365.ps1 b/Powershell/From Evernote/Connect_To_365.ps1 new file mode 100644 index 0000000..f4f24e5 --- /dev/null +++ b/Powershell/From Evernote/Connect_To_365.ps1 @@ -0,0 +1,4 @@ +Set-ExecutionPolicy RemoteSigned +$UserCredential = Get-Credential +$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $UserCredential -Authentication Basic -AllowRedirection +Import-PSSession $Session \ No newline at end of file diff --git a/Powershell/From Evernote/Disconnect_From_365.ps1 b/Powershell/From Evernote/Disconnect_From_365.ps1 new file mode 100644 index 0000000..11c7d92 --- /dev/null +++ b/Powershell/From Evernote/Disconnect_From_365.ps1 @@ -0,0 +1 @@ +Remove-PSSession $Session \ No newline at end of file diff --git a/Powershell/From Evernote/Export install.esd to install.wim files/ESD2WIM-WIM2ESD.cmd b/Powershell/From Evernote/Export install.esd to install.wim files/ESD2WIM-WIM2ESD.cmd new file mode 100644 index 0000000..5aeebef --- /dev/null +++ b/Powershell/From Evernote/Export install.esd to install.wim files/ESD2WIM-WIM2ESD.cmd @@ -0,0 +1,487 @@ +@echo off +cls +echo. +ECHO =============================================================================== +echo Paste or write the complete path to install.esd or install.wim file +echo ^(without quotes marks "" even if the path contains spaces^) +ECHO =============================================================================== +echo. +set /p WIMFILE= +if "%WIMFILE%"=="" echo Incorrect file name or path&echo.&PAUSE&GOTO :QUIT + +title ESD ^<^> WIM +color 1f +%windir%\system32\reg.exe query "HKU\S-1-5-19" >nul 2>&1 || ( +echo ------- +echo *** WARNING *** +echo ------- +echo. +echo. +echo ADMINISTRATOR PRIVILEGES NOT DETECTED +echo ____________________________________________________________________________ +echo. +echo This script require administrator privileges. +echo. +echo To do so, right click on this script and select 'Run as administrator' +echo. +echo. +echo. +echo Press any key to exit... +pause >nul +goto :eof +) +cd /d "%~dp0" +if exist "%CD%\dism\dism.exe" set Path=%CD%\dism;%Path% +SET ERRORTEMP= +set /A count=0 + +dism /get-wiminfo /wimfile:"%WIMFILE%" >nul 2>&1 || ( +echo. +echo Incorrect file name or path +echo. +echo Press any key to exit. +pause >nul +goto :eof +) +setlocal EnableDelayedExpansion +FOR /F "tokens=2 delims=: " %%i IN ('dism /english /Get-WimInfo /WimFile:"%WIMFILE%" ^| findstr "Index"') DO SET images=%%i +for /L %%i in (1, 1, %images%) do call :setcount %%i + +if "%WIMFILE:~-3%"=="esd" GOTO :ESDMENU +if "%WIMFILE:~-3%"=="wim" GOTO :WIMMENU +exit + +:setcount +set /A count+=1 +for /f "tokens=1* delims=: " %%i in ('dism /english /get-wiminfo /wimfile:"%WIMFILE%" /index:%1 ^| find /i "Name"') do set name%count%="%%j" +goto :eof + +:ESDMENU +cls +ECHO =============================================================================== +ECHO. Detected ESD file contains %images% indexes: +ECHO. +for /L %%i in (1, 1, %images%) do ( +ECHO. %%i. !name%%i! +) +ECHO. +ECHO =============================================================================== +ECHO. Options: +ECHO =============================================================================== +ECHO. 1 - Export 1st index +ECHO. 2 - Export all indexes +ECHO. 3 - Export selected single index +ECHO. 4 - Export selected range of indexes +ECHO =============================================================================== +ECHO. Press 'Q' to Quit +ECHO =============================================================================== + +choice /c 1234q /n /m "Choose a menu option, or Q to quit: " +SET ERRORTEMP=%ERRORLEVEL% +IF %ERRORTEMP%==1 GOTO :ESD1 +IF %ERRORTEMP%==2 GOTO :ESD2 +IF %ERRORTEMP%==3 GOTO :ESD3 +IF %ERRORTEMP%==4 GOTO :ESD4 +IF %ERRORTEMP%==5 GOTO :QUIT +GOTO :MAINMENU + +:ESD1 +cls +IF EXIST "%CD%\install.wim" ( +ECHO =============================================================================== +ECHO. An install.wim file is already present in the current folder. +ECHO =============================================================================== +ECHO. +echo Press any key to exit. +pause >nul +GOTO :QUIT +) +ECHO =============================================================================== +Echo Exporting ESD Index 1 to a new install.wim file... +ECHO =============================================================================== +mkdir temp +dism /Quiet /Capture-Image /ImageFile:install.wim /CaptureDir:.\temp /Name:container /Compress:max /CheckIntegrity +rmdir /s /q temp +dism /Export-Image /SourceImageFile:"%WIMFILE%" /SourceIndex:1 /DestinationImageFile:install.wim /compress:recovery /CheckIntegrity +SET ERRORTEMP=%ERRORLEVEL% +IF %ERRORTEMP% NEQ 0 (ECHO.&Echo Errors were reported during dism export.&PAUSE&GOTO :QUIT) +dism /Quiet /Delete-Image /ImageFile:install.wim /Index:1 /CheckIntegrity +echo. +echo Done. +echo. +echo Press any key to exit. +pause >nul +GOTO :QUIT + +:ESD2 +cls +IF EXIST "%CD%\install.wim" ( +ECHO =============================================================================== +ECHO. An install.wim file is already present in the current folder. +ECHO =============================================================================== +ECHO. +echo Press any key to exit. +pause >nul +GOTO :QUIT +) +ECHO =============================================================================== +Echo Exporting ESD Index 1 to a new install.wim file... +ECHO =============================================================================== +mkdir temp +dism /Quiet /Capture-Image /ImageFile:install.wim /CaptureDir:.\temp /Name:container /Compress:max /CheckIntegrity +rmdir /s /q temp +dism /Export-Image /SourceImageFile:"%WIMFILE%" /SourceIndex:1 /DestinationImageFile:install.wim /compress:recovery /CheckIntegrity +SET ERRORTEMP=%ERRORLEVEL% +IF %ERRORTEMP% NEQ 0 (ECHO.&Echo Errors were reported during dism export.&PAUSE&GOTO :QUIT) +dism /Quiet /Delete-Image /ImageFile:install.wim /Index:1 /CheckIntegrity + +if "%images%"=="1" ( +echo. +echo Done. +echo. +echo Press any key to exit. +pause >nul +GOTO :QUIT +) + +for /L %%i in (2, 1, %images%) do ( +ECHO. +ECHO =============================================================================== +Echo Exporting ESD Index %%i to install.wim file... +ECHO =============================================================================== +dism /Export-Image /SourceImageFile:"%WIMFILE%" /SourceIndex:%%i /DestinationImageFile:install.wim /compress:recovery /CheckIntegrity +SET ERRORTEMP=%ERRORLEVEL% +IF %ERRORTEMP% NEQ 0 (ECHO.&Echo Errors were reported during dism export.&PAUSE&GOTO :QUIT) +) +echo. +echo Done. +echo. +echo Press any key to exit. +pause >nul +GOTO :QUIT + +:ESD3 +cls +set _index= +ECHO =============================================================================== +ECHO. Detected ESD file contains %images% indexes: +ECHO. +for /L %%i in (1, 1, %images%) do ( +ECHO. %%i. !name%%i! +) +ECHO. +ECHO =============================================================================== +ECHO. Enter desired index number to export +ECHO =============================================================================== +ECHO. Enter zero '0' to go back to Main Menu +ECHO =============================================================================== +set /p _index= ^> +if /i "%_index%"=="0" goto :ESDMENU +if [%_index%]==[] goto :ESD3 +if /i %_index% GTR %images% echo.&echo Selected number is higher than available indexes&echo.&PAUSE&goto :ESD3 + +cls +IF EXIST "%CD%\install.wim" ( +ECHO =============================================================================== +ECHO. An install.wim file is already present in the current folder. +ECHO =============================================================================== +ECHO. +echo Press any key to exit. +pause >nul +GOTO :QUIT +) +ECHO =============================================================================== +Echo Exporting ESD Index %_index% to a new install.wim file... +ECHO =============================================================================== +mkdir temp +dism /Quiet /Capture-Image /ImageFile:install.wim /CaptureDir:.\temp /Name:container /Compress:max /CheckIntegrity +rmdir /s /q temp +dism /Export-Image /SourceImageFile:"%WIMFILE%" /SourceIndex:%_index% /DestinationImageFile:install.wim /compress:recovery /CheckIntegrity +SET ERRORTEMP=%ERRORLEVEL% +IF %ERRORTEMP% NEQ 0 (ECHO.&Echo Errors were reported during dism export.&PAUSE&GOTO :QUIT) +dism /Quiet /Delete-Image /ImageFile:install.wim /Index:1 /CheckIntegrity +echo. +echo Done. +echo. +echo Press any key to exit. +pause >nul +GOTO :QUIT + +:ESD4 +cls +set _range= +set _start= +set _end= +ECHO =============================================================================== +ECHO. Detected ESD file contains %images% indexes: +ECHO. +for /L %%i in (1, 1, %images%) do ( +ECHO. %%i. !name%%i! +) +ECHO. +ECHO =============================================================================== +ECHO. Enter desired Range of indexes to export: Start-End +ECHO. Example: 2-4 or 1-3 or 3-4 +ECHO =============================================================================== +ECHO. Enter zero '0' to go back to Main Menu +ECHO =============================================================================== +set /p _range= ^> +if /i "%_range%"=="0" goto :ESDMENU +if [%_range%]==[] goto :ESD4 +for /f "tokens=1 delims=-" %%i in ('echo %_range%') do set _start=%%i +for /f "tokens=2 delims=-" %%i in ('echo %_range%') do set _end=%%i +if /i %_start% GTR %images% echo.&echo Range Start is higher than available indexes&echo.&PAUSE&goto :ESD4 +if /i %_end% GTR %images% echo.&echo Range End is higher than available indexes&echo.&PAUSE&goto :ESD4 +if /i %_start% EQU %_end% echo.&echo Range Start and End are equal. Use option 3 of main menu to export single index&echo.&PAUSE&goto :ESDMENU + +cls +IF EXIST "%CD%\install.wim" ( +ECHO =============================================================================== +ECHO. An install.wim file is already present in the current folder. +ECHO =============================================================================== +ECHO. +echo Press any key to exit. +pause >nul +GOTO :QUIT +) +ECHO =============================================================================== +Echo Exporting ESD Index %_start% to a new install.wim file... +ECHO =============================================================================== +mkdir temp +dism /Quiet /Capture-Image /ImageFile:install.wim /CaptureDir:.\temp /Name:container /Compress:max /CheckIntegrity +rmdir /s /q temp +dism /Export-Image /SourceImageFile:"%WIMFILE%" /SourceIndex:%_start% /DestinationImageFile:install.wim /compress:recovery /CheckIntegrity +SET ERRORTEMP=%ERRORLEVEL% +IF %ERRORTEMP% NEQ 0 (ECHO.&Echo Errors were reported during dism export.&PAUSE&GOTO :QUIT) +dism /Quiet /Delete-Image /ImageFile:install.wim /Index:1 /CheckIntegrity + +set /a _start+=1 +for /L %%i in (%_start%, 1, %_end%) do ( +ECHO. +ECHO =============================================================================== +Echo Exporting ESD Index %%i to install.wim file... +ECHO =============================================================================== +dism /Export-Image /SourceImageFile:"%WIMFILE%" /SourceIndex:%%i /DestinationImageFile:install.wim /compress:recovery /CheckIntegrity +SET ERRORTEMP=%ERRORLEVEL% +IF %ERRORTEMP% NEQ 0 (ECHO.&Echo Errors were reported during dism export.&PAUSE&GOTO :QUIT) +) +echo. +echo Done. +echo. +echo Press any key to exit. +pause >nul +GOTO :QUIT + +:WIMMENU +cls +ECHO =============================================================================== +ECHO. Detected WIM file contains %images% indexes: +ECHO. +for /L %%i in (1, 1, %images%) do ( +ECHO. %%i. !name%%i! +) +ECHO. +ECHO =============================================================================== +ECHO. Options: +ECHO =============================================================================== +ECHO. 1 - Export 1st index +ECHO. 2 - Export all indexes +ECHO. 3 - Export selected single index +ECHO. 4 - Export selected range of indexes +ECHO =============================================================================== +ECHO. Press 'Q' to Quit +ECHO =============================================================================== + +choice /c 1234q /n /m "Choose a menu option, or Q to quit: " +SET ERRORTEMP=%ERRORLEVEL% +IF %ERRORTEMP%==1 GOTO :WIM1 +IF %ERRORTEMP%==2 GOTO :WIM2 +IF %ERRORTEMP%==3 GOTO :WIM3 +IF %ERRORTEMP%==4 GOTO :WIM4 +IF %ERRORTEMP%==5 GOTO :QUIT +GOTO :MAINMENU + +:WIM1 +cls +IF EXIST "%CD%\install.esd" ( +ECHO =============================================================================== +ECHO. An install.esd file is already present in the current folder. +ECHO =============================================================================== +ECHO. +echo Press any key to exit. +pause >nul +GOTO :QUIT +) +ECHO =============================================================================== +Echo Exporting WIM Index 1 to a new install.esd file... +ECHO =============================================================================== +echo. +echo *** This will require some time, high CPU and Disk usage, please be patient *** +echo. +dism /export-image /sourceimagefile:"%WIMFILE%" /Sourceindex:1 /destinationimagefile:install.esd /compress:recovery /checkintegrity +SET ERRORTEMP=%ERRORLEVEL% +IF %ERRORTEMP% NEQ 0 (ECHO.&Echo Errors were reported during dism export.&PAUSE&GOTO :QUIT) +echo. +echo Done. +echo. +echo Press any key to exit. +pause >nul +GOTO :QUIT + +:WIM2 +cls +IF EXIST "%CD%\install.esd" ( +ECHO =============================================================================== +ECHO. An install.esd file is already present in the current folder. +ECHO =============================================================================== +ECHO. +echo Press any key to exit. +pause >nul +GOTO :QUIT +) +ECHO =============================================================================== +Echo Exporting WIM Index 1 to a new install.esd file... +ECHO =============================================================================== +echo. +echo *** This will require some time, high CPU and Disk usage, please be patient *** +echo. +dism /Export-Image /SourceImageFile:"%WIMFILE%" /Sourceindex:1 /DestinationImageFile:install.esd /compress:recovery /CheckIntegrity +SET ERRORTEMP=%ERRORLEVEL% +IF %ERRORTEMP% NEQ 0 (ECHO.&Echo Errors were reported during dism export.&PAUSE&GOTO :QUIT) + +if "%images%"=="1" ( +echo. +echo Done. +echo. +echo Press any key to exit. +pause >nul +GOTO :QUIT +) + +for /L %%i in (2, 1, %images%) do ( +ECHO. +ECHO =============================================================================== +Echo Exporting WIM Index %%i to install.esd file... +ECHO =============================================================================== +dism /Export-Image /SourceImageFile:"%WIMFILE%" /SourceIndex:%%i /DestinationImageFile:install.esd /compress:recovery /CheckIntegrity +SET ERRORTEMP=%ERRORLEVEL% +IF %ERRORTEMP% NEQ 0 (ECHO.&Echo Errors were reported during dism export.&PAUSE&GOTO :QUIT) +) +echo. +echo Done. +echo. +echo Press any key to exit. +pause >nul +GOTO :QUIT + +:WIM3 +cls +set _index= +ECHO =============================================================================== +ECHO. Detected WIM file contains %images% indexes: +ECHO. +for /L %%i in (1, 1, %images%) do ( +ECHO. %%i. !name%%i! +) +ECHO. +ECHO =============================================================================== +ECHO. Enter desired index number to export +ECHO =============================================================================== +ECHO. Enter zero '0' to go back to Main Menu +ECHO =============================================================================== +set /p _index= ^> +if /i "%_index%"=="0" goto :WIMMENU +if [%_index%]==[] goto :WIM3 +if /i %_index% GTR %images% echo.&echo Selected number is higher than available indexes&echo.&PAUSE&goto :WIM3 + +cls +IF EXIST "%CD%\install.esd" ( +ECHO =============================================================================== +ECHO. An install.esd file is already present in the current folder. +ECHO =============================================================================== +ECHO. +echo Press any key to exit. +pause >nul +GOTO :QUIT +) +ECHO =============================================================================== +Echo Exporting WIM Index %_index% to a new install.esd file... +ECHO =============================================================================== +echo. +echo *** This will require some time, high CPU and Disk usage, please be patient *** +echo. +dism /Export-Image /SourceImageFile:"%WIMFILE%" /SourceIndex:%_index% /DestinationImageFile:install.esd /compress:recovery /CheckIntegrity +SET ERRORTEMP=%ERRORLEVEL% +IF %ERRORTEMP% NEQ 0 (ECHO.&Echo Errors were reported during dism export.&PAUSE&GOTO :QUIT) +echo. +echo Done. +echo. +echo Press any key to exit. +pause >nul +GOTO :QUIT + +:WIM4 +cls +set _range= +set _start= +set _end= +ECHO =============================================================================== +ECHO. Detected WIM file contains %images% indexes: +ECHO. +for /L %%i in (1, 1, %images%) do ( +ECHO. %%i. !name%%i! +) +ECHO. +ECHO =============================================================================== +ECHO. Enter desired Range of indexes to export: Start-End +ECHO. Example: 2-4 or 1-3 or 3-4 +ECHO =============================================================================== +ECHO. Enter zero '0' to go back to Main Menu +ECHO =============================================================================== +set /p _range= ^> +if /i "%_range%"=="0" goto :WIMMENU +if [%_range%]==[] goto :WIM4 +for /f "tokens=1 delims=-" %%i in ('echo %_range%') do set _start=%%i +for /f "tokens=2 delims=-" %%i in ('echo %_range%') do set _end=%%i +if /i %_start% GTR %images% echo.&echo Range Start is higher than available indexes&echo.&PAUSE&goto :WIM4 +if /i %_end% GTR %images% echo.&echo Range End is higher than available indexes&echo.&PAUSE&goto :WIM4 +if /i %_start% EQU %_end% echo.&echo Range Start and End are equal. Use option 3 of main menu to export single index&echo.&PAUSE&goto :WIMMENU + +cls +IF EXIST "%CD%\install.esd" ( +ECHO =============================================================================== +ECHO. An install.esd file is already present in the current folder. +ECHO =============================================================================== +ECHO. +echo Press any key to exit. +pause >nul +GOTO :QUIT +) +ECHO =============================================================================== +Echo Exporting WIM Index %_start% to a new install.esd file... +ECHO =============================================================================== +echo. +echo *** This will require some time, high CPU and Disk usage, please be patient *** +echo. +dism /Export-Image /SourceImageFile:"%WIMFILE%" /SourceIndex:%_start% /DestinationImageFile:install.esd /compress:recovery /CheckIntegrity +SET ERRORTEMP=%ERRORLEVEL% +IF %ERRORTEMP% NEQ 0 (ECHO.&Echo Errors were reported during dism export.&PAUSE&GOTO :QUIT) + +set /a _start+=1 +for /L %%i in (%_start%, 1, %_end%) do ( +ECHO. +ECHO =============================================================================== +Echo Exporting WIM Index %%i to install.esd file... +ECHO =============================================================================== +dism /Export-Image /SourceImageFile:"%WIMFILE%" /SourceIndex:%%i /DestinationImageFile:install.esd /compress:recovery /CheckIntegrity +SET ERRORTEMP=%ERRORLEVEL% +IF %ERRORTEMP% NEQ 0 (ECHO.&Echo Errors were reported during dism export.&PAUSE&GOTO :QUIT) +) +echo. +echo Done. +echo. +echo Press any key to exit. +pause >nul +GOTO :QUIT + +:QUIT \ No newline at end of file diff --git a/Powershell/From Evernote/Intune.ps1 b/Powershell/From Evernote/Intune.ps1 new file mode 100644 index 0000000..a768e17 --- /dev/null +++ b/Powershell/From Evernote/Intune.ps1 @@ -0,0 +1,267 @@ +param([switch]$Elevated) +function Check-Admin { +$currentUser = New-Object Security.Principal.WindowsPrincipal $([Security.Principal.WindowsIdentity]::GetCurrent()) +$currentUser.IsInRole([Security.Principal.WindowsBuiltinRole]::Administrator) +} +if ((Check-Admin) -eq $false)  { +if ($elevated) +{ +# could not elevate, quit +} +  +else { +  +Start-Process powershell.exe -Verb RunAs -ArgumentList ('-noprofile -noexit -file "{0}" -elevated' -f ($myinvocation.MyCommand.Definition)) +} +exit +} +function Write-ProgressHelper { + param ( + [int]$StepNumber, + [string]$Message + ) + + Write-Progress -Activity 'PSC Update Readiness 2019' -Status $Message -PercentComplete (($StepNumber / $steps) * 100) +} + +$script:steps = ([System.Management.Automation.PsParser]::Tokenize((gc "$PSScriptRoot\$($MyInvocation.MyCommand.Name)"), [ref]$null) | where { $_.Type -eq 'Command' -and $_.Content -eq 'Write-ProgressHelper' }).Count + +$stepCounter = 0 + +Write-ProgressHelper -Message 'Checking For Previous Run' -StepNumber ($stepCounter++) +Start-Sleep -Seconds 2.5 +$ErrorActionPreference="SilentlyContinue" +$maxRepeat = 10 +$Organisation = "PSC" +$ThisPC = ($env:COMPUTERNAME + $env:username) +$freespaceError = ("$env:COMPUTERNAME only has $spacegb GB Free and cannot continue 1903 install") +$TeamViewerFileName = "c:\teamviewer_install\TeamviewerHost.msi" +$InTuneLog = "c:\InTune_Log\$env:COMPUTERNAME.log" +$InTuneFolder = "c:\InTune_Log\*.*" +$InTune_Folder = "c:\InTune_Log\" +$ts = New-TimeSpan -Hours 2 +function not-exist { -not (Test-Path -Path $TeamViewerFileName) } +#Set-Alias !exist not-exist -Option "Constant, AllScope" +#Set-Alias exist Test-Path -Option "Constant, AllScope" +Add-Type -AssemblyName System.Windows.Forms | Out-Null +Stop-Transcript | out-null +$ErrorActionPreference = "Continue" +If (-not(Test-Path -Path $InTune_Folder)) { +mkdir $InTune_Folder } +filter timestamp {"$(Get-Date -Format G): $_"} + +if (Test-Path -Path $InTuneLog) { +Remove-Item $InTuneLog -ErrorAction SilentlyContinue +Remove-Item $InTune_Folder\$env:COMPUTERNAME.zip -Force -ErrorAction SilentlyContinue +Remove-Item c:\InTune_Log\"$env:COMPUTERNAME"_Transcript.log -ErrorAction SilentlyContinue +Remove-Item c:\InTune_Log\"$env:COMPUTERNAME".csv -ErrorAction SilentlyContinue +Remove-Item c:\InTune_Log\$env:Computername-Bitlocker-Recovery-key.txt -ErrorAction SilentlyContinue +Start-Sleep -Seconds 1.5} +Else +{ +# Move On +} +Start-Transcript -path c:\InTune_Log\"$env:COMPUTERNAME"_Transcript.log +Write-ProgressHelper -Message 'Checking For Teamviewer' -StepNumber ($stepCounter++) +Start-Sleep -Seconds 2.5 +############################################################################ +# Teamviewer Start +############################################################################ +#Get Teamviewer +if (-not (Test-Path -Path $TeamViewerFileName)) { +mkdir c:\teamviewer_install +$url = "https://onedrive.live.com/download?cid=77FB0E4F642F10B7&resid=77FB0E4F642F10B7%21273176&authkey=AOouFE3GDGRSHIc" +$output = "c:\teamviewer_install\TeamviewerHost.msi" +$start_time = Get-Date + +$wc = New-Object System.Net.WebClient +$wc.DownloadFile($url, $output) +Write-Host "Temaviewer Downloaded" +msiexec.exe /i "c:\teamviewer_install\TeamviewerHost.msi" /qn CUSTOMCONFIGID=6988pev APITOKEN=6581446-B1aEz7nIk9k92p4G7C1R ASSIGNMENTOPTIONS="--grant-easy-access" +Write-Host "Teamviewer Installed" +} +Else +{ +Write-Host "TeamViewer Already Installed" +} + +############################################################################# +# Teamviewer End +############################################################################# +Write-ProgressHelper -Message 'Checking Your PC Integrity - Integrity Is Important You Know' -StepNumber ($stepCounter++) +Start-Sleep -Seconds 5 +############################################################################## +# Computer Sanity Check End +############################################################################## + + # Power Connect Check + +#Function Check-BatteryState { +#param($Laptop=$env:computername) +#$Bstatus = ((Get-WmiObject -Class Win32_Battery).BatteryStatus) +#} +$Bstatus = ((Get-WmiObject -Class Win32_Battery).BatteryStatus) +if($Bstatus) { + switch ($Bstatus) + { + 1 { "Battery is discharging" } + 2 { "The system has access to AC so no battery is being discharged. However, the battery is not necessarily charging." } + 3 { "Fully Charged" } + 4 { "Low" } + 5 { "Critical" } + 6 { "Charging" } + 7 { "Charging and High" } + 8 { "Charging and Low" } + 9 { "Charging and Critical " } + 10 { "Unknown State" } + 11 { "Partially Charged" } + + } +} + +If ($BStatus -eq 2) { +# Move On +} + +Else { + [System.Windows.Forms.MessageBox]::Show("You Need To Be Connected To The Power Adapter! Please re run from Software Center when power is avalable. Exiting...", $Organisation, + [System.Windows.Forms.MessageBoxButtons]::OK, + [System.Windows.Forms.MessageBoxIcon]::ERROR) + + } + + + # Power Connect Check End +#---------------------------------------------------------------------------- +Write-ProgressHelper -Message 'Checking Your Free Drive Space - You Should Be Saving Everything To The Cloud Anyway' -StepNumber ($stepCounter++) +Start-Sleep -Seconds 5 + +#---------------------------------------------------------------------------- + # Free Space Check Start + +$disk = Get-WMIObject Win32_Logicaldisk -filter "deviceid='$((Get-WMIObject Win32_OperatingSystem -computername $env:COMPUTERNAME).systemdrive)'" -ComputerName $env:COMPUTERNAME +$freespace = ($disk.FreeSpace) +$spacegb = [math]::Round($disk.Freespace/1GB,2) + + # Free Space Check End +#---------------------------------------------------------------------------- +Write-ProgressHelper -Message 'Checking Your PC Is Secure - Safety First!' -StepNumber ($stepCounter++) +Start-Sleep -Seconds 5 +#---------------------------------------------------------------------------- + # Bitlocker Status +Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force +$blockerstatus = (Get-BitlockerVolume -MountPoint "C:") + +#---------------------------------------------------------------------------- +Write-ProgressHelper -Message 'Checking For PSC Admin' -StepNumber ($stepCounter++) +Start-Sleep -Seconds 5 +#---------------------------------------------------------------------------- + # PSC Admin User Check Start + + +$UserPassword = ConvertTo-SecureString "Restore99!" -AsPlainText -Force +$psclocaladmin = $null +If ($psclocaladmin = Get-LocalUser pscadmin) +{ + Add-LocalGroupMember -Group "Administrators" -Member "pscadmin" + Enable-LocalUser -Name "pscadmin" +} +Else +{ +# If (!$psclocaladmin) + New-LocalUser "pscadmin" -Password $UserPassword -FullName "PSC Admin" -Description "PSC Admin Account" -AccountNeverExpires -PasswordNeverExpires + Add-LocalGroupMember -Group "Administrators" -Member "pscadmin" + Enable-LocalUser -Name "pscadmin" + } + + + # PSC Admin User Check End +#---------------------------------------------------------------------------- +Write-ProgressHelper -Message 'Creating Restore Point - We Like To Play It Safe!' -StepNumber ($stepCounter++) +Start-Sleep -Seconds 10 +#---------------------------------------------------------------------------- + # System Restore Check Start + +Enable-ComputerRestore -Drive "C:\" +Checkpoint-Computer -Description "New Intune Setup 2019" -RestorePointType MODIFY_SETTINGS + + # System Restore Check End +#---------------------------------------------------------------------------- + +############################################################################## +# Computer Sanity Check End +############################################################################## +Write-ProgressHelper -Message 'Checking For Errors - Its Windows 10, As If There Would Be Errors!?' -StepNumber ($stepCounter++) +Start-Sleep -Seconds 5 + +# Errors + +If($freespace -lt 32212254720 ) { + $freespaceError | Format-Table | Out-File -append "c:\InTune_Log\$env:COMPUTERNAME.log" | Write-Output +} +else { + # No Error To See Here, Keep Moving! +} + + +If ($blockerstatus.protectionstatus -ne "On") { + Enable-BitLocker -MountPoint C: -UsedSpaceOnly -SkipHardwareTest -RecoveryKeyPath "c:\InTune_Log\" -RecoveryKeyProtector + manage-bde -protectors -get c: >> c:\InTune_Log\$env:Computername-Bitlocker-Recovery-key.txt + ("BitLocker Was Off") | Format-Table | Out-File -append "c:\InTune_Log\$env:COMPUTERNAME.log" | Write-Output + +} +Else +{ + manage-bde -protectors -get c: >> c:\InTune_Log\$env:Computername-Bitlocker-Recovery-key.txt +} +Start-Sleep -Seconds 1.5 +if ($BStatus -ne 2) +{ + ("$env:username Did Not Plug In To Mains") | Format-Table | Out-File -append "c:\InTune_Log\$env:COMPUTERNAME.log" | Write-Output +} + +# AutoPilot Hardware Hash +Install-Script -Name Get-WindowsAutoPilotInfo -Force +Start-Sleep -Seconds 3 +Get-WindowsAutoPilotInfo.ps1 -append -OutputFile "c:\InTune_Log\$env:COMPUTERNAME.csv" +Start-Sleep -Seconds 2.5 + +Stop-Transcript + +# Fail +$LogsExist = (Test-Path $InTuneLog) +Write-ProgressHelper -Message 'Sending Data To PSC IT' -StepNumber ($stepCounter++) +Start-Sleep -Seconds 4 +if (Test-Path $InTuneLog) +{ +$psclocaladmin | Format-Table | Out-File -append "c:\InTune_Log\$env:COMPUTERNAME.log" | Write-Output +("BitLocker Was Off, It has now been switched on by InTune Script. Please try again in an hour") | Format-Table | Out-File -append "c:\InTune_Log\$env:COMPUTERNAME.log" | Write-Output +Compress-Archive -Path $InTuneFolder -DestinationPath $InTune_Folder\$env:COMPUTERNAME.zip +Start-Sleep -Seconds 5 +Send-MailMessage -from "$env:username" -to "IT" -Subject "AAD Intune Upgrade Report Fail $env:computername" -Body "$env:COMPUTERNAME InTune Logs" -Attachments "$InTune_Folder\$env:COMPUTERNAME.zip" -SmtpServer "pscconsulting-com.mail.protection.outlook.com" +curl "https://onedrive.live.com/download?cid=77FB0E4F642F10B7&resid=77FB0E4F642F10B7%21273301&authkey=AEReiJb0-g1gGqc" -o "$InTune_Folder\sendfile.ps1" +Invoke-Expression (($InTune_Folder)+"\sendfile.ps1") +Remove-Item $InTune_Folder\sendfile.ps1 -Force -ErrorAction SilentlyContinue + [System.Windows.Forms.MessageBox]::Show("The PSC IT Update Readiness Tool Has Completed Its Task. All Details Have Been Sent To PSC IT.", $Organisation, + [System.Windows.Forms.MessageBoxButtons]::OK, + [System.Windows.Forms.MessageBoxIcon]::INFORMATION) +} +Else +{ +("BitLocker Was Already On") | Format-Table | Out-File -append "c:\InTune_Log\$env:COMPUTERNAME.log" | Write-Output +$psclocaladmin | Format-Table | Out-File -append "c:\InTune_Log\$env:COMPUTERNAME.log" | Write-Output +("$env:COMPUTERNAME has $spacegb GB Free") | Format-Table | Out-File -append "c:\InTune_Log\$env:COMPUTERNAME.log" | Write-Output +Compress-Archive -Path $InTuneFolder -DestinationPath $InTune_Folder\$env:COMPUTERNAME.zip +Start-Sleep -Seconds 5 +Send-MailMessage -from "$env:username" -to "IT" -Subject "AAD Intune Upgrade Report Success $env:computername" -Body "$env:COMPUTERNAME InTune Logs" -Attachments "$InTune_Folder\$env:COMPUTERNAME.zip" -SmtpServer "pscconsulting-com.mail.protection.outlook.com" +curl "https://onedrive.live.com/download?cid=77FB0E4F642F10B7&resid=77FB0E4F642F10B7%21273301&authkey=AEReiJb0-g1gGqc" -o "$InTune_Folder\sendfile.ps1" +Invoke-Expression (($InTune_Folder)+"\sendfile.ps1") +Remove-Item $InTune_Folder\sendfile.ps1 -Force -ErrorAction SilentlyContinue + + [System.Windows.Forms.MessageBox]::Show("The PSC IT Update Readiness Tool Has Completed Its Task. All Details Have Been Sent To PSC IT.", $Organisation, + [System.Windows.Forms.MessageBoxButtons]::OK, + [System.Windows.Forms.MessageBoxIcon]::INFORMATION) +} + +Write-ProgressHelper -Message 'Checkup Complete - Thanks For Playing' -StepNumber ($stepCounter++) +Start-Sleep -Seconds 3 \ No newline at end of file diff --git a/Powershell/From Evernote/PSC InTune Readiness Script Call Batch files/Intune-run-first.bat b/Powershell/From Evernote/PSC InTune Readiness Script Call Batch files/Intune-run-first.bat new file mode 100644 index 0000000..4e5e72d --- /dev/null +++ b/Powershell/From Evernote/PSC InTune Readiness Script Call Batch files/Intune-run-first.bat @@ -0,0 +1,28 @@ +@echo off +:: BatchGotAdmin +::------------------------------------- +REM --> Check for permissions +>nul 2>&1 "%SYSTEMROOT%\system32\cacls.exe" "%SYSTEMROOT%\system32\config\system" + +REM --> If error flag set, we do not have admin. +if '%errorlevel%' NEQ '0' ( + echo Requesting administrative privileges... + goto UACPrompt +) else ( goto gotAdmin ) + +:UACPrompt + echo Set UAC = CreateObject^("Shell.Application"^) > "%temp%\getadmin.vbs" + set params = %*:"=" + echo UAC.ShellExecute "cmd.exe", "/c %~s0 %params%", "", "runas", 1 >> "%temp%\getadmin.vbs" + + "%temp%\getadmin.vbs" + del "%temp%\getadmin.vbs" + exit /B + +:gotAdmin + pushd "%CD%" + CD /D "%~dp0" +::-------------------------------------- + +powershell -command "& {Set-ExecutionPolicy -ExecutionPolicy Unrestricted -Force}" +powershell ./Intune.ps1 diff --git a/Powershell/From Evernote/Remote Enable BitLocker files/Bitlocker.zip b/Powershell/From Evernote/Remote Enable BitLocker files/Bitlocker.zip new file mode 100644 index 0000000..0092b91 Binary files /dev/null and b/Powershell/From Evernote/Remote Enable BitLocker files/Bitlocker.zip differ diff --git a/Powershell/From Evernote/Robocopy with file exclude.html b/Powershell/From Evernote/Robocopy with file exclude.html new file mode 100644 index 0000000..0a90503 --- /dev/null +++ b/Powershell/From Evernote/Robocopy with file exclude.html @@ -0,0 +1,588 @@ + + + + + + + + + + + + + + + + + + + + + + + + + +

+ Robocopy with file exclude +

Robocopy with file exclude
20 July 2018
10:42

robocopy "\\192.168.11.7\Projects\Baywa\Hughenden Solar Farm PSCAD" "c:\Baywa\Hughenden Solar Farm PSCAD" /E /Z /ZB /R:5 /W:5 /TBD /NP /V /XF *.out
 
Created with Microsoft OneNote 2016.
+ + diff --git a/Powershell/From Evernote/Stop organisation asking to manage device win10-11.ps1 b/Powershell/From Evernote/Stop organisation asking to manage device win10-11.ps1 new file mode 100644 index 0000000..4a6adbb --- /dev/null +++ b/Powershell/From Evernote/Stop organisation asking to manage device win10-11.ps1 @@ -0,0 +1,11 @@ +#Setting registry key to block AAD Registration to 3rd party tenants. +$RegistryLocation = "HKLM:\SOFTWARE\Policies\Microsoft\Windows\WorkplaceJoin\" +$keyname = "BlockAADWorkplaceJoin" +#Test if path exists and create if missing +if (!(Test-Path -Path $RegistryLocation)){ +Write-Output "Registry location missing. Creating" +New-Item $RegistryLocation | Out-Null +} +#Force create key with value 1 +New-ItemProperty -Path $RegistryLocation -Name $keyname -PropertyType DWord -Value 1 -Force | Out-Null +Write-Output "Registry key set" \ No newline at end of file diff --git a/Powershell/From Evernote/Teamviewer Install files/Install-Teamviewer.ps1 b/Powershell/From Evernote/Teamviewer Install files/Install-Teamviewer.ps1 new file mode 100644 index 0000000..1d064b2 --- /dev/null +++ b/Powershell/From Evernote/Teamviewer Install files/Install-Teamviewer.ps1 @@ -0,0 +1,54 @@ +<# + .Synopsis Detects, downloads, installs and configures the latest version of TeamViewer. + .Notes + Requires TeamViewer 14. + + TeamViewer Installation Documentation + https://community.teamviewer.com/t5/Knowledge-Base/Mass-deployment-improvements/ta-p/39639 +#> +$ConfigurationID = "64uyck9" +$ApiToken = "6615740-y9LI6bdNq5QtaDtiGVTN" +$ComputerName = $ENV:COMPUTERNAME + +if (Test-Path 'C:\Program Files (x86)\TeamViewer\TeamViewer.exe') { + Write-Host 'Team Viewer already installed.' + return +} + +Write-Host 'Installing TeamViewer.' + +Write-Host 'Downloading TeamViewer Host Setup.' +$SetupFilePath = Join-Path $ENV:TEMP "TeamViewer_Host_Setup-idc$($ConfigurationID).exe" + +$response = Invoke-RestMethod "https://get.teamviewer.com/$ConfigurationID" +$json = '{}' +if ($response -match 'configId = "(?[^"]+).*\n.*version = "(?[^"]+).*\n.*isCustomModule = (?[^"]+);.*\n.*subdomain = "(?[^"]+)(?)' ) { + $Matches.Remove(0) + $Matches['IsCustomModule'] = if ($Matches['IsCustomModule'] -eq 'true') { $true } else { $false } + $json = [PsCustomObject]$Matches | ConvertTo-Json +} +else { + throw 'Expected JSON values not found in initial HTML page' +} + +$DownloadUri = Invoke-RestMethod -Uri 'https://get.teamviewer.com/api/CustomDesign' -Method Post -Body $json -ContentType 'application/json' +Invoke-WebRequest -Uri $DownloadUri -OutFile $SetupFilePath + + +if (-not (Test-Path $SetupFilePath)) { + throw 'TeamViewer_Setup.exe failed to download.' +} + +Write-Host 'Installing.' +& $SetupFilePath /S | Write-Output +Write-Debug "$SetupFilePath LastExitCode = $LASTEXITCODE" + +Write-Host 'Configuring' +& "C:\Program Files (x86)\TeamViewer\TeamViewer.exe" assign --api-token $ApiToken --grant-easy-access --reassign --alias $ComputerName | Write-Output +Write-Debug "TeamViewer.exe assign LastExitCode = $LASTEXITCODE" + +Write-Host 'Cleaning up.' +$SetupTempFolder = Join-Path $ENV:TEMP 'TeamViewer' +$SetupFilePath, $SetupTempFolder | Remove-Item -Recurse + +Write-Host 'Complete.' \ No newline at end of file diff --git a/Powershell/From Evernote/Teamviewer Install files/TeamviewerInstall.ps1 b/Powershell/From Evernote/Teamviewer Install files/TeamviewerInstall.ps1 new file mode 100644 index 0000000..77f0ad2 --- /dev/null +++ b/Powershell/From Evernote/Teamviewer Install files/TeamviewerInstall.ps1 @@ -0,0 +1,51 @@ +param([switch]$Elevated) +function Check-Admin { +$currentUser = New-Object Security.Principal.WindowsPrincipal $([Security.Principal.WindowsIdentity]::GetCurrent()) +$currentUser.IsInRole([Security.Principal.WindowsBuiltinRole]::Administrator) +} +if ((Check-Admin) -eq $false)  { +if ($elevated) +{ +# could not elevate, quit +} +  +else { +  +Start-Process powershell.exe -Verb RunAs -ArgumentList ('-noprofile -noexit -file "{0}" -elevated' -f ($myinvocation.MyCommand.Definition)) +} +exit +} +$TempInstallDir = "c:\teamviewer_install\" +if (Test-Path $TempInstallDir) { +Remove-Item $TempInstallDir -Recurse -Force +} +else +{ +Write-Host "Install Start" +} +$TeamViewerFileName = "C:\Program Files (x86)\TeamViewer\TeamViewer.exe" +$TeamViewer64FileName = "C:\Program Files\TeamViewer\TeamViewer.exe" + + +function not-exist { -not (Test-Path -Path $TeamViewer64FileName) } +function not-exist { -not (Test-Path -Path $TeamViewerFileName) } +if (-not (Test-Path -Path $TeamViewerFileName)) {} +if (-not (Test-Path -Path $TeamViewer64FileName)) { +mkdir c:\teamviewer_install +$url = "https://download.teamviewer.com/download/version_15x/TeamViewer_MSI32.zip" +$output = "c:\teamviewer_install\TeamviewerHost.zip" +$tvdir = "c:\teamviewer_install" +$start_time = Get-Date + +$wc = New-Object System.Net.WebClient +$wc.DownloadFile($url, $output) +Write-Host "Teamviewer Downloaded" +sleep 3 +Expand-Archive -LiteralPath $output -DestinationPath $tvdir -Force +msiexec.exe /i "c:\teamviewer_install\Host\Teamviewer_Host.msi" /qn CUSTOMCONFIGID=6988pev APITOKEN=6581446-B1aEz7nIk9k92p4G7C1R ASSIGNMENTOPTIONS="--grant-easy-access" +Write-Host "Teamviewer Installed" +} +Else +{ +Write-Host "TeamViewer Already Installed" +} \ No newline at end of file diff --git a/Powershell/From Evernote/Uninstall-IntuneClient.ps1 b/Powershell/From Evernote/Uninstall-IntuneClient.ps1 new file mode 100644 index 0000000..dc16948 --- /dev/null +++ b/Powershell/From Evernote/Uninstall-IntuneClient.ps1 @@ -0,0 +1,40 @@ +function Get-ServiceId { + #Set the registry path containing the service ID + $RegistryPath = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\OnlineManagement" + try { + #Get all the names of the items in the registry location + $RegistryItems = (Get-ChildItem -Path Registry::$RegistryPath -ErrorAction Stop).Name + #Loop through all the results + foreach ($RegistryItem in $RegistryItems) { + #Find the result that starts with the registry location followed by the first sign of a GUID + if ($RegistryItem.StartsWith("$RegistryPath\{")) { + #Replace the registry location with nothing to get the GUID + $ServiceId = $RegistryItem.Replace("$RegistryPath\","") + break + } + } + return $ServiceId + } + catch { + Write-Output "The Microsoft Intune client is not installed" + } +} + +function Start-Uninstall { + param ( + [parameter(Mandatory=$true)]$ServiceId + ) + try { + #Set the ProvisioningUtil location and parameters + $ProvisioningUtilPath = "C:\Program Files\Microsoft\OnlineManagement\Common" + $ProvisioningUtilExecutable = "ProvisioningUtil.exe" + $ProvisioningUtilArguments = "/UninstallClient /ServiceId $ServiceId /TaskName 'tempTask' /SubEventId 16" + #Trigger the uninstall of the Microsoft Intune client + Start-Process -FilePath "$($ProvisioningUtilPath)\$($ProvisioningUtilExecutable)" -ArgumentList $ProvisioningUtilArguments -Wait -PassThru + } + catch { + Write-Output "Failed to trigger the uninstall of the Microsoft Intune client" + } +} + +Start-Uninstall (Get-ServiceId) \ No newline at end of file