【问题标题】:Unable to run powershell script within powershell无法在 powershell 中运行 powershell 脚本
【发布时间】:2021-05-13 23:34:54
【问题描述】:

如果我运行此代码,它将运行文件

{Write-host "Please Enter the email address of the user you want to check the permissions"
 $user = Read-Host
 Powershell.exe  C:\Temp\Report\Reports.ps1}

但是如果我像这样运行它,这就是我需要做的

{ Write-host "Please Enter the email address of the user you want to check the permissions"
 $user = Read-Host
 Powershell.exe  C:\Temp\Report\Reports.ps1 -processOneDrive $true -OneDriveEmail $user}

我收到此错误

Powershell.exe : C:\Temp\ReportSharedFiles\ReportSharedFiles.ps1 : Missing an argument for parameter 'OneDriveEmail'. Specify a 
At C:\Temp\ReportSharedFiles\Full Exchange Script Menu.ps1:88 char:2
+  Powershell.exe "c:\Temp\ReportSharedFiles\ReportSharedFiles.ps1" -pr ...
+  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (C:\Temp\ReportS...il'. Specify a :String) [], RemoteException
    + FullyQualifiedErrorId : NativeCommandError
 
parameter of type 'System.String' and try again.
At line:1 char:71
+ ... haredFiles\ReportSharedFiles.ps1 -processOneDrive True -OneDriveEmail
+                                                            ~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (:) [ReportSharedFiles.ps1], ParameterBindingException
    + FullyQualifiedErrorId : MissingArgument,ReportSharedFiles.ps1

我做错了什么,我怎样才能让它工作?任何帮助将不胜感激

【问题讨论】:

  • 是您的 reports.ps1 文件调用 C:\Temp\Report\Full Exchange Script Menu.ps1。如果是这样,请检查 Full Exchange Script Menu.ps1 中的 line:88 char:2 与开关冲突 -processOneDrive $true -OneDriveEmail $user
  • @ClintOliveira 抱歉是错误的错误,我修复了该错误并更改了编辑错误。这就是我在第 88 行所拥有的 Powershell.exe "c:\Temp\Report\Reports.ps1" -processOneDrive $true -OneDriveEmail 它就像它不喜欢阅读我出于某种原因提出的论点一样。没有它们它会正常工作,但我需要它们

标签: powershell scripting office365 powershell-3.0 powershell-4.0


【解决方案1】:

我相信它会在错误中要求您提供一个 sting 参数

'System.String' 类型的参数,然后重试。

希望一切顺利>

 { [string]$user = Read-Host "Please Enter the email address of the user you want to check the permissions"
 Powershell.exe  C:\Temp\Report\Reports.ps1 -processOneDrive $true -OneDriveEmail $user}

输入字符串 >

【讨论】:

  • 这不可能,但尝试过但仍然错误。如果我在没有参数 -processOneDrive $true -oneDriveEmail $user 的情况下对其进行编码,那么它将运行 powershell 脚本。但是我需要使用这些论点。只有当它们被放入时才会导致错误。我想知道在调用另一个脚本并同时添加参数时我是否做错了什么。有没有可能做到。我知道如果我在 powershell 命令中运行它,它也会在参数 in 中运行良好。只有在 powershell 脚本中运行 powershell 脚本时,它才会导致参数 in 出现错误
  • 如果 PowerShell 命令有效,则问题在于调用“Full Exchange Script Menu.ps1”脚本时如何使用这些参数
【解决方案2】:

我想通了。似乎在另一个脚本中运行 powershell 脚本并包含参数时。当涉及到 -processOneDrive $true 它试图将其转换为导致错误的 boolem 。我将其更改为 1,我确定这意味着 true,所以代码看起来像这样

Powershell.exe "c:\Temp\Report\Reports.ps1" -processOneDrive 1 -OneDriveEmail $user

现在运行顺利。感谢所有试图帮助我的人:)

【讨论】:

    猜你喜欢
    • 2020-12-05
    • 1970-01-01
    • 1970-01-01
    • 2016-07-13
    • 2013-01-02
    • 2018-03-21
    • 2016-09-14
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多