我可以列出我自己电脑的共享,没有问题:
gwmi Win32_Share
Run Code Online (Sandbox Code Playgroud)
但是当我尝试
gwmi Win32_Share -computer myserver
Run Code Online (Sandbox Code Playgroud)
myserver运行 BusyBox 的 HP MediaVault mv2120在哪里。我得到回复:Get-WmiObject : The RPC server is unavailable. (Exception from HRESULT: 0x800706BA)
有什么办法可以做到这一点吗?
我尝试将我的旧日志文件移动到 yyyy\MM\dd 文件夹结构
Get-ChildItem . -Recurse -Include *.log |
Move-Item -Dest {"D:\Archive\{0:yyyy\\MM\\dd}\{1}" -f $_.LastWriteTime, $_.Name} -Force
Run Code Online (Sandbox Code Playgroud)
但我收到一个未找到路径的错误。
更新
源路径似乎不是问题。看起来使用-ForceonMove-Item不会创建丢失的目标目录。
子问题:如果没有 Get-ChildItem,也可以这样做吗?
我有向事件添加注册的 powershell 脚本,但是当事件跳转时,每次事件跳转时我都会收到以下错误:“没有可用于在此线程中运行脚本的运行空间”我正在使用 PS v2,什么可以我愿意?你能提供一些代码吗?谢谢
我想为我的一个函数禁用 PowerShell 的“通用参数”。我一直在通过编写如下函数来研究 p4.exe(Perforce 命令行实用程序)的一组扩展:
function p4(
[parameter(valuefromremainingarguments=1)]
[string[]]$cmdline)
{
# ...do some fun stuff with $cmdline...
p4.exe $cmdline # for illustration only - actual implementation uses .net objects
}
Run Code Online (Sandbox Code Playgroud)
关键是能够像我通常在命令行上做的那样使用 p4,除了有时会神奇地重新处理一些参数(添加新命令或调用不同的工具或其他什么),并且它总是感觉好像我只是使用普通的 p4 命令行。
这工作得很好,直到我开始使用像“-o”这样的参数。
p4 -p 1666 user -o scobi
Run Code Online (Sandbox Code Playgroud)
在这种情况下,我从 PowerShell 收到错误消息:
p4 : Parameter cannot be processed because the parameter name 'o' is ambiguous. Possible matches include: -OutVariable -OutBuffer.
Run Code Online (Sandbox Code Playgroud)
我找到的唯一方法是引用我的参数:
p4 -p 1666 user '-o' scobi
p4 '-p 1666 user -o scobi'
Run Code Online (Sandbox Code Playgroud)
真恶心,这妨碍了我让这个函数成为 p4.exe 的透明超集的目标。
是否有我可以附加到我的函数的魔术属性,使其告诉外壳“我不支持通用参数”?或者还有其他方法可以解决这个问题吗?
我是 PowerShell 初学者。应该使用$()Write-Host 来评估此功能的原因是什么?
我无法从文档中找到原因。
PS C:\Temp> Write-Host [math]::round($diff.TotalMinutes, 2)
[math]::round 751681,102679735 2
___________________________________________________________________________________________________________
PS C:\Temp> Write-Host $([math]::round($diff.TotalMinutes, 2))
751681,1
Run Code Online (Sandbox Code Playgroud) 我想获得地址簿上 3 个不同人今天和明天的约会。这些人在 Outlook 上共享日历。
如何使用 powershell 获取此信息?我不介意从本地 Outlook 实例获取数据,但更喜欢直接连接到服务器的东西。
我不知道如何转义“<”字符,而且我对“系统找不到指定的文件”错误感到困惑。任何人都可以帮忙吗?
我在 Windows XP 的 powershell 中使用 ack。
问题ack-grep: chars escaping与我的非常相似,但是为该问题提供和接受的解决方案对我不起作用。
PS C:\xampp\htdocs> ack abcd
<works as expected>
PS C:\xampp\htdocs> ack <
The redirection operator '<' is not supported yet.
At line:1 char:5
+ ack < <<<<
PS C:\xampp\htdocs> ack \<
The syntax of the command is incorrect.
PS C:\xampp\htdocs> ack '<'
The syntax of the command is incorrect.
PS C:\xampp\htdocs> ack '\<'
The syntax of the command is incorrect.
PS C:\xampp\htdocs> ack [<]
The system cannot find …Run Code Online (Sandbox Code Playgroud) 我已经开始学习Angular了,但是我注意到Windows中的powershell每当执行如下的angular命令时都会出现错误:
ng new new-app
Run Code Online (Sandbox Code Playgroud)
要么
ng serve
Run Code Online (Sandbox Code Playgroud)
这是我得到的错误:
ng : File C:\Users\< username >\AppData\Roaming\npm\ng.ps1 cannot be loaded because
running scripts is disabled on this system. For more information, see
about_Execution_Policies at https:/go.microsoft.com/fwlink/?LinkID=135170.
At line:1 char:1
+ ng serve
+ ~~
+ CategoryInfo : SecurityError: (:) [], PSSecurityException
+ FullyQualifiedErrorId : UnauthorizedAccess
Run Code Online (Sandbox Code Playgroud)
PS我尝试在cmd中的这些命令,它的工作原理。
有人知道为什么参数$ a上的强制属性会影响参数$ b的类型转换行为吗?在示例中,数组应强制转换为字符串。
function test ([Parameter(Mandatory = $True)] [string] $a, [string] $b) {
$a; $b
}
$b = "a", "b", "c"
test -a "my string" -b $b
Run Code Online (Sandbox Code Playgroud)
执行此代码块时,将产生错误:test:无法处理参数'b'上的参数转换。无法将值转换为类型System.String。在线:1字符:31
如果我从$ a中删除了Mandatory属性,它可以正常工作:
function test ([string] $a, [string] $b) {
$a; $b
}
$b = "a", "b", "c"
test -a "my string" -b $b
Run Code Online (Sandbox Code Playgroud)
预先感谢您的反馈
这个让我有些难过。我通常在Powershell方面感觉很高级,但我根本不了解这一功能的细微差别。
这有效
$LogFiles = Get-ChildItem -Path c:\windows\temp\*.log,c:\temp\*.log,C:\programdata\Microsoft\IntuneManagementExtension\Logs\*.log
Run Code Online (Sandbox Code Playgroud)
但是我想做的(不起作用)是这样的:
$LogsToGather = "c:\windows\temp\*.log,c:\temp\*.log,C:\programdata\Microsoft\IntuneManagementExtension\Logs\*.log"
$LogFiles = Get-ChildItem -Path "$($LogsToGather)" -Recurse
Run Code Online (Sandbox Code Playgroud)
我已经尝试过将VAR设置为数组,也尝试过使用字符串进行许多操作。我能够解决这个问题,但是我对了解哪种数据类型-path具有这种常见的描述并能够动态创建它具有独特的兴趣。
该cmdlet接受逗号描述似乎是一个技巧。是否可以使用某种数组,哈希表等来重新创建它?
有人知道吗
powershell ×10
ack ×1
angular ×1
angular-cli ×1
arrays ×1
casting ×1
escaping ×1
javascript ×1
outlook ×1
smb ×1
string ×1
windows ×1
wmi ×1