我正在编写一个PowerShell脚本来操作一些Windows Installer XML(WiX).我正在使用.NET 3.5中的新XML API来实现这一点,因为我发现它比DOM更容易使用API.以下脚本片段断然拒绝工作:
[System.Reflection.Assembly]::LoadWithPartialName("System.Xml.Linq") | Out-Null
# Basic idea: Iterate through en.wxl's l10ns, get string for each l10n, search all wxs files for that value.
pushd "C:\temp\installer_l10n"
$wxlFileName = "${pwd}\en.wxl"
$wxl = [System.Xml.Linq.XDocument]::Load($wxlFileName)
$strings = $wxl.Descendants("String")
$strings
$strings | foreach {
$_
}
popd
Run Code Online (Sandbox Code Playgroud)
该脚本应在单独的行上输出每个<String>标记.一旦这个bug得到解决,我就会让它做一些更有趣的事情;-)
XML文档是标准的WiX本地化文件:
<?xml version="1.0" encoding="utf-8" ?>
<WixLocalization Culture="en-US" xmlns="http://schemas.microsoft.com/wix/2006/localization">
<String Id="0">Advertising published resource</String>
<String Id="1">Allocating registry space</String>
...
</WixLocalization>
Run Code Online (Sandbox Code Playgroud)
$ strings不是$ null(我已经明确地测试了它),如果我写了host-wxl,我可以看到文件已被加载.将$字符串管理到Get-Member会返回一个错误,指出"没有为get-member指定任何对象",write-host $字符串不执行任何操作.我也尝试过$ wxl.Descendants("WixLocalization"),结果相同.像$ wxl.Root和$ wxl.Nodes这样的东西按预期工作.使用PowerShell ISE进行调试,我看到$ strings已设置为IEnumerator,而不是预期的IEnumerable <XElement>.使用单个MoveNext测试IEnumerator,然后使用Current测试"Current =",大概是$ null.
奇怪的是,相同的技术在以前的脚本中起作用.完全相同的代码,但具有不同的变量名和字符串文字.刚刚尝试调试该脚本(以验证行为),它似乎现在也显示相同的行为.
我正在使用 PowerShell.Exiting 引擎事件来保存我的命令历史记录并在我关闭 PowerShell 会话时进行一些其他整理,从而将其注册到我的配置文件中:
# Set up automatic functionality on engine exit.
Register-EngineEvent PowerShell.Exiting -SupportEvent -Action `
{
#stuff
...
}
Run Code Online (Sandbox Code Playgroud)
当我在控制台窗口中使用 PowerShell 时,这非常有效,但是当我在 ISE 中运行 PowerShell 时,PowerShell.Exiting 事件似乎永远不会触发,因为我没有放入任何东西,无论是通常的东西还是测试代码,曾经运行。
这是一个已知问题,如果是,是否有已知的解决方法或替代方法?
您好,我在获取有关谁将计算机加入域的信息时遇到一些问题。我可以使用此代码,但这是供某些无权访问 Powershell ActiveDirectory 模块的非管理用户使用的。
Get-ADComputer myComputer -Properties ntSecurityDescriptor | Select ntSecurityDescriptor -ExpandProperty ntSecurityDescriptor
Run Code Online (Sandbox Code Playgroud)
这是我感兴趣的业主财产。但现在我需要让它与 ADSI 一起工作
$Computer = [ADSI](([ADSISearcher]"(name=myComputer)").FindOne().Path)
$Computer.nTSecurityDescriptor
System.__ComObject
Run Code Online (Sandbox Code Playgroud)
如何使用 ADSI“扩展”nTSecurityDescriptor 的属性?
我试图执行我的Powershell脚本每5分钟运行一次.我尝试使用Windows 7的任务计划程序来运行它,但它在记事本上打开我的脚本并且不会在我的数据库中插入任何内容
下面是我的Powershell V-2.0脚本.我不确定我的代码中是否有错误(我怀疑)或者我是否可以将其包含在我的脚本中以便每隔5分钟运行一次,从早上9点到晚上9点.
这是我如何安排它:
General
--------
Run only when user is logged on
Triggers
--------
Trigger: at 8h56am every day-
Details: After triggered, repeat every 5 minutes indefinitely
Status: Enabled
Actions
-------
Action: Start a program
Details: Path to the script
Run Code Online (Sandbox Code Playgroud)
提前致谢!
POWERSHELL(不包括连接):
function ping_getUser{
#ping each computer if online, obtain information about the local hard drives only
TRY{
foreach($workstation in $workstation_list){
$command = $connection.CreateCommand();
$command.Connection = $connection;
$command.CommandText = "INSERT INTO workstation_userlogged
(username,hostname,online)
VALUES (@username,@hostname,@status)";
### =============================================================
### …Run Code Online (Sandbox Code Playgroud) 我有一个良好的运行PowerShell环境,可以从我的配置文件中预加载几个设置,功能和模块C:\Users\Paebbels\Documents\WindowsPowerShell\Microsoft. PowerShell_profile.ps1.
是否可以将相同的配置文件加载到PowerShell的ISE的集成PowerShell控制台中?
我只是问社区他们是否遇到过让脚本在执行脚本之前检查正在运行的 POSH 版本的方法。目前,我的解决方法是以下代码:
#region Final Checks
#//Check to make sure that version of PowerShell is at least 3.0 before preceding.
If($PSVersionTable.PSVersion.Major -le 2) {
Throw "This script has not been tested with version 2.0 or older of PowerShell. Please execute this script from a system that has PowerShell 3.0 or newer installed. Windows 8/Server 2012 and newer has it installed by default. Windows 7/Server 2008 R2 can be patched to have 3.0 installed."
}
#endregion Final Checks
Run Code Online (Sandbox Code Playgroud)
在定义我的参数后,我有这个权利。但是,为了我自己的疯狂,我希望脚本在进入脚本的肉和土豆之前自动执行此检查。一个很好的比较是使用 Validate[X] 作为参数。如果操作员尝试提供不适合我的用户的数据,则会在执行脚本之前引发错误。有任何想法吗?我知道 …
根据微软的说法,我们不能在它自己的 powershell ISE 控制台中运行像 python 这样的交互式控制台。根据一些消息来源,它在后台运行。我们可以在前台运行相同的python 解释器吗?
这个问题的扩展......你如何在Powershell ISE中编写多行命令?Backtick不起作用.
我在谈论命令提示符窗口 C:\>
当我在 Windows powershell 或命令模块 (Windows 10) 中输入“python”时,我会进入 python 环境。但是,当我在 Windows Powershell ISE 中尝试相同的操作时,我收到如下错误消息。关于做什么的任何指导?
python : Python 3.9.0 (tags/v3.9.0:9cf6752, Oct 5 2020, 15:34:40) [MSC v.1927 64 bit (AMD64)] on win32
At line:1 char:1
+ python
+ ~~~~~~
+ CategoryInfo : NotSpecified: (Python 3.9.0 (t...MD64)] on win32:String) [], RemoteException
+ FullyQualifiedErrorId : NativeCommandError
Type "help", "copyright", "credits" or "license" for more information.
Run Code Online (Sandbox Code Playgroud)