I'm trying to write a few lines of code in powershell, to check if a file arrived to a specific folder. If the file is there, copy it to another folder. No action required if the file is not there. So far I have only the copying part:
cd C:\
Move /y "C:\myfolder\*.csv" "C:\MyDestinationFolder"
Run Code Online (Sandbox Code Playgroud)
I can't find a simple code to check if the file is present.
我正在尝试使用 Powershell 脚本在 Windows 10 中切换语言、区域和语音。脚本结束后,用户将被注销,必须重新登录。所以一切都应该改变。
但地区和言论目前没有改变。有谁知道我在脚本中缺少什么?
Set-Culture en-US
Set-WinSystemLocale -SystemLocale en-US
Set-WinUILanguageOverride -Language en-US
Set-WinUserLanguageList en-US -Force
logoff;exit
Run Code Online (Sandbox Code Playgroud)
我希望用户只需启动 poweshell 脚本,这样他就可以使用 Cortana 进行不同的演讲。
如果有人可以帮助我或提供进一步的提示,我将非常高兴。
问候基督徒
最近在一些 Windows 10 机器上,我注意到
Get-Service | Export-Csv "C:\users\[xxx]"创建了一个 .csv 文件,如果在 Excel 中打开该文件,则只显示 A 列中的所有属性。我习惯于看到每个属性都输出到单独的列。
两台机器上的 Windows 和 Office 版本是相同的。Windows:1709(内部版本 16299.431)办公室:1802(内部版本 9029.2253 CTR)
Excel-Online 还将输出显示在一列中。
右键单击每台机器上的 .csv 文件会显示不同的文件类型:“CSV-File (.csv)”显示多列,而“Microsoft Excel-CSV-File(.csv)”显示一列。
此外,文件图标不同。
有没有人经历过这种情况并知道为什么会这样?
我很困惑哪个是正确的行为。
感谢您的输入。
我想知道在C#使用Pipeline类和PowerShell类时执行 PowerShell 脚本之间的区别。
使用管道:
Pipeline pipe = runspace.CreatePipeline();
Run Code Online (Sandbox Code Playgroud)
使用 PowerShell 类:
PowerShell ps = PowerShell.Create();
Run Code Online (Sandbox Code Playgroud)
我们可以同时使用它们在 C# 中执行 PowerShell 脚本,但是它们之间有什么区别呢?
我正在尝试编写一个执行以下操作的 PowerShell 脚本:
是否可以在不下载的情况下获取在线文件的文件大小?我尝试使用 .length 但它没有用。(我是 PowerShell 的新手)
PS脚本:
$localpath = "C:\Users\USERNAME\Desktop\test.csv"
If(Test-Path -Path $localpath)
{
#Exist, check for an updated version
$localFileSize = (Get-Item $localpath).length
$onlineFileSize = (Get-Item 'test.com/test.txt').length
if($onlineFileSize -gt $localFileSize)
{
$url = "test.com/test.txt"
$downloadFile = "C:\Users\USERNAME\Desktop\test.csv"
(New-Object System.Net.WebClient).DownloadFile($url, $downloadFile)
}
} else
{
#Does not exist, download the file
$url = "test.com/test.txt"
$downloadFile = "C:\Users\USERNAME\Desktop\test.csv"
(New-Object System.Net.WebClient).DownloadFile($url, $downloadFile)
}
Run Code Online (Sandbox Code Playgroud) 我想从我的 PowerShell 脚本的 Process 和 End 块中调用一个特定的函数。这是最小的代码:
# MyScript.ps1
function MyFunc
{
"hello"
}
Begin
{
}
Process
{
MyFunc
}
End
{
MyFunc
}
Run Code Online (Sandbox Code Playgroud)
但是,此代码不会执行。我收到此错误:
开始:术语“开始”不是 cmdlet、函数、脚本文件或可运行程序的名称。
我正在编写一个脚本,它有几个函数需要时间在不同的远程计算机上执行。有什么办法可以同时以并行方式调用-命令它们吗?一个例子将不胜感激。谢谢
对于以后的 powershell 版本,我可以毫无问题地使用以下内容:
$contents = Get-Content $path -raw
if ($contents -match $regex) {
$result = $matches[0]
}
Run Code Online (Sandbox Code Playgroud)
但是在 powershell 版本 2 中,Get-Content 没有 -raw 开关,但是如果没有 -raw 开关,正则表达式匹配步骤总是失败;$matches 似乎是 $null。
我不确定这个“原始”参数的内部工作原理,因为微软在各自的文档页面上提供了一个相当可悲的描述,所以我不确定如何解决它。
我在 Powershell 中使用以下脚本(版本为 5.1):
Get-Content -Path path\to\text\file\to\be\read.txt -Wait
Run Code Online (Sandbox Code Playgroud)
现在,即使文件没有更新,它也会继续读取。在文本文件中找到特定行后如何停止?有没有其他方法可以阻止这种情况?
突然间我收到错误
“2018-08-30T06:19:30.8460321Z ##[错误]术语“powershell.exe”不是cmdlet、函数、脚本文件或可运行程序的名称。检查名称的拼写,或如果包含路径,请验证路径是否正确并重试。”同时在 VSTS 中执行 PS 任务。
我的 PS 任务有简单的 Write-Host $variable 语句,它一直工作到今天,出了点问题,尝试重新启动目标机器,确保 PS 可用等。
请问有什么调试步骤吗?
powershell ×10
azure-devops ×1
break ×1
c# ×1
cortana ×1
csv ×1
excel ×1
pipeline ×1
runspace ×1
windows-10 ×1