AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / server / 问题

问题[powershell](server)

Martin Hope
mfinni
Asked: 2025-01-11 03:25:29 +0800 CST

get-pfxCertificate 在有效证书上失败,而 import-pfxcertificate 有效

  • 5

我有一个已知良好的 PFX 文件,并且密码正确。我可以使用 Windows 证书 UI 或 import-pfxcertificate cmdlet 导入它。但是,get-pfxcertificate 失败了。有什么想法吗?

PS > $password = read-host -AsSecureString
****************

PS > Import-PfxCertificate C:\Users\mfinnigan\Desktop\test.pfx -Password $password cert:\CurrentUser\my

   PSParentPath: Microsoft.PowerShell.Security\Certificate::CurrentUser\my

Thumbprint                                Subject              EnhancedKeyUsageList
----------                                -------              --------------------
<snip>                                    CN=<snip>            Client Authentication

PS > get-pfxCertificate C:\Users\mfinnigan\Desktop\test.pfx -Password $password
Get-PfxCertificate: An error occurred during encode or decode operation.
powershell
  • 1 个回答
  • 20 Views
Martin Hope
Adam D.
Asked: 2024-12-13 07:49:11 +0800 CST

Powershell 函数()没有参数 args

  • 5

在 Powershell 中,函数的参数列表看起来像是一个数组构造函数,但有时允许 (),有时不允许,例如在调用重载的 getHashCode() 函数时。有人能解释一下这是怎么回事吗?

这是一个简单的函数和奇怪的结果:

function onBattery {
>>     if ((Get-WmiObject -Class Win32_Battery | Select-Object -ExpandProperty batterystatus) -eq 2) {
>>         write-output "Plugged In"
>>     }
>>     else {
>>         write-output "On Battery"
>>     }
>> }
PS C:\tmp>
PS C:\tmp> (onBattery).getHashCode

OverloadDefinitions
-------------------
int GetHashCode()



PS C:\tmp> (onBattery).getHashCode()
62670595
PS C:\tmp> onBattery($null)
Plugged In
PS C:\tmp> onBattery ($null)($null)
Plugged In
PS C:\tmp> onBattery()
At line:1 char:11
+ onBattery()
+           ~
An expression was expected after '('.
    + CategoryInfo          : ParserError: (:) [], ParentContainsErrorRecordException
    + FullyQualifiedErrorId : ExpectedExpression

另外,出于好奇,如何才能使 PS 函数通过一组空括号像这样进行调用:onBattery()?

powershell
  • 1 个回答
  • 26 Views
Martin Hope
SKaye
Asked: 2024-11-27 01:54:19 +0800 CST

计算机信息 Powershell 脚本的输出:在 csv 中将列转换为行

  • 5

我肯定忽略了一些显而易见的东西,这个任务不应该这么难!如果你能指出这一点而不笑得太多,我提前谢谢了。我正在编写一个系统调查脚本,通过 GPO 在启动时在我的域中的每台计算机上运行。每次运行时,它都应该将一行添加到共享驱动器上的 csv 文件中,其中包含它收集的所有信息。我只能让它以列的形式输出。

代码:

$loglocation = "C:\Temp"
$timestamp = Get-Date -UFormat "%Y-%m-%d %H:%M"
$ipaddress = Get-NetIPAddress | fl -Property ipaddress | Out-String -stream | 
Select-String 10.15

# Add info to hashtable
$computerinfohastable = [ordered]@{
Timestamp = $timestamp
Hostname = hostname
OSName = (Get-WmiObject Win32_OperatingSystem).Caption
OSVer = (Get-WmiObject Win32_OperatingSystem).Version
IPAddress = ($ipaddress -replace "ipaddress : ").Trim()
    }

# Convert to object
$computerinforows = $computerinfohastable.Keys | ForEach-Object {
[PSCustomObject]@{
    Property = $_
    Value = $computerinfohastable[$_]
}
}

# Output to csv
$computerinforows | Export-Csv -Path "$loglocation\testfile.csv" -
NoTypeInformation -Append

我得到的是:

Property    Value 
Timestamp   11/25/2024 14:23 
Hostname    ##### 
OSName      Microsoft Windows 11 Enterprise 
OSVer       10.0.26100 
IPAddress   nnn.nnn.nnn.nnn

我想要的是:

Timestamp          Hostname  OSName                             OSVer          IPAddress 
11/25/2024 14:23   #####     Microsoft Windows 11 Enterprise    10.0.26100     nnn.nnn.nnn.nnn

我上网尝试了几种转置方法,但都没有成功。非常感谢任何建议。

powershell
  • 1 个回答
  • 21 Views
Martin Hope
Jonas
Asked: 2024-10-12 07:50:21 +0800 CST

HPE iLO | 使用 PowerShell 删除 SSL 证书

  • 6

我有大约一百台服务器需要执行重复的过程。

  1. 禁用 DHCPv4DomainName 和 DHCPv6DomainName
  2. 设置 DNSName
  3. 设置域名

通过使用 HPEILOCMDLETS 和该模块中的“Set-HPEiLOI​​Pv4NetworkSetting”和“Set-HPEiLOI​​Pv6NetworkSetting”,可以轻松实现这些目标。但是,在执行上述操作时(实际上在此之前)会出现另一个问题。证书...

  1. 删除并重新生成(自动生成的自签名)证书。

但在这里,我无法找到一种不实际使用 GUI 就能做到这一点的方法。

因此,我正在寻找一种方法,要么删除 SSL 证书并让其重置并使用“正确”的 CN 生成新证书,要么启用“自动管理 SSL 证书”设置,我认为如果不匹配就会生成新证书。

有谁遇到过类似的问题并且有解决方案吗?

提前致谢,

J

powershell
  • 1 个回答
  • 118 Views
Martin Hope
reinhardS
Asked: 2024-09-18 22:47:41 +0800 CST

如何删除 AAD 中的孤立设备?

  • 5

在 Intune、Entra 中,如何查找和删除主 UPN 被删除的孤立设备?我还需要从 Autopilot 中删除它们。有人有 powershell 脚本吗?

powershell
  • 1 个回答
  • 72 Views
Martin Hope
BioRod
Asked: 2024-09-17 04:32:10 +0800 CST

使用 Intune 将 powershell 脚本部署到 50 台设备

  • 5

我编写了一个 powershell 脚本,打算使用 Intune 将其部署到 50 台设备。该脚本会删除 Chrome 中的浏览器缓存数据。我尚未通过 Intune 进行部署。在测试机器上,我将脚本放在一个目录中并执行它。我收到以下错误:

File C:\scripts\deleteGoogleCache.ps1 cannot be loaded because running scripts is 
disabled on this system. For more
information, see about_Execution_Policies at https:/go.microsoft.com/fwlink/? 
LinkID=135170.
+ CategoryInfo          : SecurityError: (:) [], ParentContainsErrorRecordException
+ FullyQualifiedErrorId : UnauthorizedAccess

因此,我寻找解决方案。我应该以管理员身份运行 PowerShell。显然,我不会在每个设备上都以管理员身份运行 powershell。因此,我通过发出以下命令找到了另一个提示:

Set-ExecutionPolicy -ExecutionPolicy RemoteSigned

我收到了以下回复。

Execution Policy Change
The execution policy helps protect you from scripts that you do not trust. Changing the 
execution policy might expose
you to the security risks described in the about_Execution_Policies help topic at
https:/go.microsoft.com/fwlink/?LinkID=135170. Do you want to change the execution 
policy?
[Y] Yes  [A] Yes to All  [N] No  [L] No to All  [S] Suspend  [?] Help (default is "N"):

显然,我不会亲自前往每一台设备并按 [A] 表示全部“是”。

任何帮助都将不胜感激,我是 Powershell 新手。

powershell
  • 1 个回答
  • 19 Views
Martin Hope
bh-alienux
Asked: 2024-07-31 02:53:55 +0800 CST

关闭最后的 Exchange Server 步骤 5b - 如何以及在哪里在 PowerShell 中运行 Microsoft.Graph.Applications?

  • 5

完成所有先前的步骤(均在本地 Exchange PowerShell 中运行)后,我进入了此处的步骤 5b:

https://learn.microsoft.com/en-us/exchange/manage-hybrid-exchange-recipients-with-management-tools#permanently-shutting-down-your-last-exchange-server

虽然我非常熟悉 Windows PowerShell 和 Exchange Management Shell,但我并不熟悉 Microsoft Graph PowerShell。

阅读完之后,我似乎需要在 PowerShell 中运行一个命令来安装 Microsoft Graph 模块,以便完成下一步。

我在说明中看不到并且找不到验证,即我在哪里安装模块以及我使用什么凭据。

我可以从运行 PowerShell 的任何已加入域的计算机上执行此操作吗?还是需要在运行 Azure AD Connect 的服务器上执行此操作?还是我应该在 Exchange 管理 Shell 中执行此操作?

安装后我使用什么凭据进行连接?说明上说“以租户管理员身份运行”,这让我想到了 O365,但这与删除本地 Exchange 服务器有关,所以我不明白为什么要在 O365 在线 PowerShell 中运行它。

powershell
  • 2 个回答
  • 63 Views
Martin Hope
Larsen
Asked: 2024-07-22 21:26:13 +0800 CST

Powershell“New-FsrmFileScreen:0x80070057,参数不正确。”

  • 5

我们正在使用 Windows Server 2019 上的文件服务器资源管理器来监控所有网络共享,以防止勒索软件攻击。最初,我们使用黑名单,但现在我想使用 powershell 命令将其切换为白名单。

这是我用来创建模板的命令(FileGroup 之前已创建):

$ntf_action = New-FsrmAction -Type Command -Command "C:\WINDOWS\system32\WindowsPowerShell\v1.0\powershell.exe" -CommandParameters "c:\admin-skripte\block-ransomware\block-ransomware.ps1 '[Source Io Owner]' '[Source File Path]' '[Server]'"

New-FsrmFileScreenTemplate -Name "testing" -IncludeGroup "Whitelist" -Notification $ntf_action

失败并显示错误New-FsrmFileScreenTemplate : 0x80070057, The parameter is incorrect.(或0x80070057, Falscher Parameter.德语)

powershell
  • 1 个回答
  • 11 Views
Martin Hope
Halfdone
Asked: 2024-06-26 02:05:51 +0800 CST

删除最终的 Exchange 服务器,无法遵循 Microsoft 的指示

  • 6

我正在按照 Microsoft 的说明( https://learn.microsoft.com/en-us/exchange/manage-hybrid-exchange-recipients-with-management-tools#permanently-shutting-down-your-last-exchange-server )查看删除环境中的最后一个 Exchange 服务器的过程。“永久关闭最后一个 Exchange 服务器”的第 5 步是删除为 OAuth 创建的服务主体凭据。它提供了一些 PowerShell 命令来确定和删除凭据:

5a. 在 Exchange 命令行管理程序中运行以下命令以获取 OAuth credValue:

$thumbprint = (Get-AuthConfig).CurrentCertificateThumbprint
$oAuthCert = (dir Cert:\LocalMachine\My) | where {$_.Thumbprint -match $thumbprint}
$certType = [System.Security.Cryptography.X509Certificates.X509ContentType]::Cert
$certBytes = $oAuthCert.Export($certType)
$credValue = [System.Convert]::ToBase64String($certBytes)

5b. 找到与上面找到的 $credValue 相同的 KeyId,使用 Microsoft Graph PowerShell 以租户管理员身份运行以下命令。

Import-Module Microsoft.Graph.Applications
Connect-MgGraph -Scopes "Application.Read.All"
$ServiceName = "00000002-0000-0ff1-ce00-000000000000"
$p = Get-MgServicePrincipalByAppId -AppId $ServiceName
$keyId = (Get-MgServicePrincipal -ServicePrincipalId $p.Id).KeyCredentials $true | ?{$_.Value -eq $credValue}).KeyId

这将给出其值与上面找到的 $credValue 匹配的密钥的 KeyId。

5c. 要删除服务主体凭据,请运行以下命令:

Import-Module Microsoft.Graph.Applications
$params = @{
  KeyId = $keyId
}
Remove-MgServicePrincipalKey -ServicePrincipalId $p.Id -BodyParameter $params

5b 中的最后一个 $keyId 赋值不是有效的 PowerShell 命令,其中有一个“$true”位置不对,并且有一个多余的结束括号。看起来命令已损坏。手动运行 Get-MgServicePrincipal 确实返回了一个 KeyCredentials 对象,但我没有看到它似乎在寻找的“Value”属性。这可能只是因为缺少部分命令。

有人知道我该如何完成这一步吗?是通过有效的 PowerShell 还是其他方法(例如 M365 门户)?另外,跳过这一步也可以吗,因为可能会留下一些垃圾?

powershell
  • 1 个回答
  • 97 Views
Martin Hope
Samuel
Asked: 2024-06-12 20:08:53 +0800 CST

在 Intune 客户端上读取完整的用户电子邮件地址

  • 5

我正在配置 Windows 11 客户端,作为将我们的基础设施迁移到 Intune 项目的一部分。作为此项目的一部分,我在使用适用于非 Intune 域客户端的 powershell 脚本时遇到了麻烦。我需要检查电子邮件地址是否包含字符串“@stu.domain”或是否仅包含“@domain”。我的脚本如下:

# Define the path to the executable
$exePath = "C:\Program Files\uniFLOW SmartClient\momsmartclnt.exe"
$currentUser = ([adsi]"LDAP://$(whoami /fqdn)").mail

# Check if the file exists and wether user is a teacher
if (Test-Path $exePath) {
    # Run the executable
    if($currentUser -notLike "*stu.myDomain*") {
        Start-Process -FilePath $exePath
    }   
} else {
    Write-Host "File not found: $exePath"
}

现在,当我在我的 uniflow 注册客户端上运行它时,我收到以下错误:

Powershell 错误

其含义为:“无法请求 FQDN,因为当前用户不是域用户。

但是,当我运行 whoami 命令时,我得到了域/用户名,但没有得到完整的电子邮件。

我在这里是否混淆了某些事情,或者是否有更好的方法从客户端获取完整的用户电子邮件?

提前感谢您提供的任何帮助/建议。

powershell
  • 1 个回答
  • 34 Views

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    新安装后 postgres 的默认超级用户用户名/密码是什么?

    • 5 个回答
  • Marko Smith

    SFTP 使用什么端口?

    • 6 个回答
  • Marko Smith

    命令行列出 Windows Active Directory 组中的用户?

    • 9 个回答
  • Marko Smith

    什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同?

    • 3 个回答
  • Marko Smith

    如何确定bash变量是否为空?

    • 15 个回答
  • Martin Hope
    Tom Feiner 如何按大小对 du -h 输出进行排序 2009-02-26 05:42:42 +0800 CST
  • Martin Hope
    Noah Goodrich 什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同? 2009-05-19 18:24:42 +0800 CST
  • Martin Hope
    Brent 如何确定bash变量是否为空? 2009-05-13 09:54:48 +0800 CST
  • Martin Hope
    cletus 您如何找到在 Windows 中打开文件的进程? 2009-05-01 16:47:16 +0800 CST

热门标签

linux nginx windows networking ubuntu domain-name-system amazon-web-services active-directory apache-2.4 ssh

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve