saidei Posted July 8, 2024 Posted July 8, 2024 Hi Powershell is creating group policy report in utf-16 and script is giving me following error message. | Cannot find drive. A drive with the name ' Get-Content: C:\Temp\Script\NotattachedGroupPolicy4.ps1:12 Powershell version is PowerShell 7.4.3 I have enabled Beta: Use Unicode UTF-8 for worldwide language support in windows 11 Script is $unlinkedGPOs = @() $GPNames = get-gpo -all | select-object DisplayName foreach ( $GPName in $GPNames) { $GPReport= Get-GPOReport -Name $GPName.DisplayName -Encoding utf8 -ReportType Xml [xml]$gpoXml = Get-Content $GPReport $linknode = $gpoXml.GPO.LinksTo $linknode } Can anyone advise how to resolve this issue Thanks in advance
David44 Posted July 8, 2024 Posted July 8, 2024 (edited) The issue is with the Get-Content cmdlet. I don't think you need it. You already have the XML stored in $GPReport. When you use Get-Content and pass $GPReport to it, it's treating the XML you give it as a path and giving you an error about not finding a file at that path. Does this do what you need? $GPNames = get-gpo -all | select-object DisplayName foreach ($GPName in $GPNames) { $GPReport = Get-GPOReport -Name $GPName.DisplayName -ReportType Xml $linknode = ([xml]$GPReport).gpo.LinksTo $linknode } EDIT: I also removed -Encoding utf8 from Get-GPOReport because I think it was a red herring. Edited July 8, 2024 by David44
saidei Posted July 9, 2024 Author Posted July 9, 2024 thank you it is giving me the result now. I will update the script tonight and post here
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now