microsoft / Microsoft365DSC

Manages, configures, extracts and monitors Microsoft 365 tenant configurations
https://aka.ms/M365DSC
MIT License
1.54k stars 473 forks source link

Function Convert-M365DscHashtableToString - Enhance formatting #2980

Closed menswearUK closed 1 year ago

menswearUK commented 1 year ago

Details of the scenario you tried and the problem that is occurring

Suggested enhancement to the function Convert-M365DscHashtableToString in M365DSCUtil.psm1. When calling the function the output is returned as a string with values separated by a semicolon. This can be somewhat difficult to read - My suggestion is to return the output with each value on a new line, this could either be the default behaviour or selected via a switch.

Verbose logs showing the problem

output of target values from a DSC resource:

Target Values: AllowedDataStorageLocations=(); AllowedInboundDataTransferSources=allApps; AllowedOutboundClipboardSharingExceptionLength=0; AllowedOutboundClipboardSharingLevel=managedAppsWithPasteIn; AllowedOutboundDataTransferDestinations=allApps; AppActionIfDeviceComplianceRequired=block; AppActionIfIosDeviceModelNotAllowed=block; AppActionIfMaximumPinRetriesExceeded=block; AppDataEncryptionType=whenDeviceLocked; ApplicationId=; ApplicationSecret=; Apps=(com.microsoft.bing.halseyassistant,com.microsoft.d365.fs.mobile,com.microsoft.dynamics,com.microsoft.dynamics.inv oice,com.microsoft.dynamics.iphone.moca,com.microsoft.dynamics.iphone.moca.fieldservices,com.microsoft.dynamics.iphone. moca.sales,com.microsoft.lync2013.iphone,com.microsoft.mobile.polymer,com.microsoft.msapps,com.microsoft.msedge,com.mic rosoft.o365shdmobileapp,com.microsoft.office.excel,com.microsoft.office.outlook,com.microsoft.office.powerpoint,com.mic rosoft.office.word,com.microsoft.office365booker,com.microsoft.officelens,com.microsoft.officemobile,com.microsoft.onen ote,com.microsoft.plannermobile,com.microsoft.powerbimobile,com.microsoft.procsimo,com.microsoft.ramobile,com.microsoft .rms-sharing,com.microsoft.scmx,com.microsoft.sharepoint,com.microsoft.shiftr,com.microsoft.skydrive,com.microsoft.skyp e.teams,com.microsoft.splists,com.microsoft.stream,com.microsoft.to-do,com.microsoft.visio,com.microsoft.whiteboard,com .microsoft.workfolders,com.veradocs.ios.appstore.intune,wefwef); Assignments=(); ContactSyncBlocked=False; CustomBrowserProtocol=; DataBackupBlocked=False; Description=some descriptive words to describe the policy in the description. indescribable; DeviceComplianceRequired=True; DisableAppPinIfDevicePinIsSet=False; DisableProtectionOfManagedOutboundOpenInData=False; DisplayName=testiospolicy; Ensure=Present; ExcludedGroups=(); ExemptedAppProtocols=(Default:skype;app-settings;calshow;itms;itmss;itms-apps;itms-appss;itms-services;); FaceIdBlocked=False; FilterOpenInToOnlyManagedApps=False; FingerprintBlocked=False; ManagedBrowser=notConfigured; ManagedBrowserToOpenLinksRequired=False; ManagedIdentity=False; MaximumPinRetries=5; MinimumPinLength=4; NotificationRestriction=allow; OrganizationalCredentialsRequired=False; PeriodBeforePinReset=90.00:00:00; PeriodOfflineBeforeAccessCheck=12:00:00; PeriodOfflineBeforeWipeIsEnforced=90.00:00:00; PeriodOnlineBeforeAccessCheck=00:30:00; PinCharacterSet=numeric; PinRequired=True; PinRequiredInsteadOfBiometricTimeout=00:30:00; PrintBlocked=False; ProtectInboundDataFromUnknownSources=False; SaveAsBlocked=False; SimplePinBlocked=True; TargetedAppManagementLevels=unmanaged; TenantId=***; Verbose=True

Suggested solution to the issue

Suggested fix is to replace the final line of the Convert-M365DscHashtableToString function from: return ($values -join '; ') to: return ($values -join "rn")

If both options may be required the different output could be activated via a -newline switch added to the function

The DSC configuration that is used to reproduce the issue (as detailed as possible)

n/a - any configuration using the function will produce this output although the example was using IntuneAppProtectionPolicyiOS

The operating system the target node is running

n/a - cloud configuration - run from various windows 10 systems when testing

Version of the DSC module that was used ('dev' if using current dev branch)

dev

menswearUK commented 1 year ago

@ykuijs - This was something I'd added to a configuration in a previous PR and you advised it would be better to add in centrally. I wondered if you had any preference on whether I should amend the default behaviour of the function or, to minimise any possible unforeseen impact, I should modify the output via a switch? I don't think there are any uses of the function in the configurations which are not part of a verbose output but it's called a lot and I may have missed something in my searches. It does self reference itself and is also called in Convert-M365DscArrayToString, I'm not sure if there might be any impact here, There hasn't been in my testing but that's far from exhaustive.