我想使用PowerShell自动化FTP下载数据库备份文件.文件名包含日期,因此我不能每天运行相同的FTP脚本.是否有一种干净的方法来构建PowerShell或使用.Net框架?
更新我忘了提到这是一个通过安全的FTP会话.
是否可以使用命名参数从PowerShell调用COM方法?我正在使用的COM对象方法有许多参数:
object.GridData( DataFile, xCol, yCol, zCol, ExclusionFilter, DupMethod, xDupTol,
yDupTol, NumCols, NumRows, xMin, xMax, yMin, yMax, Algorithm, ShowReport,
SearchEnable, SearchNumSectors, SearchRad1, SearchRad2, SearchAngle,
SearchMinData, SearchDataPerSect, SearchMaxEmpty, FaultFileName, BreakFileName,
AnisotropyRatio, AnisotropyAngle, IDPower, IDSmoothing, KrigType, KrigDriftType,
KrigStdDevGrid, KrigVariogram, MCMaxResidual, MCMaxIterations, MCInternalTension,
MCBoundaryTension, MCRelaxationFactor, ShepSmoothFactor, ShepQuadraticNeighbors,
ShepWeightingNeighbors, ShepRange1, ShepRange2, RegrMaxXOrder, RegrMaxYOrder,
RegrMaxTotalOrder, RBBasisType, RBRSquared, OutGrid, OutFmt, SearchMaxData,
KrigStdDevFormat, DataMetric, LocalPolyOrder, LocalPolyPower, TriangleFileName )
Run Code Online (Sandbox Code Playgroud)
这些参数中的大多数是可选的,其中一些是互斥的.在使用win32com模块的Visual Basic或Python中,您可以使用命名参数来仅指定所需选项的子集.例如(在Python中):
Surfer.GridData(DataFile=InFile,
xCol=Options.xCol,
yCol=Options.yCol,
zCol=Options.zCol,
DupMethod=win32com.client.constants.srfDupMedZ,
xDupTol=Options.GridSpacing,
yDupTol=Options.GridSpacing,
NumCols=NumCols,
NumRows=NumRows,
xMin=xMin,
xMax=xMax,
yMin=yMin,
yMax=yMax,
Algorithm=win32com.client.constants.srfMovingAverage,
ShowReport=False,
SearchEnable=True,
SearchRad1=Options.SearchRadius,
SearchRad2=Options.SearchRadius, …Run Code Online (Sandbox Code Playgroud) PowerShell相当于'less'是什么?
我看到'更多',但它缺乏我依赖的一些功能(例如搜索文件)
我寻找一个寻呼机(相当于'少'),它允许一次搜索(匹配或忽略大小写),多个文件等.
我们的一些服务器运行Windows 2008,我缺乏安装cygwin的管理员权限
我听过Windows 2008,MSFT一起行动并提供了一些易于管理的工具.
更新:
我应该给出一些背景信息:
谢谢
这很奇怪.通常当我从powershell执行外部命令时,我使用这样的&运算符:
& somecommand.exe -p somearguments
Run Code Online (Sandbox Code Playgroud)
但是,今天我遇到了这样.使用的运算符:
.$env:systemdrive\chocolatey\chocolateyinstall\chocolatey.cmd install notepadplusplus
Run Code Online (Sandbox Code Playgroud)
在这种情况下,这个时期的目的是什么?我不明白.
我一直在使用Powershell Scheduled Task Cmdlet在我们的服务器上创建计划任务.
如何使用此API选择"运行用户是否登录"?
我创建action,trigger,principal和settings对象,并将它们传递到Register-ScheduledTask,如下图所示:
$action = New-ScheduledTaskAction -Execute foo.exe -Argument "bar baz"
$trigger = New-ScheduledTaskTrigger -Once -At $startTime -RepetitionInterval (New-TimeSpan -Minutes 1) -RepetitionDuration ([Timespan]::MaxValue)
$principal = New-ScheduledTaskPrincipal -UserId "$($env:USERDOMAIN)\$($env:USERNAME)" -LogonType ServiceAccount
$settings = New-ScheduledTaskSettingsSet -MultipleInstances Parallel
Register-ScheduledTask -TaskName $taskName -TaskPath "\my\path" -Action $action -Trigger $trigger -Settings $settings -Principal $principal
Run Code Online (Sandbox Code Playgroud)
当我创建这样的计划任务时,它默认为"仅在用户登录时运行".
这个问题显示了如何使用COM对象,这个使用schtasks.exe,但我如何使用*-ScheduledTask*cmdlet?
powershell scheduled-tasks powershell-3.0 windows-server-2012
假设我有一个file.properties,其内容是:
app.name=Test App
app.version=1.2
...
Run Code Online (Sandbox Code Playgroud)
我怎样才能获得app.name的值?
我有错误:
“error: Sparse checkout leaves no entry on the working directory”
Run Code Online (Sandbox Code Playgroud)
当试图在Windows上的git中设置稀疏结账时.在研究了这个问题并找到了完整的答案后,我已经回答了我自己的问题.
有什么区别ForEach和ForEach-Object?
我有一个像这样的小代码,工作正常
$txt = Get-Content 'C:\temp\000.txt'
$result = foreach ($line in $txt) {$line.replace(".ini","")}
$result | out-file 'c:\temp\001.txt'
Run Code Online (Sandbox Code Playgroud)
但如果我使用'ForEach-Object',我就会出错......
$txt = Get-Content 'C:\temp\000.txt'
$result = foreach-object ($line in $txt) {$line.replace(".ini","")}
$result | out-file 'c:\temp\001.txt'
Run Code Online (Sandbox Code Playgroud)
为什么?以及如何使用输出循环结果ForEach-Object
我正在尝试编写PowerShell脚本,以便在通过sccm安装后删除Chrome的桌面图标.但是,网络中的某些用户将其桌面定向到网络上的不同文件夹.PowerShell中是否存在存储桌面位置的变量?
我已经在网上搜索并使用了搜索Get-Variable | Out-String,但我没有找到任何东西.完成的代码应如下所示:
If (Test-Path "$DesktopLocation\Google Chrome.lnk"){
Remove-Item "$DesltopLocation\Google Chrome.lnk"
}
Run Code Online (Sandbox Code Playgroud) 我有一个类型FooObject,我有一个从FooObject实例序列化的JSON文件.现在我想用来ConvertFrom-Json将JSON文件加载到内存并将命令的输出转换为FooObject对象,然后在cmdlet中使用新对象,该cmdlet Set-Bar仅接受FooObject作为参数类型.
但我注意到输出类型ConvertFrom-Json是PSCustomObject和我没有找到任何转换PSCustomObject方式FooObject.