Add-Content: доступ к пути 'C: \' запрещен - PullRequest
0 голосов
/ 19 января 2019

Здравствуйте, у меня есть эта проблема

Моя проблема: PS C: \ WINDOWS \ system32> escribirInfo Add-Content: Доступ к пути «C: \» запрещен. На C: \ Untitled2.ps1: 41 символ: 72 + ... SerialNumber, Версия, Производитель | Дополнительный контент C: \ $ nombre_fichero + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo: PermissionDenied: (C :: String) [Add-Content], 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

        }
    }
    }

Ответы [ 2 ]

0 голосов
/ 19 января 2019

Добро пожаловать, Альберто Мартин Родригес,

@ Герт-Ян-Краайевельд прав. Вы можете запускать с правами администратора или даже лучше сохранять файлы где-нибудь в вашем пользовательском каталоге или в другом подходящем месте вместо корня вашего основного диска.

т.е. C: \ $ nombre_fichero -> C: \ Users {{YourUserName}} \ $ nombre_fichero

0 голосов
/ 19 января 2019

Пользователи не имеют разрешения на создание файлов в корне 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
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...