• 【转】如何在 Windows 10、Windows 8 启动时自动装载 VHD


    如何在 Windows 10、Windows 8.1 和 Windows 8 启动时自动装载 VHD (PowerShell)

    简介

    此 PowerShell 脚本示例展示如何在 Windows 10、Windows 8.1 和 Windows 8 启动时自动装载 VHD。

    应用场景

    用户重启计算机时,需要重新装载所有已装载的 VHD 文件。以下脚本用于解决此问题。

    脚本

    步骤 1:右键单击 PowerShell,然后选择“以管理员身份运行”。

    步骤 2:然后,将此脚本拖动到 PowerShell 控制台并输入如下所示的命令。

    注意

    如果你不希望在启动时装载 VHD 文件,则可以运行 schtasks,找到计划任务 MountVHD,然后将其删除。
    如果 VHD 文件尚未执行“初始化磁盘”或“新建简单卷”操作,则无法通过 Windows 磁盘驱动器查看该 VHD。若要了解如何执行“初始化磁盘”和“新建简单卷”操作,请查看以下文档作为参考:
    初始化磁盘
    新建简单卷

    param
    (
        [Parameter(Mandatory=$true)]
        [String]$Path
    )
    
    if(test-path -Path $path)
    {
        
        #Create diskpart configuration file
        $content = "select vdisk file= `"$path`"`nattach vdisk" 
        #Output the file and store the file into user profile folder
        out-file -InputObject $content -FilePath "$env:USERPROFILEMountVHD.txt" -Encoding ascii -Force 
        #Add schedule task
        schtasks /create /tn "MountVHD" /tr "diskpart.exe /s '$env:USERPROFILEMountVHD.txt'" /sc ONLOGON /ru SYSTEM
    
        write-host "Operation executed successfully. The specified VHD file will be mounted next logon."
    }
    Else
    {
        Write-Warning "The path is invalid."
    }
    

    https://gallery.technet.microsoft.com/scriptcenter/How-to-automatically-mount-d623ce34

  • 相关阅读:
    关于Response.End的亦常
    关于web.config
    本地打印机的设置
    xml的操作
    javascript定义对象的几种简单方法
    WindowsXP下共享无线网络设置步骤
    第四章:使用Rich控件
    第五章母版页
    第八章数据访问概述
    对lock(obj)中的obj的理解
  • 原文地址:https://www.cnblogs.com/hanfan/p/13600461.html
Copyright © 2020-2023  润新知