MicrosoftDocs / PowerShell-Docs

The official PowerShell documentation sources
https://learn.microsoft.com/powershell
Other
1.99k stars 1.58k forks source link

The command to create the profile for powershell fails `New-Item -ItemType File -Path $PROFILE -Force` #11441

Closed skrabbe001 closed 3 weeks ago

skrabbe001 commented 3 weeks ago

Type of issue

Code doesn't work

Feedback

The command for creating a profile does not work, when the PowerShell directory does not exist, which it does not when installing the current version of PowerShell:

PS C:\Windows\System32> New-Item -ItemType File -Path $PROFILE -Force
New-Item: Could not find a part of the path 'C:\Users\JonesSmith\Documents\PowerShell\Microsoft.PowerShell_profile.ps1'.

Why does it not work?

Page URL

https://learn.microsoft.com/en-us/powershell/scripting/learn/shell/creating-profiles?view=powershell-7.4

Content source URL

https://github.com/MicrosoftDocs/PowerShell-Docs/blob/main/reference/docs-conceptual/learn/shell/creating-profiles.md

Author

@sdwheeler

Document Id

c3b21d50-9ab5-ad3c-316a-330a460a5dd0

skrabbe001 commented 3 weeks ago

I just created the PowerShell directory and even when all the folders in the path exists, the command still fails.

PS C:\Windows\System32> echo $profile
C:\Users\JohnSmith\Documents\PowerShell\Microsoft.PowerShell_profile.ps1
PS C:\Windows\System32> Get-Item "C:\Users\JohnSmith\Documents\PowerShell"

    Directory: C:\Users\JohnSmith\Documents

Mode                 LastWriteTime         Length Name
----                 -------------         ------ ----
d----           10/4/2024 12:23 PM                PowerShell

PS C:\Windows\System32> New-Item -Path "C:\Users\JohnSmith\Documents\PowerShell\Microsoft.PowerShell_profile.ps1" -ItemType "File" -Force
New-Item: Could not find file 'C:\Users\JohnSmith\Documents\PowerShell\Microsoft.PowerShell_profile.ps1'.

Tested both as admin and as current user.

skrabbe001 commented 3 weeks ago

Here are the access rights to the folder:

PS C:\Windows\System32> get-acl "C:\Users\JohnSmith\Documents\PowerShell"

    Directory: C:\Users\JohnSmith\Documents

Path       Owner              Access
----       -----              ------
PowerShell AzureAD\skrabbe001 NT AUTHORITY\SYSTEM Allow  FullControl…

PS C:\Windows\System32> (get-acl "C:\Users\JohnSmith\Documents\PowerShell").Access

FileSystemRights  : FullControl
AccessControlType : Allow
IdentityReference : NT AUTHORITY\SYSTEM
IsInherited       : True
InheritanceFlags  : ContainerInherit, ObjectInherit
PropagationFlags  : None

FileSystemRights  : FullControl
AccessControlType : Allow
IdentityReference : BUILTIN\Administrators
IsInherited       : True
InheritanceFlags  : ContainerInherit, ObjectInherit
PropagationFlags  : None

FileSystemRights  : FullControl
AccessControlType : Allow
IdentityReference : AzureAD\JohnSmith
IsInherited       : True
InheritanceFlags  : ContainerInherit, ObjectInherit
PropagationFlags  : None

Note that creating files in the folder with CMD.EXE or EXPLORER.EXE works fine.

michaeltlombardi commented 3 weeks ago

This repository is for documentation. You seem to be looking for support, which we can't provide here.

I suggest you try posting your issue with context in one of the available community support forums.

skrabbe001 commented 2 weeks ago

So if the command in your doc does not work, its not a doc issue?