2016-06-08 81 views
0

我的PowerShell命令是這樣的:在批處理文件的問題調用Powershell的

Get-WmiObject -class Win32_printer | ft name, systemName, shareName >> $PSScriptRoot\printers.txt 
Get-ItemProperty HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\* | Select-Object DisplayName, DisplayVersion, InstallDate | Format-Table –AutoSize >> $PSScriptRoot\programs.txt 
Get-WmiObject -Class Win32_MappedLogicalDisk | select Name, ProviderName >> $PSScriptRoot\drives.txt 

我批的是:

@ECHO OFF 
SET Directory=%~dp0 
SET PowerShellScriptPath=%Directory%reimage_checklist.ps1 
PowerShell -NoProfile -ExecutionPolicy Bypass -Command "& '%PowerShellScriptPath%'"; 

如果我運行在IDE的PowerShell腳本,它提出了三個文本文件與請求的信息。如果我運行批處理文件,它會輸出三個批處理文件,但網絡驅動器文本文件是空白的。

+0

感謝肯解決了,我不能弄清楚如何編輯它這樣。 – giveen

+0

刪除'-NoProfile'參數,看看是否不能解決您的問題。很確定,它可以在不加載當前用戶信息的情況下運行,包括其映射的驅動器。 – TheMadTechnician

+0

@TheMadTechnician它應該忽略PowerShell配置文件嗎? – Matt

回答

0

加入

Set-ExecutionPolicy -Scope CurrentUser Bypass 

到PowerShell腳本和刪除

-ExecutionPolicy Bypass 

從批處理文件