簡體   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