powershell - 添加内容:拒绝访问路径“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
}
}
}
解决方案
默认情况下,用户无权在 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
推荐阅读
- php - $_SERVER['SERVER_SOFTWARE'] 在命令行上不起作用
- php - using group by and max on columns remove repeat value just get Maximum id value
- c# - 如何将 XML 子节点添加到多个父节点
- typescript - Puppeteer / Typescript:如何在 eval$ 页面函数中转换为 Element?
- vue.js - Vue:编译失败(字符串必须使用单引号)
- single-page-application - B2C:AcquireTokenSilent 对于 ADFS 失败,适用于本地帐户
- android - 按钮阴影参数
- sql-server - 操作数数据类型 nvarchar(max) 对减法运算符无效
- c - 在 10X10 数组中随机游走
- amazon-web-services - 如何使用 Curl 执行简单的 AWS/EC2 REST API 调用