I am trying to create a batch file to rename network drives, since 'Label' does not work. I have created a PS1 script which works, but I am trying to get the script into a single Batch file so I can run handle several sequential non-powershell commands. My PS1 is as follows:
$ShellObject = New-Object –ComObject Shell.Application
$DriveMapping = $ShellObject.NameSpace('Z:')
$DriveMapping.Self.Name = 'DataStore'
My current Batch File command is as follows:
powershell -Command " $ShellObject = New-Object –ComObject Shell.Application; $DriveMapping = $ShellObject.NameSpace('Z:'); $DriveMapping.Self.Name = 'DataStore'"
Which gives me the following error:
The property 'Name' cannot be found on this object. Verify that the property exists and can be set...
My original reference on how to approach this was from here:How to run powershell command in batch file which included the ampersand.
When I could not get it to work I then tried the format here:Run powershell command from cmd
At this point I have tried a few different arrangements of semi-colons, quotes, apostrophes, etc without any success. This seems like a simple problem and appreciate any help offered.