使用 SPE(Sitecore Powershell 扩展)我需要一个项目的通用链接类型字段“Url”属性,但在转换类型时遇到了问题。
我试图将 Item 属性转换为这样的Linkfield对象:
[Sitecore.Data.Fields.LinkField]$field = $myolditem["Email"]
Run Code Online (Sandbox Code Playgroud)
输出:
将字符串转换为 Linkfield 时出错
如何Linkfield使用 SPE将字段的字符串值转换为类型?
我需要在一组远程服务器上配置审计策略。我正在尝试使用 Invoke-Command commandlet 在每台服务器上运行 auditpol.exe。问题是我似乎无法从 auditpol 命令中捕获任何输出。
我尝试了显而易见的(将 Invoke-Command 的结果分配给一个字符串):
> $command = "Start-Process -FilePath `"auditpol.exe`" -ArgumentList `"/set`", `"/subcategory`", `"```"File System```"`", `"/success:enable`""
> $command
"auditpol.exe" -ArgumentList "/set", "/subcategory", "`"File System`"", "/success:enable"
> $out = Invoke-Command -ComputerName MyServer -ScriptBlock {$command}
> $out
>
Run Code Online (Sandbox Code Playgroud)
但是 $out 是空的。
我还使用 Wait-Job 和 Receive-Job尝试了此 MSDN 博客中详述的方法。结果有些令人鼓舞,但尚无定论:
> $command = "Start-Process -FilePath `"auditpol.exe`" -ArgumentList `"/set`", `"/subcategory`", `"```"File System```"`", `"/success:enable`""
> $command
"auditpol.exe" -ArgumentList "/set", "/subcategory", "`"File System`"", "/success:enable"
> $job = Invoke-Command -ComputerName MyServer …Run Code Online (Sandbox Code Playgroud) 我想更新 teamcity checkout 目录中的所有 assemblyinfo.cs。从 AssemblyInfo.cs 中引用了这篇文章Get and Replace AssemblyVersion。看起来缺少某些逻辑并且文件没有得到更新。它应该将行 [assembly: AssemblyVersion("1.4.0.0")] 更新为 [assembly: AssemblyVersion("1.4.0.%build.counter%")]
$BuildCounter = "%build.counter%"
$pattern = '\[assembly: AssemblyVersion\("(.*)"\)\]'enter code here
Get-ChildItem -r -filter AssemblyInfo.cs | foreach-object { $name = $_.FullName}
{
(get-content $name ) | ForEach-Object{
if($_ -match $pattern){
# We have found the matching line
# Edit the version number and put back.
$fileVersion = [version]$matches[1]
$newVersion = "{0}.{1}.{2}.{3}" -f $fileVersion.Major, $fileVersion.Minor, $fileVersion.Build, $BuildCounter
'[assembly: AssemblyVersion("{0}")]' -f $newVersion
} else { …Run Code Online (Sandbox Code Playgroud) powershell 中的以下代码将插入到 SQL Server 表中,例如
aaaaa | 呜呜呜呜
在一排,但我想要
| 乙 一个| bb 啊| bbb
在 3 个单独的行上。
$Connection = New-Object System.Data.SQLClient.SQLConnection
$Connection.ConnectionString =
"server='$Server';database='$Database';trusted_connection=true;"
$Connection.Open()
$stringA = 'a', 'aa', 'aaa'
$stirngB = 'b', 'bb', 'bbb'
for ($i = 0; $i -lt 3; $i++) {
$sql = "INSERT INTO [dbo].[Server] (ServerName, UniqueID)
VALUES ('$stringA[$i]','$stringB[$i]')"
$Command.CommandText = $sql
$Command.ExecuteReader()
}
$Connection.Close()
Run Code Online (Sandbox Code Playgroud)
如何操作我的代码以插入 3 个单独的行而不是 1 行?
我有很多时间试图理解为什么这个脚本没有按预期工作。这是一个简单的脚本,我试图在其中导入 CSV,选择我想要的几列,然后导出 CSV 并复制自身。(基本上我们已经归档了数据,由于内存大小限制,我只需要从另一个项目中提取几列数据)。这个脚本非常简单,它显然与它不起作用时造成的挫败感成反比关系......现在最终结果是我最终得到一个空的 csv 而不是一个只包含我选择的列的 csv与选择对象。
$RootPath = "D:\SomeFolder"
$csvFilePaths = Get-ChildItem $RootPath -Recurse -Include *.csv |
ForEach-Object{
Import-CSV $_ |
Select-Object Test_Name, Test_DataName, Device_Model, Device_FW, Data_Avg_ms, Data_StdDev |
Export-Csv $_.FullName -NoType -Force
}
Run Code Online (Sandbox Code Playgroud) 我正在尝试将转储文件(包含 CREATE/DROP/INSERT 命令的 .sql 文件)从 Windows 环境导入远程 MySQL 服务器。我有这个 PowerShell 脚本通过使用安装在我的环境中的“MySQL shell 实用程序”功能来为我完成这项工作
Set-ExecutionPolicy RemoteSigned
Add-Type –Path 'C:\Program Files (x86)\MySQL\MySQL Connector Net 8.0.11\Assemblies\v4.5.2\MySql.Data.dll'
$Connection = [MySql.Data.MySqlClient.MySqlConnection]@{ConnectionString='server=192.168.100.100;Encrypt=false;uid=myUser;pwd=myPass;database=myDB;'}
$Connection.Open()
$sql = New-Object MySql.Data.MySqlClient.MySqlCommand
$sql.Connection = $Connection
$sql.CommandText = "SOURCE D:/MySQL_Dumps/myFile.sql"
$sql.ExecuteNonQuery()
$Reader.Close()
$Connection.Close()
Run Code Online (Sandbox Code Playgroud)
我可以连接到服务器,并执行基本的SELECT查询,使用ExecuteNonQuery()/ ExecuteScalar()/ExecuteReader()方法,但收到此特定的源命令的错误:
使用“0”参数调用“ExecuteNonQuery”的异常:“您有一个错误
在您的 SQL 语法中;检查与您的 MySQL 服务器相对应的手册
在“源”附近使用正确语法的版本
D:/MySQL_Dumps/myFile.sql' at line 1" At line:8 char:1
+ $sql.ExecuteNonQuery()
+ ~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullQualifiedErrorId : … 您好,我是初学者,我需要比较两个哈希表并进行其他重生。
例如 :
[hashtable]$alpha =@{
"A1" = "computer";
"A2" = "folder";
"A3" = "plane";
"A4" = "flower";
"A5" = "dog";
}
[hashtable]$beta =@{
"computer" = "P1";
"plane" = "P2";
"garden" = "p3";
"flower" = "P4";
"dog" = "P5";
}
Run Code Online (Sandbox Code Playgroud)
如果我有电脑$alpha和$beta我需要编写P1用户A1,如果我在有平面$alpha和$beta我需要写P2用户A3
我需要为每个使用吗?
谢谢 !
需要使用 PowerShell 在文档中搜索以下关键字:
[“允许的收购清理期”
$keyword = ""
Get-Content $SourceFileName | Select-String -Pattern $keyword
Run Code Online (Sandbox Code Playgroud)
我正在搜索的字符串中有双引号,所以我在努力如何在这个$keyword.
我想编写一个脚本,提示用户输入一个以分钟为单位的时间来启动关机计时器。我让它工作但没有输入验证。这就是我所拥有的。
DO{
try{
$numOk= $true
[int] $minutes= Read-Host "Enter the amount in minutes until a shut down (0 to cancel)"
#$minutes= [int]$minutes
}
catch{
#if($minutes -isnot [int]){}
$numOk= $false
Write-Host "Input is not an integer!!!!!"
}
} while ($numOk = $false)
[int] $seconds= $minutes*60
if($seconds -eq 0){
shutdown -a
}
else{
shutdown -s -t $seconds
}
Run Code Online (Sandbox Code Playgroud)
当我输入一个字母时,我得到了一个非常奇怪的值。
PS C:\Users\USER\Desktop\shut down> .\shutdownTimer.ps1
Enter the amount in minutes until a shut down (0 to cancel): a
Input is not an integer!!!!!
Cannot …Run Code Online (Sandbox Code Playgroud) 我在这里做错了什么?
我的 %UserProfile%.aws\config 文件如下所示:
[profile foo]
output = json
region = us-east-1
Run Code Online (Sandbox Code Playgroud)
我的 %UserProfile%.aws\credentials 文件如下所示:
[foo]
aws_access_key_id = BAOAIGKMPRBTLBNOSCZQ
aws_secret_access_key = OcML0LadbbD3Nt+PmAlhzNTmoS6Xx9M3M6DkBx4m
Run Code Online (Sandbox Code Playgroud)
所以没有配置默认配置文件:我只想为 Powershell 会话设置。
在 Powershell 中,我运行:
set AWS_PROFILE=foo
Run Code Online (Sandbox Code Playgroud)
然后我尝试执行 cli 命令,但它说找不到凭据:
PS D:\> aws ec2 describe-instances
You must specify a region. You can also configure your region by running "aws configure".
PS D:\> aws ec2 describe-instances --region us-east-1
Unable to locate credentials. You can configure credentials by running "aws configure".
Run Code Online (Sandbox Code Playgroud) powershell ×10
aws-cli ×1
compare ×1
csv ×1
escaping ×1
export-csv ×1
hashtable ×1
mysql ×1
quoting ×1
sitecore ×1
sitecore8.2 ×1
sql-server ×1
teamcity ×1