我有一个 powershell 脚本,可以关闭 MS Word 中打开的文件名与模式匹配的所有 MS Word 实例。有时会调用 Powershell 脚本,但没有运行 MS Word 实例。cmdlet Get-Process 用于查找 MS Word 并检查当前打开的文件的名称。
无论是 [NoProcessFoundForGivenName,Microsoft.PowerShell.Commands.GetProcessCommand] 还是
[Microsoft.PowerShell.Commands.GetProcessCommand] 都被捕获。
{
$MSWordProcessHandle = Get-Process WINWORD
} catch [NoProcessFoundForGivenName,Microsoft.PowerShell.Commands.GetProcessCommand] {
Write-Output "No instances of MS Word found running."
}
Run Code Online (Sandbox Code Playgroud)
我不断收到下面的错误。
Run Code Online (Sandbox Code Playgroud)Get-Process : Cannot find a process with the name "WINWORD". Verify the process name and call the cmdlet again. At C:\Utils\scripts\Dev_Set_Close.ps1:24 char:27 + $MSWordProcessHandle = Get-Process WINWORD + ~~~~~~~~~~~~~~~~~~~ + CategoryInfo : ObjectNotFound: (WINWORD:String) [Get-Process], ProcessCommandException + …
我正在使用 robocopy 编写一个 powershell 脚本,以从列表中复制“完整”unc/文件名路径。我遇到的问题是 robocopy 似乎\
在我的源路径末尾添加了 a 。
我有一个 C:\temp\list.txt,其中列出了带有文件名的 UNC 路径示例:\server\folder\test.txt
我的代码
$Paths = Get-Content -Path C:\Temp\List.txt
ForEach ($p in $Paths) {robocopy $p "\\Server\path\path\"}
The error that powershell is throwing is :
-------------------------------------------------------------------------------
ROBOCOPY :: Robust File Copy for Windows
-------------------------------------------------------------------------------
Started : Monday, March 1, 2021 1:36:52 PM
Source : \\Server\path\path\test.xls\
Dest : \\Server\path\path\
Files : *.*
Options : *.* /DCOPY:DA /COPY:DAT /R:1000000 /W:30
------------------------------------------------------------------------------
2021/03/01 13:36:52 ERROR 267 (0x0000010B) Accessing Source Directory
\\Server\path\path\test.xls\
The …
Run Code Online (Sandbox Code Playgroud) 我有一个需要操作的文本文件。文本文件中的示例数据如下所示:
C02324R
C02645R
F06487R
F05564R
S09687R
J03345R
Run Code Online (Sandbox Code Playgroud)
这是需要发生的事情——
因此,最终结果数据将如下所示——
C02324R3
C02645R3
F06487R5
F05564R5
S09687R5
J03345R6
Run Code Online (Sandbox Code Playgroud)
我可以轻松地在 vba excel 中编写此内容,但我对 powershell 缺乏经验。我尝试过 switch、foreach 和 case 语句,大部分来自借用的代码,但似乎无法使其工作。这是我尝试过的一种方法——
switch -file 'C:\MyFile.txt'
{
$_.StartsWith("C") {$_ + "3"}
$_.StartsWith("S0") {$_+ "4"}
$_.StartsWith("S1") {$_ + "5"}
$_.StartsWith("J") {$_ + "6"}
}
$data | Set-Content C:\MyFile.txt -Force*
Run Code Online (Sandbox Code Playgroud)
建议?
我有一个很长的十六进制值字符串,可以转换为base64。
我正在寻找一个简单的格式单元格函数,例如=Hex2b64(Hexstring)
可以接受任何长度的十六进制字符。
我一直在使用http://home.paulschou.net/tools/xlate/手动进行转换。转换工作正常,所有相关数据库均接收到数据并进行了适当的解析。
我接收的数据是十六进制表示的二进制文件,已根据我不了解的项目文档将其转换为多个块,并连接成较长的十六进制字符串。
典型的输入字符串为:
Hex= 00014088F6650101393939393939392D30304646463238313030000343332353430342D35353FA10000002805900100002805
Run Code Online (Sandbox Code Playgroud)
相应的输出将是:
B64 = AAFAiPZlAQE5OTk5OTk5LTAwRkZGMjgxMDAAA0MzI1NDA0LTU1P6EAAAAoBZABAAAoAF
Run Code Online (Sandbox Code Playgroud) 我想弄清楚fabric.js 中的单位lineHeight
和charSpacing
属性以及如何计算它们。
在文档中,找不到我的答案,或者我不明白它的确切工作方式。
lineHeight :
http://fabricjs.com/docs/fabric.Text.html#lineHeight
charSpacing:
http://fabricjs.com/docs/fabric.Text.html#charSpacing
我正在尝试将日志导出到 powershell 中的 csv 文件,但我很难为文件中的每个“日志”放置时间戳。我可以将日志导出到 csv 文件中,但对于它记录的每个操作,我想要一个单独的时间戳。例如,我希望 csv 文件中的输出如下所示,并且每个输出都有一个时间戳(请注意操作之前的时间戳)
2020/02/13 93520 - Performing the operation "Remove File" on target "\\03042019-PC\C$\Users\*\AppData\Local\Apps\Test\21.txt".
2020/02/13 93522 - Performing the operation "Remove File" on target "\\03052019-PC\C$\Users\*\AppData\Local\Apps\Test\51.txt".
Run Code Online (Sandbox Code Playgroud)
任何帮助,将不胜感激!这是我到目前为止所得到的:(来自在线研究)
Import-Module ActiveDirectory
$timestamp = "LogFile"
$filepath = "C:\$timestamp.csv"
#$Computers = Get-ADComputer -Filter {Name -like "*-PC"} | Select-Object -ExpandProperty Name
$Computers = Get-ADComputer -Filter {Name -like "03*2019-PC"} | Select-Object -ExpandProperty Name
# Loop through users and delete the file
ForEach ($Computer in $Computers) {
$path = "\\$Computer\C$\Users\*\AppData\Local\Apps\Test\*"
$result = …
Run Code Online (Sandbox Code Playgroud)