This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $StorageJobIDs = Get-StorageJob | Select-Object ObjectID | Select-String -Pattern '([A-Za-z0-9]{8}\-?){1}([A-Za-z0-9]{4}\-?){3}([A-Za-z0-9]{12})' -AllMatches | | |
| Select-Object -ExpandProperty Matches | | |
| Select-Object -ExpandProperty Value -Last 1 | |
| foreach ($objectId in $StorageJobIDs) { | |
| Get-VirtualDisk | Where-Object {$_.ObjectId -match $objectID} | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $StorageJobs = Get-StorageJob | |
| foreach ($stJob in $StorageJobs) { | |
| foreach ($jobObjectID in ($stJob | Select-Object -ExpandProperty ObjectId)) { | |
| $objectID = $jobObjectID | Select-String -Pattern '([A-Za-z0-9]{8}\-?){1}([A-Za-z0-9]{4}){1}' -AllMatches | | |
| Select-Object -ExpandProperty Matches | | |
| Select-Object -ExpandProperty Value -Last 1 | |
| $vdisk = Get-VirtualDisk | Where-Object {$_.ObjectId -match $objectID} | |
| [PSCustomObject]@{ | |
| VirtualDiskName = $vdisk.FriendlyName | |
| HealthStatus = $vdisk.HealthStatus |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function Get-StorageJobReport { | |
| <# | |
| .SYNOPSIS | |
| Get current storage jobs on cluster. Returns additional information from Get-VirtualDisk. | |
| .DESCRIPTION | |
| If there are storageJobs running on the cluster will match each job to virtual disk and return custom object. | |
| .PARAMETER Cluster | |
| Hyper-V cluster name. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function Get-LAPSCredential { | |
| <# | |
| .SYNOPSIS | |
| Retrieves LAPS password from AD and creates Credential Object | |
| .DESCRIPTION | |
| Using Local Administrator Password Solution cmdlet Get-AdmPwdPassword will query AD for ms-Mcs-AdmPwd attribute. Will use retrieved password to create Credential Object | |
| .PARAMETER ComputerName | |
| ComputerName to search for LAPS password |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $ComputerName = 'SomeComputer' | |
| $LAPSPassword = (Get-AdmPwdPassword -ComputerName $ComputerName -ErrorAction SilentlyContinue).Password | |
| If ($LAPSPassword) { | |
| $LocalAdminPassword = ConvertTo-SecureString -String $LAPSPassword -AsPlainText -Force | |
| $LocalAdminCredential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList "$ComputerName\Administrator", $LocalAdminPassword | |
| $LocalAdminCredential | |
| } | |
| Else { | |
| Write-error "No LAPS password for computer {$ComputerName}" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $ComputerName = 'SomeComputer' | |
| Invoke-Command -ComputerName $ComputerName -Credential (Get-LAPSCredential -ComputerName $ComputerName) -ScriptBlock { | |
| Get-Service -Name BITS | Stop-Service | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Get-ADComputer -filter * -properties ms-Mcs-AdmPwd | | |
| Where-Object {$null -ne $_."ms-Mcs-AdmPwd"} | | |
| Select-Object samaccountname,ms-Mcs-AdmPwd |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $driveLetter = (get-disk | Where-Object {$_.PartitionStyle -eq 'RAW'} | Initialize-Disk -PartitionStyle GPT -PassThru | New-Partition -AssignDriveLetter -UseMaximumSize ).DriveLetter | |
| Format-Volume -NewFileSystemLabel 'DATA' -FileSystem 'ReFS' -DriveLetter $driveLetter -Force -confirm:$false |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function Format-RemoteDrive { | |
| <# | |
| .SYNOPSIS | |
| Formats all RAW drives on a remote system. | |
| .DESCRIPTION | |
| Using Invoke-Command will connect to remote system (ComputerName) and will format all RAW drives with given properties | |
| .PARAMETER ComputerName | |
| Name of a remote system to connect to using Invoke-Command. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $VMName = 'SomeVM' | |
| #Get VM disk path. Assuming there's only one VHD here | |
| $VHDPath = Get-VMHardDiskDrive $VMName | Select-Object -ExpandProperty Path | |
| #Verify VHD information, including current size | |
| Get-VHD -Path $VHDPath | |
| #Expand the disk | |
| $newSize = 120GB | |
| Resize-VHD -Path $VHDPath -SizeBytes $newSize |