• Status: Solved
  • Priority: Low
  • Security: Public
  • Views: 58
  • Last Modified:

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
0
janhoedt
Asked:
janhoedt
  • 7
  • 5
  • 3
  • +1
1 Solution
 
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
Improve Your Query Performance Tuning

In this FREE six-day email course, you'll learn from Janis Griffin, Database Performance Evangelist. She'll teach 12 steps that you can use to optimize your queries as much as possible and see measurable results in your work. Get started today!

 
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/DeveloperCommented:
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/DeveloperCommented:
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
 
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Improved Protection from Phishing Attacks

WatchGuard DNSWatch reduces malware infections by detecting and blocking malicious DNS requests, improving your ability to protect employees from phishing attacks. Learn more about our newest service included in Total Security Suite today!

  • 7
  • 5
  • 3
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now