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
    • 最新
    • 标签
主页 / user-1000226

webby68's questions

Martin Hope
webby68
Asked: 2024-11-05 03:55:02 +0800 CST

使用 PSSession 遍历虚拟机列表并将硬盘大小调整为新分配的磁盘空间

  • 5

我对 PowerShell 并不陌生,但也不熟练使用,因此我在这里发布我的问题以寻求可能的帮助。

我以管理员身份登录 Windows PowerShell ISE,安装了 PowerCLI 模块,当前登录托管虚拟机的 Hyper V 服务器。我有一个 PS 脚本,它将遍历多个虚拟机并扩展它们的磁盘空间以实现 30GB 的可用空间。但是,我不得不使用 PSSession 一次一台机器将这些驱动器的大小调整为新分配的空间。我一直在寻找一种方法来使用 PS 脚本遍历这些机器的文本文件列表并调整它们的大小,就像其他脚本扩展驱动器一样。经过一番研究,我意识到我可以使用 PSSession 来做到这一点。我创建了一个脚本来执行此操作,它运行良好,直到它到达下面脚本的调整大小部分。

Resize-Partition -DriveLetter $drive_letter -Size $size.SizeMax

我收到错误消息“Resize-Partition:不支持大小扩展信息:分区已经是请求的大小。”我检查了测试机器,扩展卷已正确扩展,但分区尚未调整大小以提供新提供的可用磁盘空间量。脚本发布如下。我收到的完整错误消息将发布在脚本下方。

我不确定我在这里遗漏了什么,并且感谢所提供的所有帮助。

脚本:

$vmcomputers = Get-Content -Path C:\Temp\computers.txt
$drive_letter = "C"

# iterate through list
$result = foreach ($vmcomputer in $vmcomputers) {
  # create PSsession
  #$session = New-PSSession -ConnectionUri $vmcomputer.hostname
  $session = Get-Content C:\Temp\computers.txt | New-PSSession -ThrottleLimit 50
  
  # resize disk
  $size = (Get-PartitionSupportedSize -DriveLetter $drive_letter)
  Resize-Partition -DriveLetter $drive_letter -Size $size.SizeMax

  # cleanup
  Remove-PSSession -PSSession $session
}

错误信息:

Resize-Partition : Size Not Supported
 
Extended information:
The partition is already the requested size.
 
Activity ID: {69684292-964a-4637-92bd-1ddf1ccb773f}
At C:\Temp\ResizeVMdiskPsession\AICodeResizeVmHardDisk.ps1:12 char:3
+   Resize-Partition -DriveLetter $drive_letter -Size $size.SizeMax
+   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (StorageWMI:ROOT/Microsoft/.../MSF 
   T_Partition) [Resize-Partition], CimException
    + FullyQualifiedErrorId : StorageWMI 4097,Resize-Partition
 
Remove-PSSession : A parameter cannot be found that matches parameter name 
'PSSession'.
At C:\Temp\ResizeVMdiskPsession\AICodeResizeVmHardDisk.ps1:15 char:20
+   Remove-PSSession -PSSession $session
+                    ~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (:) [Remove-PSSession], Paramet 
   erBindingException
    + FullyQualifiedErrorId : NamedParameterNotFound,Microsoft.PowerShell.Comm 
   ands.RemovePSSessionCommand
hard-drive
  • 1 个回答
  • 82 Views
Martin Hope
webby68
Asked: 2023-12-29 01:50:42 +0800 CST

如何在 PowerShell 中使用 foreach 语句删除分区

  • 6

我需要从虚拟计算机上的特定硬盘驱动器中删除分区。我可以手动执行此操作,一次一台计算机,没有问题。但是,我需要能够运行一个 PowerShell 脚本,该脚本将读取包含计算机列表的文本文件,并让脚本迭代每台计算机并删除该特定分区。

我知道每台机器的磁盘号和分区号是多少,因此不需要“if”语句。我还知道机器有这个特定的分区需要删除。

我尝试使用的脚本如下。当我在调试器中运行它时,除了“Get-Partition”行之外,所有脚本都会被读取。该脚本会遍历计算机列表,但不会选择分区,因此不会选择我需要删除的分区。

我在谷歌上研究了与获取我需要的信息相关的各种关键字,但我找不到任何专门解决这个问题的东西。如有任何建议或帮助,我们将不胜感激。

我通过 PowerCLI 代码命令连接到托管计算机的服务器。代码如下:

$computers = Get-Content -Path C:\Temp\computers.txt

foreach ($computer in $computers)
{
   Get-Disk
   Get-Partition
   Remove-Partition -DiskNumber 0 -PartitionNumber 3
}
windows
  • 1 个回答
  • 23 Views
Martin Hope
webby68
Asked: 2020-10-06 13:42:27 +0800 CST

如何减少 .csv 文件中的 PowerShell 输出以仅写入 Windows 10 操作系统的发布 ID?

  • 8

此脚本有效,但发布 id 字段中 .csv 的输出是与注册表项关联的所有内容。我想要的只是发布 ID 号(1909、1809、1709)。我如何编辑这个脚本只是为了只将该信息写入输出文件?下面是我现在得到的输出示例。下面是我正在使用的脚本。

我现在得到的输出。

@{ReleaseId=1909; PSPath=Microsoft.PowerShell.Core\Registry::HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion; PSParentPath=Microsoft.PowerShell.Core\Registry::HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT; PSChildName=CurrentVersion; PS

我正在使用的脚本如下。

$Computers = get-content "C:\Temp\computers.txt"

$( foreach ($Computer in $Computers) 
  {
        $result = Invoke-Command -ComputerName $Computer -scriptBlock { Get-ItemProperty -Path 'Registry::HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion' -Name ReleaseId } 
            
        [PSCustomObject]@{
            ComputerName = $Computer
            ReleaseID = $Result
        }
        
    } ) | Export-Csv "C:\Temp\GetReleaseID.csv" -NoType

Invoke-Item "C:\Temp\GetReleaseID.csv"
microsoft-excel windows-10
  • 1 个回答
  • 266 Views
Martin Hope
webby68
Asked: 2020-03-25 13:51:40 +0800 CST

无法将参数绑定到参数“InputObject”,因为它为空

  • 5

我正在使用 SCCM 2016、Windows Server 2012。我正在使用下面的代码将集合移动到另一个文件夹。我收到错误消息Move-CMObject : Cannot bind argument to parameter 'InputObject' because it is null.

我已经通过谷歌研究了这个错误,但我仍然无法理解“InputObject”是如何为空的。我见过其他格式相同的 PS 脚本,它是一个工作脚本。我想知道如何解决这个问题并将集合移动到另一个文件夹。

$sitecode = "123"
$colltomove = "JJJ00287"
$destcollfolder = '$($sitecode):\DeviceCollection\Test Operational' 

$collID = Get-CMCollection -Name $colltomove
Move-CMObject -InputObject $collID -FolderPath $destcollfolder
powershell windows-server-2012
  • 1 个回答
  • 2594 Views
Martin Hope
webby68
Asked: 2019-12-17 15:07:15 +0800 CST

Powershell - 如何显示消息并将用户输入保存到日志文件

  • 5

我花了大部分时间研究实现这一目标的最佳和最简单的方法,但似乎没有。我找到了一些零碎的东西,但我无法成功地让它们工作。我只是想通过运行 Powershell 脚本向用户显示一条弹出消息。我想让脚本执行以下操作:

1. The popup would give an action for input by the user, 
2. The message will tell them their computer will be restarted to complete a Windows 1809 upgrade, 
3. The user will click ok and the input, along with the username and machine name will be sent to a log file. 
4. The script would have a timer on it that will restart the computer within 30 minutes whether the input is given or not. 

下面的代码做我想要的,减去计时器,但不会给用户带来弹出消息。它只是在 Powershell 控制台中给出消息。我怎样才能让它做同样的事情,但在弹出消息中呢?

$HostName = $env:COMPUTERNAME
$PatchLocation = "c:\Temp\"
$LogFile = "responses.log"
$LogPath = $PatchLocation + $LogFile
$date = Get-Date

$response = Invoke-Command -ComputerName $HostName -ScriptBlock{ Read-Host "Your computer will be restarted in 30 minutes. Please save your work. Type 'Agree' If you have saved your work"}

"Response for $HostName is $response - $date"|Out-File -FilePath $LogPath -Append
windows-10 powershell
  • 2 个回答
  • 897 Views
Martin Hope
webby68
Asked: 2019-11-27 10:53:23 +0800 CST

Powershell 脚本 - 仅在驱动器空间低于 MinThreshold 时发送电子邮件

  • 6

我使用的是 Windows 10 Enterprise 1709 和 PowerShell 5.0 版。我在网上找到了这个 PowerShell 脚本。它有效,但我不明白代码中的一行在做什么,所以我可以决定如何编辑它以完成我需要做的事情。此外,即使驱动器不低于最低阈值,它也会发送电子邮件。我想了解这行代码并将其修复为仅在低于最低阈值时发送电子邮件警报。$freeSpaceGB = [Math]::Round([float]$disk.FreeSpace / 1073741824);这条线$computer = $computer.toupper();

整个代码如下:

$minGbThreshold = 50GB

$computers = $env:COMPUTERNAME
$smtpAddress = "smtp.anydomain.com"
$toAddress = "anyone@anywhere.com"
$fromAddress = "desktop-admin@anywhere.com"

foreach($computer in $computers)
{    
    $disks = Get-WmiObject -ComputerName $computer -Class Win32_LogicalDisk -Filter "DriveType = 3";
    $computer = $computer.toupper();
    $deviceID = $disk.DeviceID;
    foreach($disk in $disks)
    {
        $freeSpaceGB = [Math]::Round([float]$disk.FreeSpace / 1073741824);
        if($freeSpaceGB -lt $minGbThreshold)
        {
            $smtp = New-Object Net.Mail.SmtpClient($smtpAddress)
            $msg = New-Object Net.Mail.MailMessage
            $msg.To.Add($toAddress)
            $msg.From = $fromAddress
            $msg.Subject = “Diskspace below threshold ” + $computer + "\" + $disk.DeviceId
            $msg.Body = $computer + "\" + $disk.DeviceId + " " + $freeSpaceGB + "GB Remaining";
            $smtp.Send($msg)
        }
    }
}
windows-10 windows
  • 1 个回答
  • 1628 Views
Martin Hope
webby68
Asked: 2019-03-30 10:30:08 +0800 CST

禁用后无法启用 Microsoft Print to PDF

  • 1

我使用以下命令查找功能名称,第二个命令 (Powershell) 禁用 Microsoft Print to PDF,第三个命令重新启用它。

DISM /online /get-features /format:table | find "Disabled"

Disable-WindowsOptionalFeature -Online -FeatureName "Microsoft-Windows-Printing-PrintToPDFServices-Package"

Enable-WindowsOptionalFeature -Online -FeatureName "Microsoft-Windows-Printing-PrintToPDFServices-Package"

禁用命令完美运行,但是,我在尝试启用它时收到以下消息。

“enable-windowsoptionalfeature:几个父功能之一被禁用,因此无法启用当前功能。” (见截图)

启用 Windows 可选功能错误

其次,我尝试通过“打开或关闭 Windows 功能”启用该功能,但找不到。(见截图)

打开或关闭 Windows 功能

我已经为此研究了几个小时,我能找到的唯一信息是如何通过程序和功能重新添加打印机。我将不胜感激所有帮助解决这个问题。

windows-10 powershell command-line
  • 1 个回答
  • 1744 Views
Martin Hope
webby68
Asked: 2019-03-29 12:34:05 +0800 CST

如何使用 SCCM 禁用各种 PDF 打印机

  • 1

我使用的是 SCCM 版本 1802、控制台版本 5.1、站点版本 5.0.8。我希望能够禁用 Litera EPO PDF 打印机、Microsoft print to pdf、Microsoft XPS Document Writer 和 Fax。我想这样做的原因是我想防止使用这些,但我不想从用户或 SCCM 图像中删除它们,以防万一出现问题需要恢复。我目前正在使用 powershell 命令将其删除,但我无法找到将这些打印机添加回来的脚本。有这样的选择吗?如果是这样,它是如何使用的?我正在使用的命令如下。

Remove-Printer -Name "Microsoft Print to PDF"
print-to-pdf sccm
  • 1 个回答
  • 397 Views

Sidebar

Stats

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

    如何减少“vmmem”进程的消耗?

    • 11 个回答
  • Marko Smith

    从 Microsoft Stream 下载视频

    • 4 个回答
  • Marko Smith

    Google Chrome DevTools 无法解析 SourceMap:chrome-extension

    • 6 个回答
  • Marko Smith

    Windows 照片查看器因为内存不足而无法运行?

    • 5 个回答
  • Marko Smith

    支持结束后如何激活 WindowsXP?

    • 6 个回答
  • Marko Smith

    远程桌面间歇性冻结

    • 7 个回答
  • Marko Smith

    子网掩码 /32 是什么意思?

    • 6 个回答
  • Marko Smith

    鼠标指针在 Windows 中按下的箭头键上移动?

    • 1 个回答
  • Marko Smith

    VirtualBox 无法以 VERR_NEM_VM_CREATE_FAILED 启动

    • 8 个回答
  • Marko Smith

    应用程序不会出现在 MacBook 的摄像头和麦克风隐私设置中

    • 5 个回答
  • Martin Hope
    Vickel Firefox 不再允许粘贴到 WhatsApp 网页中? 2023-08-18 05:04:35 +0800 CST
  • Martin Hope
    Saaru Lindestøkke 为什么使用 Python 的 tar 库时 tar.xz 文件比 macOS tar 小 15 倍? 2021-03-14 09:37:48 +0800 CST
  • Martin Hope
    CiaranWelsh 如何减少“vmmem”进程的消耗? 2020-06-10 02:06:58 +0800 CST
  • Martin Hope
    Jim Windows 10 搜索未加载,显示空白窗口 2020-02-06 03:28:26 +0800 CST
  • Martin Hope
    andre_ss6 远程桌面间歇性冻结 2019-09-11 12:56:40 +0800 CST
  • Martin Hope
    Riley Carney 为什么在 URL 后面加一个点会删除登录信息? 2019-08-06 10:59:24 +0800 CST
  • Martin Hope
    zdimension 鼠标指针在 Windows 中按下的箭头键上移动? 2019-08-04 06:39:57 +0800 CST
  • Martin Hope
    jonsca 我所有的 Firefox 附加组件突然被禁用了,我该如何重新启用它们? 2019-05-04 17:58:52 +0800 CST
  • Martin Hope
    MCK 是否可以使用文本创建二维码? 2019-04-02 06:32:14 +0800 CST
  • Martin Hope
    SoniEx2 更改 git init 默认分支名称 2019-04-01 06:16:56 +0800 CST

热门标签

windows-10 linux windows microsoft-excel networking ubuntu worksheet-function bash command-line hard-drive

Explore

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

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve