Skip to content

The Provided Example Nr4 in Powershell Documentation appears to be incorrect #9256

@HansLoepfe

Description

@HansLoepfe

Prerequisites

  • Existing Issue: Search the existing issues for this repository. If there is an issue that fits your needs do not file a new one. Subscribe, react, or comment on that issue instead.
  • Descriptive Title: Write the title for this issue as a short synopsis. If possible, provide context. For example, "Typo in Get-Foo cmdlet" instead of "Typo."
  • Verify Version: If there is a mismatch between documentation and the behavior on your system, ensure that the version you are using is the same as the documentation. Check this box if they match or the issue you are reporting is not version specific.

Links

https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.management/get-psdrive?view=powershell-7.2#example-4-check-to-see-if-a-drive-is-in-use-as-a-windows-powershell-drive-name

Summary

The if-statement for 'get-psdrive' used in Example 4: does NOT return 'true' or 'false' as expected.

Details

This is the Code used in Example #4
if (Get-PSDrive X -ErrorAction SilentlyContinue) { Write-Host 'The X: drive is already in use.' } else { New-PSDrive -Name X -PSProvider Registry -Root HKLM:\SOFTWARE }

Suggested Fix

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-managementArea - Microsoft.PowerShell.Management moduleresolution-answeredStatus - closed by existing documentation

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions