运行提升的PowerShell脚本和导入系统模块
问题描述:
我正在尝试使用批处理文件调用.PS1来生成仅包含用户名和其他电话号码详细信息的csv文件。我有脚本来生成csv文件。运行提升的PowerShell脚本和导入系统模块
Get-ADUser -Filter * -Properties otherTelephone |
select name, @{L='otherTelephone'; E={$_.otherTelephone[0]}} | sort-object otherTelephone | select-object -last 1000 |
Export-Csv C:\Test.csv -NoTypeInformation
和我有批处理文件来提升PowerShell的
powershell -noprofile -command "&{ start-process powershell -ArgumentList '-noprofile -file C:\Test.ps1' -verb RunAs}"
问题是,当我试图通过添加
powershell.exe -ImportSystemModules
在PowerShell中的前导入系统模块脚本,CSV仅返回标题信息,例如名字和其他电话。如果我手动导入模块,即右键单击导入系统模块,但是在运行脚本之前尝试加载模块,则脚本不起作用。
基本上我需要以管理员身份运行PS脚本,导入系统模块并让代码输出我的数据。
任何帮助,我哪里去错了赞赏。
powershell.exe -ImportSystemModules Get-ADUser -Filter * -Properties otherTelephone |
select name, @{L='otherTelephone'; E={$_.otherTelephone[0]}} | sort-object otherTelephone | select-object -last 10 |
Export-Csv C:\Test.csv -NoTypeInformation
答
如果您需要内部脚本使用下面的代码加载模块:
Get-Module -ListAvailable | Where-Object {$_.Path -like "$PSHOME*"} | Import-Module
的-ImportSystemModules
开关是powershell.exe
的标志。如果在脚本中调用powershell.exe -ImportSystemModules
,它将启动另一个PowerShell实例并将其加载到其中。
您还可以将-ImportSystemModules
添加到批处理文件中的powershell调用中。这应该工作太
问候
有很大的帮助的感谢,我加入了-ImportSystemModules批处理文件并运行它这样** PowerShell的-noprofile -command“&{开始处理PowerShell的-ArgumentList“-importSystemModules - 文件C:\ VMRs \ 1.ps1'-verb RunAs}“** – Clagnuts 2015-02-23 14:16:45