Guest User

Untitled

a guest
Jan 19th, 2017
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.85 KB | None | 0 0
  1. <#
  2. .SYNOPSIS
  3.  
  4. Install Windows from a passed ISO.
  5. .DESCRIPTION
  6.  
  7. This command takes a path to a .iso file, mounts it, and starts setup.exe to begin windows installation.
  8. This should only be run on Windows PE instances.
  9. .PARAMETER ISOPath
  10.  
  11. This is the path to the .iso file that will be mounted, and used for the installation media.
  12. .EXAMPLE
  13.  
  14. InstallWindows -ISOPath "Z:\Windows\en_windows_10_enterprise_version_1607_updated_jul_2016_x64_dvd_9054264.iso"
  15. #>
  16. function InstallWindows
  17. {
  18. param (
  19. [Parameter(Mandatory=$true)]
  20. [string]$ISOPath
  21. )
  22.  
  23. $img = Mount-DiskImage -imagepath $ISOPath -PassThru
  24. Start-Process -FilePath "$(($img | Get-Volume).DriveLetter):\Setup.exe"
  25. }
  26.  
  27. <#
  28. .SYNOPSIS
  29.  
  30. Get information about versions of windows that are supported on an ISO.
  31. .DESCRIPTION
  32.  
  33. This command mounts a passed .iso file, and returns the output from the Get-WindowsImage function for \Sources\install.wim on said image.
  34. .PARAMETER ISOPath
  35.  
  36. This is the path to the .iso file that information will be retrieved from. Please ensure it is valid Windows installation media.
  37. .EXAMPLE
  38.  
  39. GetWindowsISOInfo -ISOPath "Z:\Windows\en_windows_10_enterprise_version_1607_updated_jul_2016_x64_dvd_9054264.iso" | Format-Table -Property ImageName, ImageSize
  40. #>
  41. function GetWindowsISOInfo
  42. {
  43. param (
  44. [Parameter(Mandatory=$true)]
  45. [string]$ISOPath
  46. )
  47.  
  48. $img = Mount-DiskImage -imagepath $ISOPath -PassThru
  49. Get-WindowsImage -ImagePath "$(($img | Get-Volume).DriveLetter):\sources\install.wim"
  50. $img | Dismount-DiskImage
  51. }
  52.  
  53. <#
  54. .SYNOPSIS
  55.  
  56. A helper method to mount network shares, with optional credentials.
  57. .DESCRIPTION
  58.  
  59. This command is designed to mount network shares to the Z: drive letter.
  60. It will automatically unmount any drives that are mounted at that location.
  61. If credentials are not passed, it will assume 'guest' for both the username and password.
  62. .PARAMETER NetworkPath
  63.  
  64. This is the network path that should be mounted, including volumes if need be.
  65. .PARAMETER NetworkUser
  66.  
  67. The username that should be used to connect to the network share.
  68. .PARAMETER NetworkPass
  69.  
  70. The password that should be used to connect to the network share.
  71. .EXAMPLE
  72.  
  73. MountNetShare -NetworkPath "\\Fileserver\Share"
  74. .EXAMPLE
  75.  
  76. MountNetShare -NetworkPath "\\Fileserver\Share\Folder\Subfolder"
  77. .EXAMPLE
  78.  
  79. MountNetShare -NetworkPath "\\Fileserver\SecureShare" -NetworkUser $username -NetworkPass $password
  80. #>
  81. function MountNetShare
  82. {
  83. param (
  84. [Parameter(Mandatory=$true)]
  85. [string]$NetworkPath,
  86. [string]$NetworkUser = "guest",
  87. [string]$NetworkPass = "guest"
  88. )
  89.  
  90. if(Test-Path Z:) {echo Remove-PSDrive -Name "Z"}
  91. $credentials = New-Object System.Management.Automation.PSCredential ($NetworkUser, (ConvertTo-SecureString $NetworkPass -AsPlainText -Force))
  92. New-PSDrive -Name "Z" -PSProvider FileSystem -Root $NetworkPath -Credential $credentials -Persist -Scope Global
  93. }
Add Comment
Please, Sign In to add comment