Format disk on remote machine via Powershell?

Hi,

I got this really  nice Powershell script that adds an extra disk to a vm (vmware) then formats it to E-drive.
However, it does not work on Windows 7 :-(

Any idea howto make it work/convert it so it does work? The get-disk does not work and the import-module storage (which uses get-disk) either.
Thanks for your input!

					$driveletter = 'E'
					$sb = {
						$Disk = Get-Disk | Where partitionstyle -eq 'raw'
						set-disk -Number $Disk.Number -IsOffline $false
						set-disk -Number $Disk.Number -IsReadOnly $false
						Get-Disk $Disk.Number | Initialize-Disk -PartitionStyle MBR -PassThru -Confirm:$false | New-Partition -AssignDriveLetter -UseMaximumSize | Format-Volume -FileSystem NTFS -NewFileSystemLabel "Data" -Confirm:$false
						if ($(Get-Partition -DiskNumber 1).DriveLetter -ne 'E')
						{ Set-Partition -DiskNumber $Disk.Number -NewDriveLetter $using:driveletter -PartitionNumber 1 }
						
					} #EndIfConnected
					Invoke-Command -ScriptBlock $sb -ComputerName $computername

Open in new window


J
janhoedtAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Andrew Hancock (VMware vExpert / EE MVE^2)VMware and Virtualization ConsultantCommented:
what OS does it work in ?

does it work in any OS now, or has the command been deprecated...
1
ITguy565Commented:
1
janhoedtAuthor Commented:
Windows 7.
0
Redefine Your Security with AI & Machine Learning

The implications of AI and machine learning in cyber security are massive and constantly growing, creating both efficiencies and new challenges across the board. Check out our on-demand webinar to learn more about how AI can help your organization!

janhoedtAuthor Commented:
It works in Windows 10, not in W7, as mentioned in initial question.
0
Andrew Hancock (VMware vExpert / EE MVE^2)VMware and Virtualization ConsultantCommented:
is this the exact script and complete script which adds a virtual disk to a VMware Virtual machine, just seems to contain the OS portion ?
0
janhoedtAuthor Commented:
just the format option
0
Shaun VermaakTechnical Specialist IVCommented:
0
janhoedtAuthor Commented:
So there is no other way to do this remote/via Powershell?
0
ITguy565Commented:
@janhoedt

I would agree with @Shawn on this, Upgrading powershell would be your best option as it would allow you to use that script in it's original state rather than having to reverse engineer the script to work with legacy code. The path of least resistance in this case would be just to upgrade Powershell.
0
janhoedtAuthor Commented:
Upgraded, but command is still not possible.
0
ITguy565Commented:
can you post the version information for powershell on that computer?
0
Shaun VermaakTechnical Specialist IVCommented:
Where did you upgrade PowerShell on?
0
janhoedtAuthor Commented:
Not sure about the machine anymore. Have changed disk manually afterwards. So you think on a W7 with Powershell 5, it SHOULD work?
Remember that I checked via PS and got 5.0 back.
0
ITguy565Commented:
Yes, I think it should work in windows 7 Powershell Ver 5.0


Your Comment
by:ITguy565


ID: 42512511
2018-03-26
get-disk was implemented in Powershell V5

http://www.tomsitpro.com/articles/powershell-for-storage,2-764.html 
0
janhoedtAuthor Commented:
Powershell version

Major  Minor  Build  Revision
-----  -----  -----  --------
5      0      10586  117  

In a remote session:
get-disk
The term 'get-disk' is not recognized as the name of a cmdlet, function, script file
0
ITguy565Commented:
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Andrew Hancock (VMware vExpert / EE MVE^2)VMware and Virtualization ConsultantCommented:
In that case Author cannot do what he wants in Windows 7 so question is moot!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Powershell

From novice to tech pro — start learning today.