首页 > 解决方案 > 添加内容:拒绝访问路径“C:\”

问题描述

你好我有这个问题

我的问题:PS C:\WINDOWS\system32> escribirInfo Add-Content : 拒绝访问路径“C:\”。在 C:\Untitled2.ps1:41 char:72 + ... 序列号、版本、制造商 | 添加内容 C:\$nombre_fichero + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : PermissionDenied: (C::String) [添加内容],UnauthorizedAccessException + FullyQualifiedErrorId:GetContentWriterUnauthorizedAccessError,Microsoft.PowerShell.Commands.AddContentCommand

main{
    crearFichero
    escribirInfo
}
function crearFichero
    {
    #Expliqueu que fa la funció!!!
        [CmdletBinding()]
        Param(

        )
        Begin
        {
        #RES
        }
        Process
        {
            $nombre_sistema = (Get-WmiObject -Class Win32_ComputerSystem -Property Name).Name
            $ip = Test-Connection $nombre_sistema -Count 1 | select IPV4Address
            $ip_replace = $ip.IPV4Address.IPAddressToString.Replace(".","_")
            $fecha = Get-Date -Format "MM_dd_yyyy"
            $ext = ".txt"
            $nombre_fichero = [System.String]::Concat($ip_replace, $fecha, $ext)
            $crear_fichero= New-Item C:\$nombre_fichero -ItemType file
        }
    }

function escribirInfo
    {
    #Expliqueu que fa la funció!!!
        [CmdletBinding()]
        Param(

        )
        Begin
        {
        #RES
        }
        Process
        {
        gwmi win32_bios | select SerialNumber, Version, Manufacturer | Add-Content C:\$nombre_fichero

        }
    }
    }

标签: powershell

解决方案


默认情况下,用户无权在 C:\ 的根目录下创建文件:

PS C:\> (get-acl c:\).Access


FileSystemRights  : AppendData
AccessControlType : Allow
IdentityReference : NT AUTHORITY\Authenticated Users
IsInherited       : False
InheritanceFlags  : None
PropagationFlags  : None

FileSystemRights  : -536805376
AccessControlType : Allow
IdentityReference : NT AUTHORITY\Authenticated Users
IsInherited       : False
InheritanceFlags  : ContainerInherit, ObjectInherit
PropagationFlags  : InheritOnly

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

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

FileSystemRights  : ReadAndExecute, Synchronize
AccessControlType : Allow
IdentityReference : BUILTIN\Users
IsInherited       : False
InheritanceFlags  : ContainerInherit, ObjectInherit
PropagationFlags  : None

推荐阅读