Last active
May 19, 2021 14:37
-
-
Save numbnet/c52a58febf0b033638f756defb388826 to your computer and use it in GitHub Desktop.
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
##*********************** ≠≠≠≠ *********************** | |
## start as ADMIN | |
$currentUser = New-Object Security.Principal.WindowsPrincipal $([Security.Principal.WindowsIdentity]::GetCurrent()) | |
$testadmin = $currentUser.IsInRole([Security.Principal.WindowsBuiltinRole]::Administrator) | |
if ($testadmin -eq $false) { | |
Start-Process powershell.exe -Verb RunAs -ArgumentList ('-noprofile -noexit -file "{0}" -elevated' -f ($myinvocation.MyCommand.Definition)) | |
exit $LASTEXITCODE | |
} | |
##*********************************************************** | |
## виртуальный диск в формате VHDX | |
#New-Item -Path $env:SYSTEMDRIVE\ -Name 'VHD' -ItemType Directory; | |
## Create new VHD | |
$DLetter = "B" | |
$vhdpath = "$env:SYSTEMDRIVE\VHD\${DLetter}.vhdx" | |
$PCName = "$env:COMPUTERNAME" | |
$vhdsize = 512GB | |
$vhdBSize = 33554432 | |
$vhdPSSize = 4096 | |
$vhdLSSize = 512 | |
echo " == CREATE $vhdpath ==" | |
Start-Sleep -Seconds 5 | |
New-VHD -Path $vhdpath -Dynamic -SizeBytes $vhdsize -BlockSizeBytes $vhdBSize -ComputerName $PCName -LogicalSectorSizeBytes $vhdLSSize -PhysicalSectorSizeBytes $vhdPSSize | Mount-VHD -Passthru | Initialize-Disk -Passthru | New-Partition -DriveLetter ${DLetter} -UseMaximumSize | Format-Volume -FileSystem NTFS -Confirm:$false -Force | |
echo "END" | |
##********************************************** | |
$vhdpath = "$env:SYSTEMDRIVE\VHD\A.vhdx"; | |
Dismount-VHD -Path "$vhdpath" -Passthru; | |
Mount-VHD -Path "$vhdpath" –PassThru | Get-Disk | Get-Partition | Set-Partition -NewDriveLetter A | |
#Register-ScheduledTask -Xml "$env:SYSTEMDRIVE\PS\VHD\automountvhdx\automountvhd.xml" -TaskName "RunAsAdmin" | |
########################################################### | |
## new task Add | |
Get-Command -Module ScheduledTasks | |
#при загрузке компьютера, первая строка должна быть такой: | |
$Trigger= New-ScheduledTaskTrigger -AtStartup | |
#Если нужно выполнять задание при входе пользователя: | |
#$Trigger= New-ScheduledTaskTrigger –AtLogon | |
## в определенное время | |
#$Trigger = New-ScheduledTaskTrigger -At 10:00am -Daily | |
$User = "NT AUTHORITY\SYSTEM" | |
$TaskName = "TEST" | |
#$Action= New-ScheduledTaskAction -Execute "PowerShell.exe" -Argument “-NoProfile -NoLogo -NonInteractive -ExecutionPolicy Bypass -File C:\PS\StartupScript.ps1" | |
$Action = New-ScheduledTaskAction -Execute "PowerShell.exe" -Argument "Dismount-DiskImage -ImagePath $env:SYSTEMDRIVE\D\DRIVE\${DLetter}.vhdx;Mount-DiskImage -ImagePath $env:SYSTEMDRIVE\D\DRIVE\VDrive.vhd -Access ReadWrite -StorageType VHD" | |
Register-ScheduledTask -TaskName "$TaskName" -Trigger $Trigger -User $User -Action $Action -RunLevel Highest –Force | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment