【发布时间】:2017-12-07 20:18:37
【问题描述】:
我们正在努力在我们的环境中使用 RMS 保护文件。我们必须使用 PowerShell。
我什至不能使用 MDT 加入域的 WDS 服务器,因为它使用的 psxml 文件没有签名。
我必须将 PS 脚本作为单行命令或使用编码命令运行
[convert]::ToBase64String([Text.Encoding]::Unicode.GetBytes($code))
符合我用$code = {} 包裹的脚本。
此脚本在从 PowerShell ISE 运行时有效。
$lines = Get-Content E:\folder\list.txt | Select-String -Pattern "Success Message" -AllMatches -Context 1,0 | % $_.Context.PreContext[0]
foreach ( $line in $lines ) {
$file = $line.ToString().TrimStart("chars. ")
Protect-RMSFile -File $file -InPlace -DoNotPersistEncryptionKey All -TemplateID "template-ID" -OwnerEmail "admin@domain.com" | Out-File -FilePath E:\folder\logs\results.log -Append
}
批处理脚本:
"e:\folder\command.exe -switches" > "E:\folder\list.txt"
powershell.exe -EncodedCommand encodedBlob
输出:
Cannot index into a null array.
At line:3 char:1
+ $lines = Get-Content E:\folder\list.txt | Select-String -Pattern "S ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : NullArray
我在另一个问题上看到了某种异常日志可能会有所帮助...
$Error.Exception | Where-Object -Property Message -Like "Cannot index into a null array." | Format-List -Force | Out-File -FilePath E:\folder\err.log
输出:
ErrorRecord : Cannot index into a null array.
StackTrace : at CallSite.Target(Closure , CallSite , Object , Int32 )
at System.Dynamic.UpdateDelegates.UpdateAndExecute2[T0,T1,TRet](CallSite site, T0 arg0, T1 arg1)
at System.Management.Automation.Interpreter.DynamicInstruction`3.Run(InterpretedFrame frame)
at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame)
at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame)
WasThrownFromThrowStatement : False
Message : Cannot index into a null array.
Data : {System.Management.Automation.Interpreter.InterpretedFrameInfo}
InnerException :
TargetSite : System.Object CallSite.Target(System.Runtime.CompilerServices.Closure, System.Runtime.CompilerServices.CallSite, System.Object,
Int32)
HelpLink :
Source : Anonymously Hosted DynamicMethods Assembly
HResult : -2146233087
认为这就像 NTFS 权限一样简单,我取得了所有者并将此文件夹结构上的所有权限替换为管理员和我的完全控制权。错误没有变化。
有什么建议吗?我忽略了一些简单的事情吗?
【问题讨论】:
-
如果是权限问题,您会在
Get-Content调用中遇到错误。你的逻辑不适合模式匹配,所以$Lines最终会是$Null。
标签: powershell base64 rights-management