M365 WriteLicenseSkuDisplayNames WA

M365SLICNAMES.WriteLicenseSkuDisplayNames.WA (WriteActionModuleType)

Will write default DisplayName list to CSV file.

Element properties:

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

Member Modules:

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

Overrideable Parameters:

IDParameterTypeSelector
EventIDFilterstring$Config/EventIDFilter$
OutFilestring$Config/OutFile$
ProbeActionTimeoutSecondsint$Config/ProbeActionTimeoutSeconds$
WriteToEventLogbool$Config/WriteToEventLog$

Source Code:

<WriteActionModuleType ID="M365SLICNAMES.WriteLicenseSkuDisplayNames.WA" Accessibility="Internal" Batching="false" RunAs="M365SL!M365SL.RunAs.Profile">
<Configuration>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" minOccurs="1" name="DEFAULT_LIST" type="xsd:string"/>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" minOccurs="1" name="EventIDFilter" type="xsd:string"/>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" minOccurs="1" name="OutFile" type="xsd:string"/>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" minOccurs="1" name="ProbeActionTimeoutSeconds" type="xsd:integer"/>
<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="WriteToEventLog" type="xsd:boolean"/>
</Configuration>
<OverrideableParameters>
<OverrideableParameter ID="EventIDFilter" Selector="$Config/EventIDFilter$" ParameterType="string"/>
<OverrideableParameter ID="OutFile" Selector="$Config/OutFile$" ParameterType="string"/>
<OverrideableParameter ID="ProbeActionTimeoutSeconds" Selector="$Config/ProbeActionTimeoutSeconds$" ParameterType="int"/>
<OverrideableParameter ID="WriteToEventLog" Selector="$Config/WriteToEventLog$" ParameterType="bool"/>
</OverrideableParameters>
<ModuleImplementation Isolation="Any">
<Composite>
<MemberModules>
<WriteAction ID="WA" TypeID="Windows!Microsoft.Windows.PowerShellWriteAction">
<ScriptName>M365SLIC.Write-SkuDisplayNames.ps1</ScriptName>
<ScriptBody><Script><![CDATA[<#
Filename: M365SLIC.Write-SkuDisplayNames.ps1
Author: Tyson Paul
Description: Will write default DisplayName list to CSV file.
Version History:
2020.11.07.1423 - Redesigned for agent task
2020.09.21.0000 - v1
#>

Param (
[string]$DEFAULT_LIST,
[string]$EventIDFilter,
[string]$OutFile = 'C:\Windows\Temp\M365SSM\License\LicenseSkuDisplayNames.csv',
[string]$WorkflowName = '<No WorkflowName provided>',
[string]$WriteToEventLog = 'false'
)

[bool]$WriteToEventLog = [System.Convert]::ToBoolean($WriteToEventLog)
[string]$ScriptName = 'M365SLIC.Write-SkuDisplayNames.ps1'
[Int]$info=0
[Int]$critical=1
[Int]$warn=2
[string]$whoami = whoami.exe
[int]$maxLogLength = 31000 #max chars to allow for event log messages
$ThisScriptInstanceGUID = [System.GUID]::NewGuid().ToString().Substring((35 ) -5).ToUpper()
$ScriptTimer = [System.Diagnostics.Stopwatch]::StartNew()


################################################################


Function LogIt {
[CmdletBinding(DefaultParameterSetName='Parameter Set 1',
SupportsShouldProcess=$true,
PositionalBinding=$false,
HelpUri = 'http://MonitoringGuys.com/',
ConfirmImpact='Medium')]
Param
(
[int]$EventID,

[Parameter(Mandatory=$true,
ParameterSetName='Parameter Set 1')]
[ValidateRange(0,2)]
[int]$Type,

[Alias("Message")]
[string]$msg = 'No message specified.',

[bool]$Proceed,

$Line
)

If ($Proceed -AND (($EventIDFilter -match $EventID) -OR ($EventIDFilter.Length -eq 0) ))
{
# Since this is a common function, only attempt to include auth info if it is truly available/exists.
If ("$($M365_ClientID)$($M365_ClientSecret)" -ne ''){
Try {
$authInfo = @"
ClientID: $M365_ClientID

"@
} Catch {
Write-Output "Tried to include workflow auth info into logging but something failed. Not a big deal."
}

If ($SenderEmailAddress) {
$authInfo += @"
ReceiverEmailAddress: $ReceiverEmailAddress
ReceiverPassword: $ReceiverPassword
SenderEmailAddress: $SenderEmailAddress
SenderPassword: $SenderPassword
TenantName: $TenantName
MailflowDirection: $MailflowDirection
TLSVersion: $TLSVersion
"@
}
}

$output = @"

WorkflowName: $WorkflowName
Message: $msg
AuthInfo (if applicable):
$authInfo

Invocation/Function: $($MyInvocation.InvocationName)
ThisScriptInstanceGUID: $ThisScriptInstanceGUID
ScriptLine: $Line
Running As: $whoami

WriteToEventLog: $WriteToEventLog

Any Errors: $($Error[0])

"@

$oEvent = New-Object -ComObject 'MOM.ScriptAPI'
If ($output.Length -gt $maxLogLength){
$output = ($output.Substring(0,([math]::Min($output.Length,$maxLogLength) )) + '...TRUNCATED...')
}
$oEvent.LogScriptEvent("$ScriptName",$EventID,$Type,$output )
}
}
################################################################
Function _LINE_ {
$MyInvocation.ScriptLineNumber
}


############## TESTING ##############
<# #Run this as needed when testing

Function Testing {
$Testing = $true
Get-Item Alias:\_LINE_ -ErrorAction Ignore | Remove-Item -ErrorAction Ignore
$testFile = (Join-path $TestFolder ("PARAMS_$($ScriptName)"))
# Test-Path $testFile
. $testFile
$error.Clear()

}

$TestFolder = 'C:\Test\M365SMP_Dev\License\TestSetup'
If (Test-Path -Path $TestFolder) {
. Testing
}

#>
############## TESTING ##############

LogIt -EventID 9990 -Type $info -Msg "Begin script..." -Proceed $WriteToEventLog -LINE $(_LINE_); $Error.Clear()

# This is where the data file will be stored
$thisTempFolder = (Split-Path $OutFile -Parent)
If (-NOT (Test-Path $thisTempFolder)) {
$Message = "Temp path does not exist: [$($thisTempFolder)]. Creating folder now..."
Write-Output $Message
LogIt -EventID 9992 -Type $info -Msg $Message -Proceed $WriteToEventLog -LINE $(_LINE_); $Error.Clear()
Try {
New-Item -Path $thisTempFolder -ItemType Directory -ErrorAction Stop
} Catch {
$Message = "Failed to create Temp path: [$($thisTempFolder)]. Exiting."
LogIt -EventID 9995 -Type $warn -Msg $Message -Proceed $true -LINE $(_LINE_); $Error.Clear()
Exit
}
}

# Write data from online source if it was successfully retrieved. Otherwise write the default data to file.
$message = "Will attempt to write DisplayName CSV data to file: [$($OutFile)]..."
Write-Output $message
LogIt -EventID 9992 -Type $info -Msg $message -Proceed $WriteToEventLog -LINE $(_LINE_); $Error.Clear()
Try {
$DEFAULT_LIST | Set-Content -Path $OutFile -ErrorAction Stop
$message = "Success writing DisplayName CSV data to file: [$($OutFile)]. "
Write-Output $message
LogIt -EventID 9992 -Type $info -Msg $message -Proceed $WriteToEventLog -LINE $(_LINE_); $Error.Clear()
} Catch {
$message = "Failed to write DisplayNames CSV data to file: [$($OutFile)]. Exiting."
Write-Output $message
LogIt -EventID 9995 -Type $warn -Msg $message -Proceed $true -LINE $(_LINE_); $Error.Clear()
}

LogIt -EventID 9991 -Type $info -Proceed $WriteToEventLog -msg "Script Finished in [$($ScriptTimer.Elapsed.TotalSeconds)] seconds. `n" -LINE $(_LINE_)
]]></Script></ScriptBody>
<Parameters>
<Parameter>
<Name>DEFAULT_LIST</Name>
<Value>$Config/DEFAULT_LIST$</Value>
</Parameter>
<Parameter>
<Name>EventIDFilter</Name>
<Value>$Config/EventIDFilter$</Value>
</Parameter>
<Parameter>
<Name>OutFile</Name>
<Value>$Config/OutFile$</Value>
</Parameter>
<Parameter>
<Name>WorkflowName</Name>
<Value>$Config/WorkflowName$</Value>
</Parameter>
<Parameter>
<Name>WriteToEventLog</Name>
<Value>$Config/WriteToEventLog$</Value>
</Parameter>
</Parameters>
<TimeoutSeconds>$Config/ProbeActionTimeoutSeconds$</TimeoutSeconds>
</WriteAction>
</MemberModules>
<Composition>
<Node ID="WA"/>
</Composition>
</Composite>
</ModuleImplementation>
<OutputType>Windows!Microsoft.Windows.SerializedObjectData</OutputType>
<InputType>System!System.BaseData</InputType>
</WriteActionModuleType>