【问题标题】:Powershell error trying to create a text file尝试创建文本文件的 Powershell 错误
【发布时间】:2018-12-07 00:25:32
【问题描述】:
Sub CreateAfile
    Set fs = CreateObject("Scripting.FileSystemObject")
    Set a = fs.CreateTextFile("c:\testfile.txt", True)
    a.WriteLine("This is a test.")
    a.Close
End Sub

尝试在 Powershell 中运行上述代码时,我收到“',' 之后缺少表达式”。谢谢

【问题讨论】:

  • 那不是 PowerShell 代码。那是VBA?
  • 代码运行良好,如.vbs。根据权限,您可能无法写入系统驱动器的根目录。
  • 此 VBScript 的 PowerShell 等效项可能是 Add-Content -Path "c:\testfile.txt" -Value "This is a test."

标签: powershell


【解决方案1】:

那不是真正的PowerShell,而是VB Script

在 PowerShell 中创建文件非常简单:

New-Item -Name "myFile.txt" -ItemType File -Path "C:\temp"

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-07-11
    • 2021-09-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-06-19
    相关资源
    最近更新 更多