Jump to content

Recommended Posts

Posted

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

Posted (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 by David44

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 account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...