Windows Server 2008
--
Questions
--
Followers
Top Experts
Wanted to run disk2vhd nightly on the server and have it backup to a NAS devicea and/or usb drive.....wanted this to be automated and if possible to have it delete the vhd previous on the device....
Does anyone have a script for this???
I have no nothing about scripting and have searched but found nothing...
Any help is appreciated>>>>.
Zero AI Policy
We believe in human intelligence. Our moderation policy strictly prohibits the use of LLM content in our Q&A threads.
@echo off
net use Y: \\path-to-your-networkshare /u:administrator passowrd
if exist Y:\test.vhd del Y:\test.vhd
disk2vhd C: Y:\test.vhd
 line # 2, replace \\path-to-your-networkshar
It will map a network Drive Y: and create image of your C: in the Y: drive as a file name test. before that it will del the existing file if present.
let me know if you want to modify something






EARN REWARDS FOR ASKING, ANSWERING, AND MORE.
Earn free swag for participating on the platform.
Thanks for all your help....
Â
$UNCPathToShare="\\NAS\backup"
$DriveLetter="x:"
$filename = (get-date -uformat %d%b%y) + "_" `
+ $Env:COMPUTERNAME + ".vhd"
$drive = new-object -com wscript.network
$drive.MapNetworkDrive($DriveLetter, $UNCPathToShare)
c:\disk2vhd.exe c: d: ($driveletter + "\" + $filename)
$backups = dir x: *.vhd
if ($backups.Count -gt 1) {
foreach ($backup in $backups) {
remove-item ($driveletter + "\" + $backup) `
-Exclude $filename
}
}
$drive.RemoveNetworkDrive($DriveLetter)
Change the path for $UNCPathToShare to whatever the share is that your exporting to.
I can't get disk2vhd to work on my machine period via the command line, so I'm not 100% certain that this will even run (have you been successful running this from command line?).
The file name is today's date and the machine's hostname.
The script will delete any other backup aside from Today's backup, so long as there is more than one file in the folder that is .vhd (this runs after the export, so there should be two files and it will delete the older one).
Note that if you have never used powershell to run scripts, you'll need to set the execution level. Open Powershell.exe and run
Set-ExecutionPolicy remotesigned -force

Get a FREE t-shirt when you ask your first question.
We believe in human intelligence. Our moderation policy strictly prohibits the use of LLM content in our Q&A threads.






EARN REWARDS FOR ASKING, ANSWERING, AND MORE.
Earn free swag for participating on the platform.
Your script worked fine for me up to creating the vhd, but i'm having am struggling to get the removal of previous .vhd to work. Seems it fails at the Exclude command. Got any further ideas. Thanks in advance.
Missing expression after unary operator '-'.
At C:\mapdrive.ps1:20 char:15
+ Â Â Â Â Â Â Â - <<<<Â Exclude $filename
  + CategoryInfo      : ParserError: (-:String) [], Pars
  + FullyQualifiedErrorId : MissingExpressionAfterOper
Hope this helps!!
$filename = (get-date -uformat %d%b%y) + "_" `
      + $Env:COMPUTERNAME + ".vhd"
$DriveLetter="w:"
c:\disk2vhd c: ($driveletter + "\" + $filename) | wait-job
Â
cd $driveletter
remove-item .\* -exclude "$filename",admin* -force

Get a FREE t-shirt when you ask your first question.
We believe in human intelligence. Our moderation policy strictly prohibits the use of LLM content in our Q&A threads.
Windows Server 2008
--
Questions
--
Followers
Top Experts
Windows Server 2008 and Windows Server 2008 R2, based on the Microsoft Vista codebase, is the last 32-bit server operating system released by Microsoft. It has a number of versions, including including Foundation, Standard, Enterprise, Datacenter, Web, HPC Server, Itanium and Storage; new features included server core installation and Hyper-V.