简体   繁体   English

我需要把这个 powershell 代码变成 C#,因为我不能设置执行策略来运行 powershell 脚本

[英]I need to turn this powershell code into C#, because I cant set execution policy to run powershell scripts

I work on a computer where I have no admin rights and I am unable to set execution policy.我在没有管理员权限且无法设置执行策略的计算机上工作。 I need to turn this powershell code into C#, so I can make binary module, because those are unaffected by execution policy.我需要将这个 powershell 代码转换为 C#,这样我就可以制作二进制模块,因为它们不受执行策略的影响。

$Host.PrivateData.ErrorForegroundColor = 'Red'
$Host.PrivateData.WarningForegroundColor = 'Magenta'
$Host.PrivateData.DebugForegroundColor = 'Black'
$Host.PrivateData.VerboseForegroundColor = 'Blue'
$Host.PrivateData.ProgressForegroundColor = 'White'

$Host.PrivateData.ErrorBackgroundColor = 'DarkYellow'
$Host.PrivateData.WarningBackgroundColor = 'DarkYellow'
$Host.PrivateData.DebugBackgroundColor = 'DarkYellow'
$Host.PrivateData.VerboseBackgroundColor = 'DarkYellow'
$Host.PrivateData.ProgressBackgroundColor = 'DarkBlue'

Set-PSReadlineOption -Colors @{
  Command = 'DarkRed';
  Comment = 'DarkGray';
  ContinuationPrompt = 'DarkCyan';
  DefaultToken = 'DarkMagenta';
  Emphasis = 'Red';
  Error = 'DarkRed';
  Keyword = 'DarkGreen';
  Member = 'DarkGreen';
  Number = 'DarkGreen';
  Operator = 'Black';
  Parameter = 'DarkCyan';
  String = 'DarkBlue';
  Type = 'DarkBlue';
  Variable = 'DarkGreen';
}

Set-Location C:\
Clear-Host

So I can compile this as.dll with Add-Type cmdlet and use command Load-Colors to execute this module's contents.因此,我可以使用 Add-Type cmdlet 将其编译为 as.dll 并使用命令 Load-Colors 来执行该模块的内容。

Is it possible to make binary profile like Microsoft.PowerShell_profile.dll?是否可以制作像 Microsoft.PowerShell_profile.dll 这样的二进制配置文件? I have eyesight problems (Astigmatism), I need light colorscheme.我有视力问题(散光),我需要浅色配色方案。 Thank you in advance!先感谢您! Much appreciate it!非常感谢!

You can use either powershell.exe -ExecutionPolicy Bypass or Set-ExecutionPolicy -Scope CurrentUser RemoteSigned -Force to modify the execution policy on a machine you don't have local admin rights on.您可以使用powershell.exe -ExecutionPolicy BypassSet-ExecutionPolicy -Scope CurrentUser RemoteSigned -Force在您没有本地管理员权限的计算机上修改执行策略。

Answers from the comments of Mathias R. Jessen & mklement0来自 Mathias R 评论的答案。Jessen & mklement0

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM