Skip to content

Instantly share code, notes, and snippets.

View mczerniawski's full-sized avatar

mczerniawski mczerniawski

View GitHub Profile
@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_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_CreateFileShare.ps1
Last active October 2, 2017 21:13
Create File share for GPO Installations for LAPS
$ShareName = 'GPOInstalls'
$RemoteChildFolder = 'LAPS'
$FileServer = 'FileServer1'
$LocalFilesPath = "C:\$ShareName"
$RemoteFilesPath = Join-Path -Path "\\$FileServer" -ChildPath $LocalFilesPath.Replace(':','$')
New-Item -Path (split-Path $RemoteFilesPath -Parent) -ItemType Directory -Name $ShareName
$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
}
}
$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
$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}
}
$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