基本上我正在编写一个Powershell脚本,如果不存在,将创建一个新的核心,更新schema.xml,重新启动核心并运行数据导入实用程序.
一个解决方案是做一个
solr create -c products
Run Code Online (Sandbox Code Playgroud)
如果它已经存在,那将会抛出错误,但这不是一个优雅的解决方案
我有一些像这样的视频文件:
VideoName_s01e01.mp4季节和剧集是变量.我想在s??和之间添加一个下划线("_")e??.
我一直在使用powershell进行重命名,我有一个起点:
GCI $path -filter '*_s??e??*' -rec | Ren -new { $_.name -replace '_s[0-9][0-9]', '_s[0-9]_[0-9]_' } -passthru
Run Code Online (Sandbox Code Playgroud)
这实际上重命名了我的文件VideoName_s[0-9]_e[0-9].mp4.
基本上,我正在寻找s??e??我不知道如何在替换部分中使它们成为变量的字符.
我认为最好的方法是:
e??s??(我们称之为X)的位置.X-3._到中间的" ".我在Azure中有一个"Web应用程序",我使用Visual Studio部署/发布.Net Web应用程序.(构建 - >发布),它的工作原理.
我希望能够使用Powershell脚本部署/发布我的应用程序.我得到以下脚本来为构建部分工作:
CMD> "c:\Program Files (x86)\MSBuild\14.0\bin\msbuild.exe" WebApplication1.sln
Run Code Online (Sandbox Code Playgroud)
为了使它也部署,我需要添加一些参数:
CMD> "c:\Program Files (x86)\MSBuild\14.0\bin\msbuild.exe" WebApplication1.sln /p:DeployOnBuild=true /p:PublishProfile="C:\Users\jgodse\Documents\Visual Studio 2015\Projects\WebApplication1\WebApplication1\Properties\PublishProfiles\jg-7-web-app-1 - Web Deploy.pubxml" /p:Configuration=Release
Run Code Online (Sandbox Code Playgroud)
我收到一个错误:
Build FAILED.
"c:\Users\jgodse\Documents\Visual Studio 2015\Projects\WebApplication1\WebApplication1.sln" (default target) (1) ->
"c:\Users\jgodse\Documents\Visual Studio 2015\Projects\WebApplication1\WebApplication1\WebApplication1.csproj" (default target) (2) ->
(MSDeployPublish target) ->
C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v14.0\Web\Microsoft.Web.Publishing.targets(4295,5): msdeploy error ERROR_USER_UNAUTHORIZED: Web deployment task failed. (Connected to the remote computer ("jg-7-web-app-1.scm.azurewebsites.net") using the Web Management Service, but could not authorize. Make sure that you are using the correct user name …Run Code Online (Sandbox Code Playgroud) 如何传递具有以下消息的异常?
Invoke-RestMethod:{"Message":"ETag不代表资源的最新状态."}
看到参考,我认为"传递If-Match: "*" header"应该是关键,但不知道如何做到这一点.
注意:更新或删除文件时,将应用ETag行为.您可以传递If-Match:"*"标头以禁用ETag检查.
# Kudu auth information creation
$WebSiteName = Get-AutomationVariable -Name 'WebApps_name'
# Example: "WebApps04"
$username = Get-AutomationVariable -Name 'WebApps_deploy_username'
$password = Get-AutomationVariable -Name 'WebApps_deploy_password'
# Above are set by "Asset - Variable" of in Azure Automation account
$base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $username,$password)))
$userAgent = "powershell/1.0"
# Add-content dummy HTML file
$Filename = "sample1.html"
$a = "<HTML><BODY>Sample HTML Data " + $WebSiteName + "</BODY></HTML>"
$a | add-content …Run Code Online (Sandbox Code Playgroud) PS sss:\> $match.ApplicabilityCondition
<ApplicabilityRule ExpressionLanguage="Custom" Handler="{2DB70103-3DFB-4806-85B0-B27B561284BB}"><UpdateId>3a50171e-f09b-46fd-991c-ffa0c1fabcc6</UpdateId><CISource><Id>{7ABE2526-ED91-47AE-A989-275B4B2924FE}</Id><Version>188</Version></CISource><ProductId>704a0a4a-518f-4d69-9e03-10ba44198bd5</ProductId></ApplicabilityRule>
Run Code Online (Sandbox Code Playgroud)
ApplicabilityCondition是类似XML的对象,作为Get-CMSoftwareUpdate(SCCM相关命令)的一部分返回。这ExpressionLanguage="Custom"对我没有任何意义。有没有一种简单的方法可以引用显示的子属性?最终,我试图得到UpdateID。
我遇到一个简单的脚本问题,我想在远程服务器上运行GCI,问题是,该值与另一个哈希表属性相结合,因此GCI失败.
该脚本从两列.csv中读取条目,标题是"server"和"platform"
这是我得到的:
$ShortDate = (Get-Date).ToString('MM/dd/yyyy')
$CheckServer = @{}
$serverObjects = @() # create a list of server objects
Import-Csv $Dir\Servers.csv | ForEach {
$CheckServer.Server = $_.Server
$CheckServer.Platform = $_.Platform
if (GCI \\$_.Server\c$\log\Completed_Summary_*.html -EA 0 | where {$.LastWriteTime -ge "$ShortDate"}) {
Write-Host "FOUND"
} # end of IF GCI
} # end of For-Each
$serverObjects += New-Object -TypeName PSObject -Property $CheckServer
Run Code Online (Sandbox Code Playgroud)
问题是,条目$_.Server应该是SERVER1,SERVER2,SERVER3等,来自servers.csv中的所有条目,而不是两者的值$_.Server和$_.Platform组合.如:
Write-Host "Checking" \\@{Server=SERVER1; Platform=PLATFORM_1}.Server\c$\log\Completed_Summary_*.html
Run Code Online (Sandbox Code Playgroud)
它应该显示如下:
Write-Host "Checking" \\SERVER1\log\Completed_Summary_*.html
Run Code Online (Sandbox Code Playgroud)
如何取消组合它们以便GCI命令有效?
我试图写一个简单的do..until循环,它不起作用:
$yesNo = Read-Host -Prompt 'Do you want to add alternative DNS names or IPs into Certificate? Y/N: '
do {
$dnsipname = Read-Host -Prompt "Please input DNS or IP as dns=alternativeCNname or ip=ipName: "
Write-Output "$dnsipname"
$strQuit = Read-Host " do you want to add another DNS? (Y/N)"
do {
$dnsipname = Read-Host -Prompt "Please input DNS or IP as dns=alternativeCNname or ip=ipName: "
Write-Output "$dnsipname"
Add-Content D:\Scripts\expiringCerts\request.inf '`r`n_continue_ = "$dnsipname"'
} until ($strQuit -eq "Y" -or …Run Code Online (Sandbox Code Playgroud) 在Powershell中,我有一个哈希表,其中包含与此类似的数据 -
Name Value
---- -----
1-update.bat 1
2-update.bat 2
3-update.bat 3
3.1-update.bat 3.1
4-update.bat 4
Run Code Online (Sandbox Code Playgroud)
例如,我还有一个包含数字的变量 3
我想要做的是遍历数组并删除值小于或等于的任何条目 3
我认为这很容易,特别是当文档说有表包含.remove方法时.但是,我下面的代码失败了,这是错误的 -
用"1"参数调用"删除"的异常:"集合是固定大小的."
这是我使用的代码 -
$versions = @{}
$updateFiles | ForEach-Object {
$versions.Add($_.name, [decimal]($_.name -split '-')[0])
}
[decimal]$lastUpdate = Get-Content $directory\$updatesFile
$versions | ForEach-Object {
if ( $_.Value -le $lastUpdate ) {
$versions.Remove($version.Name)
}
}
Run Code Online (Sandbox Code Playgroud)
我首先尝试以$versions不同的方式循环,同时尝试foreach和for方法,但两者都以相同的方式失败.
我还尝试创建一个临时数组来保存要删除的版本的名称,然后循环该数组以删除它们,但这也失败了.
接下来我点击谷歌,虽然我可以找到几个类似的问题,但没有一个能回答我的具体问题.大多数情况下,他们建议使用一个列表(New-Object System.Collections.Generic.List[System.Object]),我可以告诉我这里没有任何帮助.
有人能提出修复建议吗?
我正在尝试创建一个简单的TFS vNext任务,使用Powershell执行Powershell脚本.
我可以加载任务,但在我使用任务触发发布后,我得到了
##[error]System.Management.Automation.ParameterBindingException: A parameter cannot be found that matches parameter name 'PoolName'.
Run Code Online (Sandbox Code Playgroud)
我的task.json如下.
{
"id": "7fe28fb2-c323-4494-beb6-b5c5939b09e7",
"name": "ManageIIS",
"friendlyName": "ManageIIS",
"description": "ManageIIS",
"helpMarkDown": "ManageIIS",
"category": "Utility",
"visibility": [
"Build"
],
"author": "Baskar Lingam",
"version": {
"Major": 1,
"Minor": 0,
"Patch": 3
},
"demands": [],
"minimumAgentVersion": "1.83.0",
"groups": [
{
"name": "advanced",
"displayName": "Advanced",
"isExpanded": false
}
],
"instanceNameFormat": "ManageIIS",
"inputs": [
{
"name": "PoolName",
"type": "string",
"label": "Application Pool Name",
"required": true,
"defaultValue": "AppPoolName"
},
{
"name": "AppPoolAction", …Run Code Online (Sandbox Code Playgroud) powershell tfs tfsbuild azure-pipelines-build-task azure-pipelines
我使用了几个变量,但是通常我使用从Get-ChildItemcmdlet 返回的对象来查找文件并使用经过更改的if语句。
但是,如何在目录中找到特定文件,如果找到该文件,则将其删除?这是我编写的代码:
$VM_NAME="Test"
$search=Get-ChildItem -Path B:\Virtualservers\Disks\Users\* -include $VM_NAME.vhdx -filter *.vhdx -Recurse
if ($search.Name -contains "$VM_NAME.vhdx") {remove-item ??? }
else {write-host "Continue.."}
Run Code Online (Sandbox Code Playgroud)