Configure OneDrive Discovery

M365SONE.Configure.OneDrive.POSH.WA (WriteActionModuleType)

Will add registry settings so that objects can become discovered.

Element properties:

TypeWriteActionModuleType
IsolationAny
AccessibilityInternal
RunAsM365SL.RunAs.Profile
InputTypeSystem.BaseData
OutputTypeMicrosoft.Windows.SerializedObjectData

Member Modules:

ID Module Type TypeId RunAs 
POSH WriteAction Microsoft.Windows.PowerShellWriteAction Default

Overrideable Parameters:

IDParameterTypeSelector
DeleteConfigurationbool$Config/DeleteConfiguration$
IntervalSecondsint$Config/IntervalSeconds$
M365_AccountNamestring$Config/M365_AccountName$
M365_AccountPasswordstring$Config/M365_AccountPassword$
M365_ClientIDstring$Config/M365_ClientID$
M365_ClientSecretstring$Config/M365_ClientSecret$
PoshLibraryPathstring$Config/PoshLibraryPath$
WriteActionTimeoutSecondsint$Config/WriteActionTimeoutSeconds$
WriteToEventLogbool$Config/WriteToEventLog$

Source Code:

<WriteActionModuleType ID="M365SONE.Configure.OneDrive.POSH.WA" Accessibility="Internal" Batching="false" RunAs="M365SL!M365SL.RunAs.Profile">
<Configuration>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" minOccurs="1" name="DeleteConfiguration" type="xsd:boolean"/>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" minOccurs="1" name="IntervalSeconds" type="xsd:integer"/>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" minOccurs="1" name="M365_AccountName" type="xsd:string"/>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" minOccurs="1" name="M365_AccountPassword" type="xsd:string"/>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" minOccurs="1" name="M365_ClientID" type="xsd:string"/>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" minOccurs="1" name="M365_ClientSecret" type="xsd:string"/>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" minOccurs="1" name="MgmtGroupRegKey" type="xsd:string"/>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" minOccurs="1" name="PoshLibraryPath" type="xsd:string"/>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" minOccurs="1" name="TenantName" type="xsd:string"/>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" minOccurs="1" name="WorkflowName" type="xsd:string"/>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" minOccurs="1" name="WriteActionTimeoutSeconds" type="xsd:integer"/>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" minOccurs="1" name="WriteToEventLog" type="xsd:boolean"/>
</Configuration>
<OverrideableParameters>
<OverrideableParameter ID="DeleteConfiguration" Selector="$Config/DeleteConfiguration$" ParameterType="bool"/>
<OverrideableParameter ID="IntervalSeconds" Selector="$Config/IntervalSeconds$" ParameterType="int"/>
<OverrideableParameter ID="M365_AccountName" Selector="$Config/M365_AccountName$" ParameterType="string"/>
<OverrideableParameter ID="M365_AccountPassword" Selector="$Config/M365_AccountPassword$" ParameterType="string"/>
<OverrideableParameter ID="M365_ClientID" Selector="$Config/M365_ClientID$" ParameterType="string"/>
<OverrideableParameter ID="M365_ClientSecret" Selector="$Config/M365_ClientSecret$" ParameterType="string"/>
<OverrideableParameter ID="PoshLibraryPath" Selector="$Config/PoshLibraryPath$" ParameterType="string"/>
<OverrideableParameter ID="WriteActionTimeoutSeconds" Selector="$Config/WriteActionTimeoutSeconds$" ParameterType="int"/>
<OverrideableParameter ID="WriteToEventLog" Selector="$Config/WriteToEventLog$" ParameterType="bool"/>
</OverrideableParameters>
<ModuleImplementation Isolation="Any">
<Composite>
<MemberModules>
<WriteAction ID="POSH" TypeID="Windows!Microsoft.Windows.PowerShellWriteAction">
<ScriptName>M365SONE.ConfigureOneDrive.ps1</ScriptName>
<ScriptBody><Script>&lt;#
Filename: M365SONE.ConfigureOneDrive.ps1
Description: Will configure registry settings to enable discovery of entities
Author: Tyson Paul
Blog: MonitoringGuys.com
Version History:
2020.11.06.1660 - Added ability to delete configuration.
2020.09.28.1846 - v1
#&gt;
########################################################################################################

Param(
[int]$IntervalSeconds,
[string]$M365_ClientID,
[string]$M365_ClientSecret,
[string]$M365_AccountName,
[string]$M365_AccountPassword,
[string]$TenantName,

[string]$DeleteConfiguration = 'false',
[string]$MgmtGroupRegKey,
[string]$PoshLibraryPath, #comma-separated list of .ps1 files to load

[string]$WorkflowName = '&lt;No WorkflowName provided&gt;',
[string]$WriteToEventLog = 'false'
)

[bool]$WriteToEventLog = [System.Convert]::ToBoolean($WriteToEventLog)
[bool]$DeleteConfiguration = [System.Convert]::ToBoolean($DeleteConfiguration)
[string]$ScriptName = 'M365SONE.ConfigureOneDrive.ps1'
$NameSpace = 'OneDrive'

######################### FUNCTIONS ############################
################################################################
Function Load-Library {
Param (
[string]$PoshLibraryPath
)
$ErrorActionPreference = 'STOP'
If ($PoshLibraryPath ){
ForEach ($Path in $PoshLibraryPath.Split(',') ){
Try {
If (($Path.Length) -AND ($Path -notmatch '^-1$')) {
. $Path
}
} Catch {
Write-Host "Line [$($MyInvocation.ScriptLineNumber )]: Error loading PoshLibrary at path:[$($Path)]. This is likely to cause many other dependent functions to fail. `n`nError data: $($_)`n`n"
}
}
}
$ErrorActionPreference = 'CONTINUE'
}
################################################################

############## TESTING ##############
&lt;# #Run this as needed when testing

#---------------------------------------
Function Testing {
$Testing = $true
$testParamsFile = (Join-path $TestFolder ("PARAMS_$($ScriptName)"))
#Write-Host "$(Test-Path $testParamsFile):$($testParamsFile)" -F Yellow -B Green
. $testParamsFile
. Load-Library -PoshLibraryPath $PoshLibraryPath

# Encode user data/passwords in current test user context
$M365_ClientSecret = Encode-UserData $M365_ClientSecret_PLAINTEXT
$M365_AccountPassword = Encode-UserData $M365_AccountPassword_PLAINTEXT
$error.Clear()
LogIt -EventID 9995 -Type $warn -Proceed $true -msg "TESTING ENABLED. Test file used: [$($testFile)]" -LINE $(_LINE_); $Error.Clear()
}
#---------------------------------------

$TestFolder = "C:\Test\M365SMP_Dev\$($NameSpace)\TestSetup"
If (Test-Path -Path $TestFolder) {
. Testing
}
#&gt;
############## TESTING ##############

. Load-Library -PoshLibraryPath $PoshLibraryPath

LogIt -EventID 9990 -Type $info -Msg "Begin Script. " -Proceed $WriteToEventLog -LINE $(_LINE_); $Error.Clear()
Write-Output "Computer: $([System.Net.Dns]::GetHostByName($env:computerName).HostName)"

#verify that TenantName is valid/exists. If invalid, will exit.
Verify-TenantName -TenantName $TenantName -MgmtGroupRegKey $MgmtGroupRegKey

$TenantKey = Join-Path $MgmtGroupRegKey $TenantName
$RegKey = Join-Path $TenantKey $NameSpace
LogIt -EventID 9992 -Type $info -Msg "Reg Key set to [$($RegKey)] " -Proceed $WriteToEventLog -LINE $(_LINE_); $Error.Clear()

# Will proceed to delete config if appropriate. This function is designed to be run dot-sourced
. Verify-ShouldDeleteConfiguration

LogIt -EventID 9992 -Type $info -Msg "Formatting ClientSecret..." -Proceed $WriteToEventLog -LINE $(_LINE_); $Error.Clear()
$M365_ClientSecret_ENCRYPTED = Format-ClientSecret $M365_ClientSecret

LogIt -EventID 9992 -Type $info -Msg "Encrypting AccountPassword for account: [$($M365_AccountName)]..." -Proceed $WriteToEventLog -LINE $(_LINE_); $Error.Clear()
$M365_AccountPassword_ENCRYPTED = Format-AccountPassword $M365_AccountPassword

# This section will construct a hash object which represents the registry values to be added.
#region regsettingshash
$NewSettings = [ordered]@{
'IntervalSeconds' = @{
Key = $RegKey
ValueType = 'REG_SZ'
ValueData = $IntervalSeconds
}

'M365_AccountName' = @{
Key = $RegKey
ValueType = 'REG_SZ'
ValueData = $M365_AccountName
}

'M365_AccountPassword' = @{
Key = $RegKey
ValueType = 'REG_SZ'
ValueData = $M365_AccountPassword_ENCRYPTED
}

'M365_ClientID' = @{
Key = $RegKey
ValueType = 'REG_SZ'
ValueData = $M365_ClientID
}

'M365_ClientSecret' = @{
Key = $RegKey
ValueType = 'REG_SZ'
ValueData = $M365_ClientSecret_ENCRYPTED
}
}
#endregion regsettingshash

LogIt -EventID 9992 -Type $info -Msg "Proceed to add registry data at key: [$($RegKey)] " -Proceed $WriteToEventLog -LINE $(_LINE_); $Error.Clear()
Create-RegistryEntries -NewSettings $NewSettings

LogIt -EventID 9991 -Type $info -Proceed $WriteToEventLog -msg "Script End. Finished in [$($ScriptTimer.Elapsed.TotalSeconds)] seconds. `n" -LINE $(_LINE_)
</Script></ScriptBody>
<Parameters>
<Parameter>
<Name>DeleteConfiguration</Name>
<Value>$Config/DeleteConfiguration$</Value>
</Parameter>
<Parameter>
<Name>IntervalSeconds</Name>
<Value>$Config/IntervalSeconds$</Value>
</Parameter>
<Parameter>
<Name>M365_AccountName</Name>
<Value>$Config/M365_AccountName$</Value>
</Parameter>
<Parameter>
<Name>M365_AccountPassword</Name>
<Value>$Config/M365_AccountPassword$</Value>
</Parameter>
<Parameter>
<Name>M365_ClientID</Name>
<Value>$Config/M365_ClientID$</Value>
</Parameter>
<Parameter>
<Name>M365_ClientSecret</Name>
<Value>$Config/M365_ClientSecret$</Value>
</Parameter>
<Parameter>
<Name>MgmtGroupRegKey</Name>
<Value>$Config/MgmtGroupRegKey$</Value>
</Parameter>
<Parameter>
<Name>PoshLibraryPath</Name>
<Value>$FileResource[Name='Res.M365SONE.M365Library.ps1.Resource']/Path$,$Config/PoshLibraryPath$</Value>
</Parameter>
<Parameter>
<Name>TenantName</Name>
<Value>$Config/TenantName$</Value>
</Parameter>
<Parameter>
<Name>WorkflowName</Name>
<Value>$Config/WorkflowName$</Value>
</Parameter>
<Parameter>
<Name>WriteToEventLog</Name>
<Value>$Config/WriteToEventLog$</Value>
</Parameter>
</Parameters>
<TimeoutSeconds>$Config/WriteActionTimeoutSeconds$</TimeoutSeconds>
</WriteAction>
</MemberModules>
<Composition>
<Node ID="POSH"/>
</Composition>
</Composite>
</ModuleImplementation>
<OutputType>Windows!Microsoft.Windows.SerializedObjectData</OutputType>
<InputType>System!System.BaseData</InputType>
</WriteActionModuleType>