添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接

上接Windwos升级映像部署1

背景:由于在企业管理中大多数用户没有管理员权限,因此在升级OS作业时只能通过暂时开放权限或WSUS部署,但前者存在安全风险,后者无法部署经过定制的ISO映像文件(反正我没找到)

由Landesk,SCCM等终端管理软件可部署用户可用任务,更加安全高效,由用户选择空闲的时间段自行升级。安装文件已在前期部署放入用户磁盘内。

在用户权限下以管理员运行Setup.exe

Set-ExecutionPolicy -ExecutionPolicy RemoteSigned
#该命令用于修改powershell脚本运行权限 可以在本机运行以上命令 但需要手动确认

#由于下面的ps2exe代码运行过程为生成PS脚本在C盘Temp文件并运行( 完成执行后PS脚本会自动删除,但这个过程也有泄露管理员密码的风险,并不是绝对安全 ),本质上还是Powershell,因此修改权限在用户电脑上可能是必须的(Windows默认都不会开启)

#如果为批量部署,可以在组策略中为用户PC修改该权限

关于powershell脚本运行权限的信息: 关于执行策略 - PowerShell | Microsoft Docs

$uname="<Domain>\<UserName>"
$pwd=ConvertTo-SecureString  "<Password>" -AsPlainText -Force
#账户密码(建议使用临时建立的本地管理员,在升级作业结束后禁用或删除)
$cred=New-Object System.Management.Automation.PSCredential($uname,$pwd)
#密码凭据生成
mount-DiskImage -ImagePath "D:\TEST.iso"
#镜像挂载(由于mount命令无法指定挂载的盘符,无法确认用户安装文件所在路径,没想出好办法只能一个个TEST)
if (TEST-Path E:\setup.exe) {Start-Process -FilePath  "E:\setup.exe" -Credential $cred}
if (TEST-Path F:\setup.exe) {Start-Process -FilePath  "F:\setup.exe" -Credential $cred}
if (TEST-Path G:\setup.exe) {Start-Process -FilePath  "G:\setup.exe" -Credential $cred}

#Powershell也能完成提权作业,但管理员密码泄露风险比exe更大

附录·Powershell转EXE脚本

(网上引用,去除了弹出的messageBOX和增加了等待程序执行的时间,可以等待部署脚本运行)

更新Github工具:https://github.com/MScholtes/TechNet-Gallery/

PS1 TO EXE 很好用

function Convert-PS1ToExe
    param(
    [Parameter(Mandatory=$true)]
    [ValidateScript({$true})]
    [ValidateNotNullOrEmpty()]    
    [IO.FileInfo]$ScriptFile
    if( -not $ScriptFile.Exists)
        Write-Warning "$ScriptFile not exits."
        return
    [string]$csharpCode = @'
    using System;
    using System.IO;
    using System.Reflection;
    using System.Diagnostics;
    namespace LoadXmlTestConsole
        public class ConsoleWriter
            private static void Proc_OutputDataReceived(object sender, System.Diagnostics.DataReceivedEventArgs e)
                Process pro = sender as Process;
                Console.WriteLine(e.Data);
            static void Main(string[] args)
                // Set title of console
                Console.Title = "Powered by PSTips.Net";
                // read script from resource
                Assembly ase = Assembly.GetExecutingAssembly();
                string scriptName = ase.GetManifestResourceNames()[0];
                string scriptContent = string.Empty;
                using (Stream stream = ase.GetManifestResourceStream(scriptName))
                using (StreamReader reader = new StreamReader(stream))
                    scriptContent = reader.ReadToEnd();
                string scriptFile = Environment.ExpandEnvironmentVariables(string.Format("%temp%\\{0}", scriptName));
                    // output script file to temp path
                    File.WriteAllText(scriptFile, scriptContent);
                    ProcessStartInfo proInfo = new ProcessStartInfo();
                    proInfo.FileName = "PowerShell.exe";
                    proInfo.CreateNoWindow = true;
                    proInfo.RedirectStandardOutput = true;
                    proInfo.UseShellExecute = false;
                    proInfo.Arguments = string.Format(" -File {0}",scriptFile);
                    var proc = Process.Start(proInfo);
                    proc.OutputDataReceived += Proc_OutputDataReceived;
                    proc.BeginOutputReadLine();
                    proc.WaitForExit();
                catch (Exception ex)
                    Console.WriteLine("Hit Exception: {0}", ex.Message);
                finally
                    // delete temp file
                    if (File.Exists(scriptFile))
                        File.Delete(scriptFile);
    # $providerDict
    $providerDict = New-Object 'System.Collections.Generic.Dictionary[[string],[string]]'
    $providerDict.Add('CompilerVersion','v4.0')
    $codeCompiler = [Microsoft.CSharp.CSharpCodeProvider]$providerDict
    # Create the optional compiler parameters
    $compilerParameters = New-Object 'System.CodeDom.Compiler.CompilerParameters'
    $compilerParameters.GenerateExecutable = $true
    $compilerParameters.GenerateInMemory = $true
    $compilerParameters.WarningLevel = 3
    $compilerParameters.TreatWarningsAsErrors = $false
    $compilerParameters.CompilerOptions = '/optimize'
    $outputExe = Join-Path $ScriptFile.Directory "$($ScriptFile.BaseName).exe"
    $compilerParameters.OutputAssembly =  $outputExe
    $compilerParameters.EmbeddedResources.Add($ScriptFile.FullName) > $null
    $compilerParameters.ReferencedAssemblies.Add( [System.Diagnostics.Process].Assembly.Location ) > $null
    # Compile Assembly
    $compilerResult = $codeCompiler.CompileAssemblyFromSource($compilerParameters,$csharpCode)
    # Print compiler errors
    if($compilerResult.Errors.HasErrors)
        Write-Host 'Compile faield. See error message as below:' -ForegroundColor Red
        $compilerResult.Errors | foreach {
            Write-Warning ('{0},[{1},{2}],{3}' -f $_.ErrorNumber,$_.Line,$_.Column,$_.ErrorText )
         Write-Host 'Compile succeed.' -ForegroundColor Green
         "Output executable file to '$outputExe'"

"本站所有文章均为原创,欢迎转载,请注明文章出处:https://blog.csdn.net/weixin_57323573?type=blog。本人习惯不定期对自己的博文进行修正和更新,因此请访问出处以查看本文的最新版本。"

在ILLiad服务器上重新启动IIS / ILLiad服务 在运行Jenkins应用程序的服务器上引用环境变量。 对Cent-OS7使用Microsoft的Docker Powershell映像。 步骤如下: 构建Docker映像 导入illiad.iis.reset.ps1脚本和illiad.services.reset.ps1 运行脚本: 创建变量,包括来自Jenkins服务器的环境变量 在ILLiad服务器上输入Powershell会话 重新启动IIS服务或ILLiad服务 用于将Windows部署到VHDX或物理磁盘的PowerShell模块 该模块提供了将WIM快速换为可预订VHD(x)并创建完全更新的WIM / VHD(x)的工具。 从CD创建补丁映像或仅从CD创建基准VHDX过去一直需要将MDT部署到计算机上,然后修补并捕获映像。 使用MDT非常耗时。 将WIM直接换为VHDX更为有效。 过去这是通过Convert-WindowsImage.ps1 虽然这是一个很棒的工具,但我发现它有很多缺点 这是一个巨大的文件(就像单一用途的PowerShell脚本一样) 越野车(大多数已在近期修复) 它不是模块(这是我最大的遗憾) Jeffrey Hicks写了两篇很棒的文章,介绍了创建Gen2 VHDX并从WIM填充它的过程 本杰明·阿姆斯特朗(Benjamin Armstrong)创建了一个脚本,用于创建修 发现就LocalMachine有选项。在这个情况下,我用如下命令设置权限。 Set-ExecutionPolicy RemoteSigned -Scope CurrentUser 后面很重要,设置好以后,要重启Pow Ps1 To Exe是款将PowerShell脚本换为EXE可执行文件的软件。同时软件非常小巧,功能实用,软件还支持各国的语言,有需要的小伙伴们不要错过了。(点击图片查看高清大图)【软件特色】1、Ps1 To Exe 支持多种语言2、Ps1 To Exe使用简单,占用内存少【安装方法】1、首先下载Ps1 To Exe安装程序压缩包,然后解压缩,得到exe文件;2、鼠标双击下载下来的安装程序。如果... 单击"开始"按钮以打开"开始"菜单, 展开Windows PowerShell 文件夹。右键单击 Windows PowerShell。选择"以管理员身份运行"。同时按键盘上的 Windows + R 键以打开"运行"框。键入 powershell 并按 Enter 键。这将以管理员身份运行PowerShell。在任务栏在搜索框中键入 powershell ,右键单击结果上的 Windows PowerShell,然后选择"以管理员身份运行"。 本文描述如何加密 PowerShell 中的敏感信息,从而避免敏感信息(诸如密码)在代码中被显式的展现出来。这里我们使用 ConvertFrom-SecureString 命令来完成加密操作,需要注意的是,如果我们没有指定Key,那么,将采用基于 Windows 内置的 DPAPI 进行数据的加密。这种情况下,原文的加密和解密必须在同一台机器上,且基于同一个User去进行。 ConvertFrom $r = (cmd /c mount ${CONFIG_DIR_NFS_PATH} S:) $DeviceId = Get-CimInstance -Query "Select * from Win32_volume where name like 'S%'"| Select-Object -ExpandProperty DeviceID rm -R ${CONFIG_DIR_ENGINE_PATH} mkdir -p ${CONFIG_DIR_ENGINE_PATH} mountvol ${CONFIG 您可以使用下面的代码创建一个PowerShell脚本来以管理员身份运行映射网络代码: if (!([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrato... Powershell scripts are used to complete tasks simply running script files. This provides easy to use ways to run the same commands again and again. Scripts also used to share the experience with other... 第1步: 同时按下Windows + R键以弹出“运行”对话框。 第2步: 在框中键入PowerShell,然后单击OK(确定)按钮。 普通的Windows PowerShell将以当前用户身份启动。 第3步: 键入命令start-process PowerShell -verb runas,然后按“enter”键。 第4步: 以上命令将以管理员身份提升Windows PowerShell的权限。 方法2. 使用Cortana搜索栏以管理员身份运行