我正试图找到一种方法来计算我所拥有的项目的所有源文件中的总行数.我已经尝试过管道dir -r -name输入measure-object -line,但这只计算了我拥有的文件数量.
有没有人有脚本来做这个?
如果我有一个可执行文件out.exe,它stdout被重定向到一个文件,即:
out.exe > $file
现在,如果我这样做,它只输出:
<----------------------------->
80 columns per line to the file
Run Code Online (Sandbox Code Playgroud)
有没有办法让控制台列数中的标准输出更宽?这是在out.exe某种程度上混乱列?就我而言,我正在使用fxcopcmd.exe.
我正在编写一个返回id,name对的函数.
我想做点什么
$a = get-name-id-pair()
$a.Id
$a.Name
Run Code Online (Sandbox Code Playgroud)
喜欢在javascript中可能.或至少
$a = get-name-id-pair()
$a["id"]
$a["name"]
Run Code Online (Sandbox Code Playgroud)
喜欢在PHP中可能.我可以用PowerShell做到吗?
已经有问题解决我的问题(我可以让&&在Powershell中工作吗?),但有一点不同.我需要两个命令的OUTPUT.看,如果我只是运行:
(command1 -arg1 -arg2) -and (command2 -arg1)
Run Code Online (Sandbox Code Playgroud)
我不会看到任何输出,而是stderr消息.正如所料,只需输入:
command1 -arg1 -arg2 -and command2 -arg1
Run Code Online (Sandbox Code Playgroud)
给出语法错误.
是否可以从PowerShell脚本创建可执行的.exe文件?
我正在使用Powershell编写构建脚本.这些脚本执行各种操作,例如从SVN获取最新的源代码,备份等,并使用MSBuild构建解决方案:
cmd /c C:\WINDOWS\Microsoft.NET\Framework\v3.5\msbuild.exe "C:\Dev\Path\MyProjct.sln" /p:Configuration=Release
Run Code Online (Sandbox Code Playgroud)
在这条指令之后,如果编译成功,我只想执行其余的脚本.我怎么检查这个?
该项目是一个Web项目,因此检查输出并不容易,但我猜一些变量将包含编译结果.此外,因为我用cmd/c调用msbuild,我能够访问这些变量吗?
通常,如果要将switch参数的规范推迟到某个变量,可以将表达式传递给switch参数,如WhatIf参数所示.
test.ps1
param ( [string] $source, [string] $dest, [switch] $test )
Copy-Item -Path $source -Destination $dest -WhatIf:$test
Run Code Online (Sandbox Code Playgroud)
这使您在使用交换机时具有很大的灵活性.但是,当您使用cmd.exe或其他东西调用powershell时,最终会出现以下情况:
D:\test>powershell -file test.ps1 -source test.ps1 -dest test.copy.ps1 -test:$true
D:\test\test.ps1 : Cannot process argument transformation on
parameter 'test'. Cannot convert value "System.String" to type "System.Manageme
nt.Automation.SwitchParameter", parameters of this type only accept booleans or
numbers, use $true, $false, 1 or 0 instead.
At line:0 char:1
+ <<<<
+ CategoryInfo : InvalidData: (:) [test.ps1], ParentContainsError
RecordException
+ FullyQualifiedErrorId : ParameterArgumentTransformationError,test.ps1
Run Code Online (Sandbox Code Playgroud)
但是,通过时会出现相同的结果-test:true,并且-test:1 …
将哈希表传递给我的PowerShell函数时,它会抱怨它收到一个对象.
Function ExtendHash(){
param(
[hashtable] $source,
[hashtable] $extender
)
...
}
Run Code Online (Sandbox Code Playgroud)
和来电者:
$hash1 = @{One = 1; Two = 2}
$hash2 = @{Two = 22; three = 3}
ExtendHash($hash1, $hash2)
Run Code Online (Sandbox Code Playgroud)
无法将System.Object []类型的System.Object []值转换为System.Collection.Hashtable类型
那我该怎么做呢?建议?
另外,我错过了内置的东西吗?我想要与JavaScript用于扩展默认选项(合并和覆盖默认值)相同的模式.
我的目录结构如下所示:
C:\TFS\MasterScript\Script1.ps1
C:\TFS\ChildScript\Script2.ps1
Run Code Online (Sandbox Code Playgroud)
我想要做的是指定Script2.ps1中的相对路径,以在目录hirearchy中查找Script1.ps1.
这是我在Script2.ps1中尝试过的:
Import-Module ../MasterScript/Script1.ps1
Run Code Online (Sandbox Code Playgroud)
但它不起作用,并说它找不到模块.
如果我说Import-Module C:\TFS\MasterScript\Script1.ps1,它工作正常.我在这里失踪了什么?
我正在寻找一种从命令提示符运行几个PowerShell命令的方法.我不想为此创建脚本,因为它只需要运行几个命令,因为我真的不知道如何使用PowerShell编写脚本.
这是我试图用来开始的命令:
Get-AppLockerFileInformation -Directory <folderpath> -Recurse -FileType <type>
Run Code Online (Sandbox Code Playgroud)
我真的不想为此创建一个脚本,因为如果我可以从批处理文件中运行一个或两个命令与其余的东西会更容易.
编辑:这是我到目前为止所尝试的.
1)
powershell -Command "Get-AppLockerFileInformation....."
Error: The term 'Get-AppLockerFileInformation is not recognized as the name of a cmdlet, function, script file, or operable program....
Run Code Online (Sandbox Code Playgroud)
2)
powershell -Command {Get-AppLockerFileInformation.....}
Run Code Online (Sandbox Code Playgroud)
这种方式没有错误,但我没有得到任何回报.如果我使用Set-AppLockerPolicy...没有任何反应.
3)
powershell -Command "{Get-AppLockerFileInformation.....}"
Error: The term 'Get-AppLockerFileInformation is not recognized as the name of a cmdlet, function, script file, or operable program....
Run Code Online (Sandbox Code Playgroud)
4)
powershell -Command "& {Get-AppLockerFileInformation.....}"
Error: The term 'Get-AppLockerFileInformation is not recognized as the name of a …Run Code Online (Sandbox Code Playgroud) powershell ×10
cmd ×2
arrays ×1
batch-file ×1
console ×1
executable ×1
hashtable ×1
msbuild ×1
parameters ×1
syntax ×1