小编Tim*_*ham的帖子

Powershell强制性布尔总是如此

我有一个脚本,其中包含以下设置,如果我使用强制参数屏幕,则会返回不正确的结果.感觉它没有在我的输入上进行某种类型验证或投射.我该如何解决?

param ( [Parameter(Mandatory=$true)] [bool]$autoinstall )

if ( $autoinstall  ) 
{
    echo "Autoinstall true"
}
else
{
    echo "Autoinstall false"
}
Run Code Online (Sandbox Code Playgroud)

如果我使用.\ myscript.ps1 -autoinstall $ false调用它,这非常有效,但是如果我使用强制密码提示并输入'$ false',则无论我通过什么,$ autoinstall变量始终为true.

编辑:

使用开关对我不起作用.我真的需要这个可编写脚本和强制参数函数用于即时使用的用户快捷方式.

parameters powershell casting

8
推荐指数
2
解决办法
2万
查看次数

为Atom提要创建XSL

我正在创建一个小的自定义XSL文件来呈现RSS提要.内容基本如下.这种方式完美无缺,除非源XML在Feed定义中包含'xmlns ="http://www.w3.org/2005/Atom"'行.我该如何解决这个问题?我对命名空间不够熟悉,不知道如何解释这种情况.

<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" >
<xsl:template match="/" >
<html xsl:version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns="http://www.w3.org/1999/xhtml">
  <body style="font-family:Arial;font-size:12pt;background-color:#EEEEEE">
  <xsl:for-each select="feed/entry">
      <div style="background-color:teal;color:white;padding:4px">
        <span style="font-weight:bold"><xsl:value-of select="title"/></span> - <xsl:value-of select="author"/>
      </div>
      <div style="margin-left:20px;margin-bottom:1em;font-size:10pt">
        <b><xsl:value-of select="published" /> </b>
        <xsl:value-of select="summary"  disable-output-escaping="yes" />
      </div>
    </xsl:for-each>
  </body>
</html>
</xsl:template>
</xsl:stylesheet>
Run Code Online (Sandbox Code Playgroud)

xml xslt

7
推荐指数
1
解决办法
3855
查看次数

Powershell关闭VM

我有一个小的Powershell脚本,用于在发生长时间断电时关闭我的虚拟机.它需要一个特定的VM对象并强制关闭.

Function DirtyShutdown
{ param([VMware.VimAutomation.ViCore.Impl.V1.Inventory.VirtualMachineImpl]$VM )
$VM | Stop-VM -Confirm:$false
}
Run Code Online (Sandbox Code Playgroud)

我想使用start-job命令加速此过程并行运行所有这些任务.我尝试过使用以下几种变体,我认为这些变体是正确的.

Start-Job -InputObject $VM -ScriptBlock{ $input | Shutdown-VMGuest -Confirm:$false }
Run Code Online (Sandbox Code Playgroud)

基于Receive-Job输出,看起来问题是在Start-Job的上下文中没有加载正在使用的管理单元(在调用上述函数之前添加).

实现这一目标的正确语法是什么?

powershell vmware powershell-2.0 powercli

3
推荐指数
1
解决办法
4530
查看次数

Perl oneliner匹配重复自身

我正在尝试用Perl读取文件中某一行的特定部分.有问题的文件具有以下语法.

# Sets $USER1$ 
$USER1$=/usr/....
# Sets $USER2$ 
#$USER2$=/usr/...
Run Code Online (Sandbox Code Playgroud)

我的oneliner很简单,

perl -ne 'm/^\$USER1\$\s*=\s*(\S*?)\s*$/m; print "$1";' /my/file
Run Code Online (Sandbox Code Playgroud)

由于某些原因,我得到了1美元的提取重复几次,显然是在匹配发生后文件中的每一行.我在这里错过了什么?

perl pcre

0
推荐指数
1
解决办法
347
查看次数

标签 统计

powershell ×2

casting ×1

parameters ×1

pcre ×1

perl ×1

powercli ×1

powershell-2.0 ×1

vmware ×1

xml ×1

xslt ×1