Sunday, March 7, 2021

Simplifying getting a summary for your scripts

 

Simplifying getting a summary for your scripts. I will assume you are writing script often and you want to be more organized with your scripts. When writing script it is always a good idea to make sure you have enough information about your code. Following example will demonstrate same end goal. in the example given below, when writing script within the scripts following notation is used.

#(1)_.Adding Vars

#(2)_.Check folder existence

#(3)_.Entering loop 

#(4)_.Setting counter 

after making sure script is built correctly , you can run below function to grab all lines includes pattern defined "#" and use can use it within the script to present summary information.

  


 


<#   

 

.NOTES

#------------------------------------------------------

# Script      : Untitled18.ps1

# Created     : ISE 3.0

# Author(s)   : (Casey.Dedeal)

# Date        : 03/07/2021 08:56:40

# Org         : CloudSec365

# File Name   : Untitled18.ps1

# Comments    : None

# Assumptions : None

#------------------------------------------------------

 

.SYNOPSIS     : Untitled18.ps1

.DESCRIPTION  : Following script,

.License      : Open license

.Limitations  : None

.Known issues : None

.Credits      : (Casey.Dedeal)

.Blog         : https://simplepowershell.blogspot.com

.Blog         : https://msazure365.blogspot.com

.Blog         : https://cloudsec365.blogspot.com

.Twitter      : https://twitter.com/Message_Talk

              

.EXAMPLE

 

  .\Get-Sample.ps1

  MAP:

-----------

 

#(1)_.Adding Vars

#(2)_.Check folder existence

#(3)_.Entering loop 

#(4)_.Setting counter 

 

-----------

 

   #>

 

 



function Function-Print-MAP {

[cmdletbinding()]

param(

    [parameter(

        Mandatory         = $true,

        ValueFromPipeline = $true)]

        [string]$Filepath,

        $pipelineInput

)

 

    Begin {      

    }

 

    Process {

Try{

 

     #(1)_.Check to make sure filepath exist

  If (!(Test-Path $Filepath)){

     Write-Host 'CANNOT locate file' -ForegroundColor White -BackgroundColor Red

     Write-Host 'Script will stop' -ForegroundColor Yellow

     break;

     }

     #(2)_.Catch pattern

     $pattern = "#"

     $report = get-content $filePath -ReadCount 1000 | foreach { $_ -match $pattern }

     $report | Foreach {$_.TrimEnd()}

     $report

     $report | Out-GridView

 

  }Catch{

 

  $errofile = $($PSItem.ToString())

  Write-Warning 'Error has occoured'

  Write-host 'Problem FOUND' $errofile -ForegroundColor red -BackgroundColor Black

 

               }

    

           }

 

    End {

 

    }

 

}

 

 

$filepath = "C:\TEMP\KFM-SET-Health-CHECK-V1.ps1"

Function-Print-MAP -Filepath $filepath

 

 

 

Azure Solutions Architect
AWS Certified Cloud Practitioner
Azure Certified Security Engineer Associate
https://simplepowershell.blogspot.com
https://cloudsec365.blogspot.com
https://msazure365.blogspot.com
https://twitter.com/Message_Talk

 


Saturday, February 20, 2021

KFM ( Known Folder Move) what you need to know when it fails.

 

KFM ( Known Folder Move) what you need to know when it fails.

 If you have deployed KFM (Known Folder Move) in your environment and user GPO to force it down to user computer , you did enabled at the least below reg keys via your GPO, or add them manually via SCCM or PS script.

 KFM , required and recommended GPO settings

Registry Hive

HKEY_LOCAL_MACHINE

Registry Path

SOFTWARE\Policies\Microsoft\OneDrive

Value Name

KFMBlockOptIn

Value Type

REG_DWORD

Enabled Value

1

Disabled Value

0

KFMSilentOptIn

Tenant ID:

 

Registry Hive

HKEY_LOCAL_MACHINE

Registry Path

SOFTWARE\Policies\Microsoft\OneDrive

Value Name

KFMSilentOptIn

Value Type

REG_SZ

Default Value

 

 

 

KFMSilentOptInWithNotification

 

Show notification to users after folders
have been redirected:

Enabled

Registry Value

HKEY_LOCAL_MACHINE

Registry Path

SOFTWARE\Policies\Microsoft\OneDrive

Value Name

KFMSilentOptInWithNotification

Value Type

REG_DWORD

Value

0

 

If you found out KFM did not worked one of the most common reason is, existing folder redirection, and OneDrive will add several keys in the registry to prevent KFM run next time, since it has already been failed. You need to fix existing folder redirection issue, whatever is causing it. Then clean up following registry keys to be ready to try again

 

 

 

STEPS

Registry Key Location

Registry Keys

STEP#1

Close OneDrive make sure it is not running

STEP#2

Check existing group policy
redirection -fdeploy key

HKLM\Software\Microsoft\WindowsNT\CurrentVersion\ProfileList\
(yoursid)\fdeploy 

 

 

PathEffective

 

 

 

STEP#3

Reset the state of KFM deployment, remove all KFM keys in the following registry location

HKCU\SOFTWARE\Microsoft\OneDrive\Accounts\Business1

 

Some examples are

 

 

 

Delete Keys:

 

 

KfmAcmAdminMessageState

 

 

KfmHasForceShownWindow

 

 

KfmIsDoneSilentOptIn

 

 

KfmSilentAttemptedFolders

 

 

 

STEP#4

 

 

 

Additionally you need to remove following key

HKCU\SOFTWARE\Microsoft\OneDrive\

 

Delete Key

KfmFolderNotSyncingMessageHandled

STEP#5

Close OneDrive and try. and make sure all keys for the deployment does exist

 

 

 

 

 

 

 

STEP#5

GPO Basic KFM reg keys

# KFMBlockOptIn

 

these keys later on)

# KFMSilentOptIn

 

$registryPath = "HKLM:\SOFTWARE\Policies\Microsoft\OneDrive"

# KFMSilentOptInWithNotification

 

 

# KFMOptInWithWizard ( recommended by MS )

 

 

 

 

 

Azure Solutions Architect
AWS Certified Cloud Practitioner
Azure Certified Security Engineer Associate
https://simplepowershell.blogspot.com
https://cloudsec365.blogspot.com
https://msazure365.blogspot.com
https://twitter.com/Message_Talk