2017-08-08 45 views
1

我有以下模塊:PowerShell腳本模塊不返回任何信息

Function Get-ProcessHash { 
    param($ComputerName) 

    $username = $ComputerName + '\localadm' 
    $password = ConvertTo-SecureString 'supersecret' -AsPlainText -Force 
    $cred = New-Object -typename System.Management.Automation.PSCredential -ArgumentList $username, $password 

    Invoke-Command -ComputerName $ComputerName -Credential $cred -Authentication Negotiate -ScriptBlock { 
     Get-Process * | Select-Object Id, Name, ProductVersion, Company, Path, @{l="SHA256";e={if ($_.Path -ne $null) { (Get-FileHash $_.Path).Hash}}} 
    } 
} 

這個腳本模塊位於C:\Users\<username>\Documents\WindowsPowerShell\Modules\SuperModule\SuperModule.psm1。我可以通過Get-Command -Module SuperModule看到它的功能。如果我在函數之外手動運行腳本的內容,它將工作並返回所有值,但是當我嘗試運行該函數爲PS C:\Users\<username>\Documents\Scripts> Get-ProcessHash US0001時,它不返回任何內容。

憑據是有效的,我可以在模塊外執行腳本,它的工作原理。

+4

您在加載時是否對此模塊進行了更改?如果關閉所有活動的PowerShell會話並重試,您的問題是否相同? – Matt

+1

好點@Matt,也可以試試'Import-Module -Force' – briantist

+0

我通常會在評論中試着遵循KISS。 – Matt

回答

0

馬特說,在評論中,解決方案很簡單:

「,同時將其裝填如果關閉所有活動PowerShell會話,然後再試一次是你的問題一樣你一直在修改這個模塊? 「