?
Solved

PowerShell Script in windows 2012 R2 is not working

Posted on 2014-04-19
5
Medium Priority
?
738 Views
Last Modified: 2014-05-26
Dear All,

i create a new PowerShell script "CreateVM.Ps1" and i run it from PowerShell in windows 2012 R2, the problem is; the first command done, but the remaining is not running, the script to create VHDX, below:

NEW-VHD -Fixed C:\ClusterStorage\Exch-DB1\Exch-DB1.vhdx -SizeBytes 495GB
NEW-VHD -Fixed C:\ClusterStorage\Exch-DB2\Exch-DB2.vhdx -SizeBytes 495GB
NEW-VHD -Fixed C:\ClusterStorage\Exch-DB3\Exch-DB3.vhdx -SizeBytes 495GB
NEW-VHD -Fixed C:\ClusterStorage\Exch-DB4\Exch-DB4.vhdx -SizeBytes 495GB
NEW-VHD -Fixed C:\ClusterStorage\Exch-DB5\Exch-DB5.vhdx -SizeBytes 495GB
NEW-VHD -Fixed C:\ClusterStorage\Exch-DB6\Exch-DB6.vhdx -SizeBytes 495GB


do i have to do anything in between the command above?
0
Comment
Question by:Rhala
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 25

Expert Comment

by:Zephyr ICT
ID: 40010740
Are you getting any errors?

Does it work like this:

NEW-VHD -Path C:\ClusterStorage\Exch-DB6\Exch-DB6.vhdx -Fixed -SizeBytes 495GB

Remember, you can use -Whatif to see what the line does...
0
 
LVL 83

Expert Comment

by:David Johnson, CD, MVP
ID: 40010835
hyper-v\NEW-VHD -Fixed C:\ClusterStorage\Exch-DB1\Exch-DB1.vhdx -Size 4GB
hyper-v\NEW-VHD -Fixed C:\ClusterStorage\Exch-DB2\Exch-DB2.vhdx -Size 4GB
hyper-v\NEW-VHD -Fixed C:\ClusterStorage\Exch-DB3\Exch-DB3.vhdx -Size 4GB
hyper-v\NEW-VHD -Fixed C:\ClusterStorage\Exch-DB4\Exch-DB4.vhdx -Size 4GB
hyper-v\NEW-VHD -Fixed C:\ClusterStorage\Exch-DB5\Exch-DB5.vhdx -Size 4GB
hyper-v\NEW-VHD -Fixed C:\ClusterStorage\Exch-DB6\Exch-DB6.vhdx -Size 4GB

Open in new window

I have 2 hyper-v  modules so I had to select the right one.  Note the Size vs SizeBytes


ComputerName            : DC01
Path                    : C:\ClusterStorage\Exch-DB5\Exch-DB5.vhdx
VhdFormat               : VHDX
VhdType                 : Fixed
FileSize                : 4299161600
Size                    : 4294967296
MinimumSize             :
LogicalSectorSize       : 512
PhysicalSectorSize      : 4096
BlockSize               : 0
ParentPath              :
DiskIdentifier          : f431105f-e532-40f5-adb8-e964468d21fc
FragmentationPercentage : 0
Alignment               : 1
Attached                : False
DiskNumber              :
Key                     :
IsDeleted               : False
Number                  :

ComputerName            : DC01
Path                    : C:\ClusterStorage\Exch-DB6\Exch-DB6.vhdx
VhdFormat               : VHDX
VhdType                 : Fixed
FileSize                : 4299161600
Size                    : 4294967296
MinimumSize             :
LogicalSectorSize       : 512
PhysicalSectorSize      : 4096
BlockSize               : 0
ParentPath              :
DiskIdentifier          : 7af9b31c-e119-4157-8a8e-2cf2cb5b648c
FragmentationPercentage : 0
Alignment               : 1
Attached                : False
DiskNumber              :
Key                     :
IsDeleted               : False
Number                  :
0
 
LVL 19

Expert Comment

by:Kash
ID: 40049809
why not use loops to perform such an action. google "for loop" for powershell
0
 
LVL 71

Accepted Solution

by:
Qlemo earned 2000 total points
ID: 40050475
What Kash wanted to suggest (next time please do so, Kash!), is
foreach ($loc in 'Exch-DB1', 'Exch-DB2', 'Exch-DB3', 'Exch-DB4', 'Exch-DB5', 'Exch-DB6') {
  new-VHD -Fixed C:\ClusterStorage\$loc\$loc.vhdx -SizeBytes 495GB
}

Open in new window

But that does not change the issue at hand, probably. There has to be an error message stopping the script.
0
 
LVL 19

Expert Comment

by:Kash
ID: 40050758
i will do that Qlemo and not spend my time doing my paid job. Thanks for reminding me.
0

Featured Post

Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Previously, on our Nano Server Deployment series, we've created a new nano server image and deployed it on a physical server in part 2. Now we will go through configuration.
My attempt to use PowerShell and other great resources found online to simplify the deployment of Office 365 ProPlus client components to any workstation that needs it, regardless of existing Office components that may be needing attention.
In this Micro Tutorial viewers will learn how to use Windows Server Backup to create full image of their system. Tutorial shows how to install Windows Server Backup Feature on Windows 2012R2 and how to configure scheduled Bare Metal Recovery backup.…
This tutorial will walk an individual through the process of configuring basic necessities in order to use the 2010 version of Data Protection Manager. These include storage, agents, and protection jobs. Launch Data Protection Manager from the deskt…

718 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question