2013-11-26 179 views
1

我需要一些幫助來執行遠程腳本。我想要做的就是連接到遠程服務器並使用命令導入.psm1。 問題似乎是Powershell在執行腳本的計算機上的用戶路徑中查找文件。我也將腳本複製到了網絡共享中,但是我得到了在那裏執行的相同結果。PowerShell在本地運行腳本 - 執行遠程操作

Script.ps1

Invoke-Command -ComputerName servername.domain.com -Credential domain\admin.account –ScriptBlock { 

#!! Microsoft MDT Section !! 
# Import Microsoft MDT commands 
#Add-PSSnapIn Microsoft.BDD.PSSnapIn 
Import-Module –name .\MDTDB.psm1 
# 
#Connect to MDT database 
Connect-MDTDatabase –sqlServer servername.domain.com –database DATABASE 

#Import file with settings to add servers to database 
#$vms = Import-Csv InputServerInfo.csv 
$machines = Import-Csv .\InputServerInfo.csv 
# 
# Script commands goes here 
} 

錯誤消息:

The specified module '.\MDTDB.psm1' was not loaded because no valid module file was found in any module directory. 
    + CategoryInfo   : ResourceUnavailable: (.\MDTDB.psm1:String) [Import-Module], FileNotFoundException 
    + FullyQualifiedErrorId : Modules_ModuleNotFound,Microsoft.PowerShell.Commands.ImportModuleCommand 
    + PSComputerName  : servername.domain.com 

The term 'Connect-MDTDatabase' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again. 
    + CategoryInfo   : ObjectNotFound: (Connect-MDTDatabase:String) [], CommandNotFoundException 
    + FullyQualifiedErrorId : CommandNotFoundException 
    + PSComputerName  : servername.domain.com 

Could not find file 'C:\Users\admin.account\Documents\InputServerInfo.csv'. 
    + CategoryInfo   : OpenError: (:) [Import-Csv], FileNotFoundException 
    + FullyQualifiedErrorId : FileOpenFailure,Microsoft.PowerShell.Commands.ImportCsvCommand 
    + PSComputerName  : servername.domain.com 

我試圖與這兩個調用命令和新的PSSession,但我無法得到它的工作。我還重新討論了Dot Source在執行前加載內存中的腳本,但我不確定這一點。

我真的會爲這件事情指點一些指針。

回答

1

給那就是遠程計算機訪問該模塊的完整的UNC路徑

Import-Module \\server\share\MDTDB.psm1 
+0

當我嘗試,我得到以下錯誤:GET-itemproperty:找不到路徑「H:\ - 」,因爲它不存在。在\\ servername \ share \ MDTDB.psm1:130 char:26 + $ mdtProperties = get-itemproperty $ drivePath + ~~~~~~~~~~~~~~~~~~~~~~~~~ ~~ + CategoryInfo:ObjectNotFound:(H:\ - :字符串)[Get-ItemProperty],ItemNotFoundException + FullyQualifiedErrorId:PathNotFound,Microsoft.PowerShell.Commands.GetItemPropertyCommand似乎Powershell以某種方式希望我的本地映射H:\驅動器存在服務器也? – user3012250

+0

你已經通過了第一個障礙,因爲它現在正在加載模塊。 $ drivepath是如何設置的?你需要找到h:\傳遞給它的東西 – malexander

相關問題