I am trying to follow MS article, https://learn.microsoft.com/en-us/powershell/module/exchange/new-dlpcompliancerule?view=exchange-ps
Example 3
$data = Get-Content -Path "C:\Data\Sensitive Type.txt" -ReadCount 0
New-DLPComplianceRule -Name "Contoso Rule 1" -Policy "Contoso Policy 1" -AdvancedRule $data -NotifyUer
But getting an error saying that $data is not string. My colleagues PC works fine but mine requires out-string in the first line. What is the difference? Any advice is appreciated.
Thank you,
When I ran the same code in my environment, I got same error saying
Connot convert value to type System.String:Response:
To resolve the error, you need to add
Out-Stringat the end that converts the array of strings returned by the Get-Content cmdlet to a single string.When I added
Out-Stringat the end, I got the response successfully like below:Response:
To confirm that, I checked the same in Microsoft Purview Portal where Data loss prevention compliance rule named
Contoso Rule 1created successfully:If it's working in your colleagues PC without adding
Out-String, verify whether you are using different version of PowerShell compared to them by running below command: