繁体   English   中英

无法在 powershell 中运行 powershell 脚本

[英]Unable to run powershell script within powershell

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

{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

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

我相信它会在错误中要求您提供一个 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}

输入字符串 > 在此处输入图像描述

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

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

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM