Skip to content

Instantly share code, notes, and snippets.

View mczerniawski's full-sized avatar

mczerniawski mczerniawski

View GitHub Profile
@mczerniawski
mczerniawski / LAPS_CheckOUPermissions.ps1
Last active September 11, 2017 15:34
Check OU permissions
$OUsServers = @('OU=TestBedSecurity,OU=Servers,DC=contoso,DC=com')
$OUsWorkstations =@('OU=TestBedSecurity,OU=Workstations,DC=contoso,DC=com')
$OUsServers | ForEach-Object {
Find-AdmPwdExtendedRights -identity $_ | fl
}
$OUsWorkstations | ForEach-Object {
Find-AdmPwdExtendedRights -identity $_ | fl
}
@mczerniawski
mczerniawski / LAPS_OUPermissions.ps1
Last active September 11, 2017 15:19
Alter OU permissions for LAPS
$OUsServers | ForEach-Object {
$serverProps = @{
Identity = $_
AllowedPrincipals = $ServerGroupProps.SamAccountName
}
Set-AdmPwdComputerSelfPermission -OrgUnit $_
Set-AdmPwdReadPasswordPermission @serverProps
}
@mczerniawski
mczerniawski / LAPS_GetPassword.ps1
Created September 11, 2017 14:41
LAPS Get-Password
PS> Get-AdmPwdPassword -ComputerName SomeComputer
ComputerName DistinguishedName Password ExpirationTimestamp
------------ ----------------- -------- -------------------
SomeComputer CN=SomeComputer,OU=TestBed,OU=Ser... ; 5G#cnz94&;Oq1 29.09.2017 13:30:42
$disks=Get-PhysicalDisk | where {$_.operationalstatus -eq 'Transient Error'}
#Set disks to retired state
$disks | Select-Object UniqueId | ForEach-Object {
Set-PhysicalDisk -UniqueId $PSItem.UniqueId -Usage Retired
}
#remove disks from pool
$disks | ForEach-Object {
Remove-PhysicalDisk -PhysicalDisks $PSItem -StoragePoolFriendlyName 'S2D on HVCL0' -Confirm:$false
$cluster = 'cluster'
$HVNodesActive = Get-ClusterNode -Cluster $cluster | where {$_.State -eq 'UP'}
$AllVMs = Get-VM -ComputerName $HVNodesActive | select Name,Path,ComputerName
#MOVE VMS where Storage IS
foreach ($hvhost in $HVNodesActive) {
foreach ($VM in ($AllVMs | where {$_.ComputerName -ne $hvhost -AND $_.Path -match $hvhost} ).Name) {
Get-ClusterGroup $VM -Cluster $cluster | Move-ClusterVirtualMachineRole -Node $hvhost -Wait 0 -ErrorAction SilentlyContinue
}
}
$cluster = 'cluster'
$HVNodesActive = Get-ClusterNode -Cluster $cluster | where {$_.State -eq 'UP'}
$AllVMs = Get-VM -ComputerName $HVNodesActive | select Name,Path,ComputerName
#region Workflow declaration
Workflow Invoke-ParallelLiveMigrateStorage
{
Param (
[parameter(Mandatory=$true)]
$VMList,
$clusterName = 'YourCLusterName'
Get-VM -computername (Get-ClusterNode -Cluster $clusterName).Name |
Get-VMDvdDrive |
Where-Object {$null -ne $_.Path} |
Select-Object VMName,ComputerName,Path |
Out-GridView -PassThru | ForEach-Object {
Set-VMDvdDrive -Path $null -ComputerName $PSItem.ComputerName -VMName $PSItem.VMName -Passthru
}
New-ItemProperty -Path HKLM:\SYSTEM\CurrentControlSet\Services\W32Time\TimeProviders\VMICTimeProvider -Name Enabled -Value 0 –Force
w32tm /config /manualpeerlist:"212.244.36.227 80.50.231.226 pool.ntp.org" /syncfromflags:manual /reliable:yes /update
w32tm /config /update
Stop-Service w32time
sleep(5)
Start-Service w32time
w32tm /resync /rediscover
w32tm /query /source
w32tm /config /syncfromflags:domhier /reliable:no
w32tm /config /update
Stop-Service w32time
sleep(5)
Start-Service w32time
w32tm /resync /rediscover
w32tm /query /source