我查询 Office365 以获取与Chris的 displayName 匹配的所有用户的列表。
我想提示用户他们想要选择哪个克里斯。这样做时,我有以下 for..each 代码
$tmpUserOffice = Get-MsolUser -SearchString "*Chris*"
if ($tmpUserOffice -is [array])
{
if ($tmpUserOffice.Count -lt 50) {
Write-Host "Many matching users in MSOL. Choose which one you want to save"
for ($i = 0; $i -lt $tmpUserOffice.Count; $i++) {
Write-Host $i " " $($tmpUserOffice[$i].DisplayName)
}
Write-Host $tmpUserOffice.Count " None of the above"
$chosen = Read-Host
if ($chosen -eq $tmpUserOffice.Count) {
Write-Warning "Nothing found. Try searching with different criteria or use wildcards"
Write-Output $null …Run Code Online (Sandbox Code Playgroud) 有一些指南展示了如何执行此操作,但它们是不久前的,我似乎找不到它们所指的实用程序 certoc.exe。这是否已从 Nanoserver 的更高版本中删除?
https://joshuachini.com/2018/02/08/how-to-import-an-enterprise-certificate-into-a-windows-container/
https://www.ntweekly.com/2017/01/30/install-self-signed-certificate-on-windows-nano-server-2016/
有人知道我应该在哪里获得这个实用程序吗?
我在这里发现了另一个小线索 https://github.com/PowerShell/CertificateDsc/issues/45
这种情况回避了 Nano 服务器中可用的 Import-Certificate 命令。虽然我也没有找到。
任何帮助都会得到应用,干杯。
PS C:\> docker run microsoft/nanoserver:1803_KB4338819 certoc.exe
C:\Program Files\Docker\Docker\Resources\bin\docker.exe: Error response from daemon: container 3f732602c6d8fbbf9370613971a7f40993a54bc33870d3040bf5e9c2fec8969c encountered an error during CreateProcess: failure in a Windows system call: The system cannot find the file specified. (0x2) extra info: {"CommandLine":"certoc.exe","User":"ContainerUser","WorkingDirectory":"C:\\","CreateStdInPipe":true,"CreateStdOutPipe":true,"CreateStdErrPipe":true,"ConsoleSize":[0,0]}.
PS C:\> docker run -it microsoft/powershell:6.0.4-nanoserver-1803_kb4338819 certoc.exe
C:\Program Files\Docker\Docker\Resources\bin\docker.exe: Error response from daemon: container 285d821dccac930df5681e73842f8ce2bac812f361a6b9d14b00dcb4901a9141 encountered an error during CreateProcess: failure in a Windows system call: The system …Run Code Online (Sandbox Code Playgroud) 我到处寻找,但没有运气。
对数组使用 foreach,在对每个数组项运行命令后,我不确定结果来自哪个数组项。
我尝试了很多变化。这段代码是我尝试过的最好的例子。
$ADGroupVar = @(
'ADGroup1'
'ADGroup2'
'ADGroup3'
);
foreach ($ADgrouplist in $ADGroupVar)
{
Write-Host $ADgrouplist
Get-ADGroupMember ($ADgrouplist) | select name
}
ADGroup1
ADGroup2
ADGroup3
Computer5
Computer10
Computer2
Computer4
Computer20
Computer3
Computer1
Run Code Online (Sandbox Code Playgroud)
期望的结果是:
ADGroup1
Computer5
Computer10
ADGroup2
Computer2
Computer4
Computer20
ADGroup3
Computer3
Computer1
或者
Computer5 ADGroup1
Computer10 ADGroup1
...
无论出于何种原因,在 powershell 中的以下命令中,
Set-PSReadlineOption -TokenKind Comment -ForegroundColor Gray
Run Code Online (Sandbox Code Playgroud)
我猜颜色有些不对劲,我正在尝试改变它。关键似乎是选择正确的 TokenKind,此处列出(但未记录)。
TokenKind为了看到破折号后的文本,我应该更改哪些内容?
我正在尝试运行一个已作为字符串存储在变量中的命令,但是当我尝试使用“Invoke-Command”运行它时,我被告知它需要是“ScriptBlock”而不是字符串。\n该命令是:
\n\nASIMPORT.EXE -rexactdb-01 -DTEST001 -u -~ I -URL X:\\test.xml -Tglentries -OPT18 \xe2\x80\x93Oauto\nRun Code Online (Sandbox Code Playgroud)\n\n我正在尝试将其运行为:
\n\nInvoke-Command -ScriptBlock $command\nRun Code Online (Sandbox Code Playgroud)\n\n尝试使用和不使用“ScriptBlock”,总是得到相同的错误。谷歌搜索后,老实说我不明白我应该如何解决这个问题,所以任何建议都是值得赞赏的。
\n我正在尝试获取 Google Chrome 的版本号,但找不到。
我可以看到 chrome 已安装:

我尝试使用PowerShell:
get-wmiobject Win32_Product | Format-Table IdentifyingNumber, Name, LocalPackage -AutoSize
Run Code Online (Sandbox Code Playgroud)
但我得到的是一个不包含“Google Chrome”的列表。
如何获取 Chrome 浏览器的版本号?
在powershell中,与在 中一样cmd,您必须键入文件的路径,包括文件本身,或者如果您与文件所在的位置相同,则只需键入文件名,下面显示了每种情况的示例:
# if the file is a different location
[Path to the file]\[fileName]
# if the file is in the same location
.\[fileName]
Run Code Online (Sandbox Code Playgroud)
我想要做的是将文件的路径分配给一个变量,当我想打开文件时只需键入变量名称,如下所示:
$path = [fileLocation + fileName]
Run Code Online (Sandbox Code Playgroud)
但是,问题是,当我键入变量时,PowerShell 会返回 的字符串值$path,因此,如何通过将文件的路径分配给变量来启动文件?
我正在尝试生成每个 ASCII 字符 1 个的字符串。我开始于
32..255| %{[char]$_ | Out-File -filepath .\outfile.txt -Encoding ASCII -Append}
Run Code Online (Sandbox Code Playgroud)
我期望的是可打印字符列表,但我得到了不同的字符。
谁能向我指出获得预期结果的更好方法,或者解释为什么我会得到这些结果?
我有以下 powershell 脚本文件
C:\用户\桌面\script1.ps1
脚本的内容如下:
get-process
Run Code Online (Sandbox Code Playgroud)
我正在尝试创建一个 C# 控制台应用程序以在控制台上获取此脚本的输出。当我在 C# 外部执行脚本时,它运行良好,但当我在 C# 内部执行它时,它不会产生任何结果。我正在尝试使用 addscript 并调用。
C#代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Management.Automation;
using System.Collections.ObjectModel;
namespace InvokePowerShellScriptFrmCsharp1
{
class Program
{
static void Main(string[] args)
{
string script = @"C:\\Users\\Desktop\\script1.ps1";
PowerShell shell = PowerShell.Create();
shell.AddScript(script);
//shell.AddCommand("get-process");
shell.Invoke();
//shell.AddScript(script).Invoke();
Collection<PSObject> pSObjects = shell.Invoke();
foreach (PSObject p in pSObjects)
{
Console.WriteLine(p.ToString());
}
Console.WriteLine("Press any key to continue");
Console.ReadLine();
}
}
}
Run Code Online (Sandbox Code Playgroud)
当我执行上述命令时,控制台显示“按任意键继续”,但在此之前没有输出。
但如果我尝试下面的方法我会得到结果
shell.addcommand("get-process");
Run Code Online (Sandbox Code Playgroud)
我希望将来能够使用 addscript 来实现这一功能,因为如果 …
我正在尝试创建一个自定义 Azure RM 角色定义,其范围适用于一个订阅内的某些资源组。我不想提供对所有订阅或仅一个资源组的访问,并且我可以指定资源组列表,因为其中一些资源组尚未创建。我只想提供订阅资源组的某些子集的访问权限。
\n\n为此,我使用 PowerShell cmdlet
\n\nNew-AzureRmRoleDefinition -InputFile .\\new-role.json \nRun Code Online (Sandbox Code Playgroud)\n\nJSON 在哪里
\n\n{\n "Name": "RoleAssignmentsWriter",\n "Description": "Allow to perform role assignment",\n "Actions": [\n "Microsoft.Authorization/roleAssignments/write"\n ],\n "AssignableScopes": [\n "/subscriptions/xxxxx-xxxxx-xxxx-xxx-xxxxxxx/resourceGroups/prefix*"\n ]\n} \nRun Code Online (Sandbox Code Playgroud)\n\n其中prefix是现有资源组名称和功能资源组名称的前缀。
\n\n如果AssignableScopes: [\xe2\x80\x9c/subscriptions/xxxxx-xxxxx-xxxx-xxx-xxxxxxx\xe2\x80\x9d]\xe2\x80\x93 整个订阅或者如果AssignableScopes: ["/subscriptions/xxxxx-xxxxx-xxxx-xxx-xxxxxxx/resourceGroups/ResourceGroupName\xe2\x80\x9d]
AssignableScopes: ["/subscriptions/xxxxx-xxxxx-xxxx-xxx-xxxxxxx/resourceGroups/prefix*"]但如果我指定或什至 则不\xe2\x80\x99 不起作用AssignableScopes: ["/subscriptions/xxxxx-xxxxx-xxxx-xxx-xxxxxxx/resourceGroups/*"]。
一件重要的事情是,我想为尚不存在的资源组创建角色定义,稍后将创建它们。
\n\n问题是:是否可以AssignableScopes仅指定订阅资源组的某些子集?也许我可以在其中使用某种通配符AssignableScopes?简单的星号标记不起作用。\n或者也许我可以使用资源组标签或其他东西?
预先非常感谢您。
\npowershell ×10
arrays ×1
ascii ×1
azure ×1
c# ×1
command ×1
command-line ×1
docker ×1
encoding ×1
execution ×1
foreach ×1
nano-server ×1
rbac ×1
version ×1
windows ×1
write-host ×1