powershelll Mount-DiskImage "The system cannot find the path specified." - powershell

I have a batch file I'm executing on Windows 10 through the "Deployment and Imaging Tools Environment"
powershell Mount-DiskImage ./%WORKSPACE%/W10-LTSB.iso
The environment variable WORKSPACE has been checked and contains a valid path that exists as does the file W10-LTSB.iso, however when this command is executed it results in:
Mount-DiskImage: The system cannot find the path specified.
At line:1 char:1
+ Mount-DiskImage ./CA20-4002-OperatingSystem-AIMB-216/W10-LTSB.iso
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (MSFT_DiskImage:ROOT/Microsoft/.../MSFT_DiskImage) [Mount-DiskImage], CimException
+ FullyQualifiedErrorId : HRESULT 0x80070003,Mount-DiskImage
Everything looks valid and has been checked many times, what does this message mean?

When a path starts with a dot/period ., it refers to the current directory. When a shell session starts, its current directory is configuration dependent.
For example, try running a Powershell session. It should default in c:\Users\<username>. Run a Powershell as admin and it usually defaults in C:\WINDOWS\system32.
When mounting a disk image with a path beginning with a dot
powershell Mount-DiskImage ./%WORKSPACE%/W10-LTSB.iso
will tell Mount-DiskImage to look the file from its current directory's subdir. Should the current directory be unexpected, Powershell's looking the file from wrong a place.
As for a solution, use absolute paths, or make sure the file is located in a path that's available via current directory (whatever it is).

Related

Powershell PSModule unc path

I am adding a UNC path, like "\\server\share\modules" to the user session env variable PSModule like this:
$env:PSModulePath = $env:PSModulePath + ";\\server\share\modules"
But, when I try to load a module from this path, I get an error
PS C:\> Import-Module WS_XML_MODULE
Import-Module : The specified module 'WS_XML_MODULE' was not loaded because no valid module file was found in any module directory.
At line:1 char:1
+ Import-Module WS_XML_MODULE
+ ~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ResourceUnavailable: (WS_XML_MODULE:String) [Import-Module], FileNotFoundException
+ FullyQualifiedErrorId : Modules_ModuleNotFound,Microsoft.PowerShell.Commands.ImportModuleCommand
Listing all the available modules, which should show the UNC path available modules, doesn't show me any of the UNC folder modules...
Get-Module -listavailable
Anybody knows why?
Thanks
Go this working...
I took a look at the system modules folder and the syntax of the folders and files are exacly the same, with dots separating words like Microsoft.Powershell.Something
I then changed the name of the PSM1 file to the same and got them into folder with the same name and BAmm.. in a heartbeat loaded all my modules.
Place the "WS_XML_MODULE.psm1 and WS_XML_MODULE.psd1" in the folder named "WS_XML_MODULE".
Make sure "WS_XML_MODULE" folder is located in "\\server\share\modules"
Note: Don't include the Module name in Path

Azure Function in PowerShell to untar file

I am trying to convert some a number of files compressed into a .tar.gz archive into a single file. To do so I need to first untar the file.
I have a copy of 7z.exe loaded into the directory, and calling the command locally works
.\7z.exe x *.tar.gz
I've uploaded the exe into the wwwroot/poshUntar directory alongside the run.ps1 file that gets executed, and using the online editor I can execute the powershell script. I would of course expect my function to fail generally since I'm not providing the variable values but I would not expect it to error about finding the 7z.exe file
.\7z.exe : The term '.\7z.exe' is not recognized as the name of a cmdlet,
function, script file, or operable program. Check the spelling of the name, or
if a path was included, verify that the path is correct and try again.
At D:\home\site\wwwroot\poshUntar\run.ps1:10 char:1
+ .\7z.exe x *.tar -o logs
+ ~~~~~~~~
+ CategoryInfo : ObjectNotFound: (.\7z.exe:String) [], CommandNot
FoundException
+ FullyQualifiedErrorId : CommandNotFoundException
What is the correct way to invoke an executable inside a PowerShell Azure Function?
I believe that you also need to upload 7z.dll into the wwwroot directory.
Could you try using the following code-segment in your script?
Set-Location D:\home\site\wwwroot\poshUntar
.\7z.exe x *.tar.gz
.\7z.exe x *.tar -ologs

Add-appxPackage deployment failed: does not find files

I am trying to deploy windows 10 app that I created to a laptop. In my computer everything goes fine, but in the laptop the Add-appPackage first recognizes the relevant package files, but when running the line in the script that makes the unbundle it fails and returns with:
' The system cannot find the file specified' eventhough the files exists.
I tried to make a deploy using the -register flag from working solution directory but the result was the same.
I use in my computer Windows 10 HOME and the Laptop is Windows 10 Pro but I think it does not matter.
The line in the script file generated by the visual studio packager which fails is:
Add-AppxPackage -Path $DeveloperPackagePath.FullName -DependencyPath $DependencyPackages.FullName -ForceApplicationShutdown
I checked the variables - they contain correct data.
Afterwards it outputs the error with the line:
$Error[0] # Dump details about the last error
that does not give me too much details about which file is missing as you can see in the full output:
C:\users\User\AlephBet_1.0.4.0_Test\Dependencies\x86\Microsoft.NET.Native.Framework.1.3.appx
C:\users\User\AlephBet_1.0.4.0_Test\Dependencies\x86\Microsoft.NET.Native.Runtime.1.3.appx
C:\users\User\AlephBet_1.0.4.0_Test\Dependencies\x86\Microsoft.VCLibs.x86.14.00.appx
C:\users\User\AlephBet_1.0.4.0_Test\Dependencies\x64\Microsoft.NET.Native.Framework.1.3.appx
C:\users\User\AlephBet_1.0.4.0_Test\Dependencies\x64\Microsoft.NET.Native.Runtime.1.3.appx
C:\users\User\AlephBet_1.0.4.0_Test\Dependencies\x64\Microsoft.VCLibs.x64.14.00.appx
Add-AppxPackage : The system cannot find the file specified.
The system cannot find the file specified.
At C:\users\User\AlephBet_1.0.4.0_Test\Add-AppDevPackage.ps1:388 char:13
+ Add-AppxPackage -Path $DeveloperPackagePath.FullName -Dep ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Add-AppxPackage], FileNotFoundException
+ FullyQualifiedErrorId : System.IO.FileNotFoundException,Microsoft.Windows.Appx.PackageManager.Commands.A ddAppx
PackageCommand
I tried also getting information with get-AppxLog but it does log the error.
What happens? What is missing? Is there a way to get more information about the error?
Where does Windows 10 put the appx? Is there a way to make a bypass and take the files from an existing executable version, something like .exe files and copy them as is to the laptop?

All commands failing in powershell (4.0.) Even "c:" and "cd" and "dir"

I'm not sure when this started... whenever I open PowerShell, I can't execute even the most basic commands. I always get the following error message:
PS C:\> dir
dir : Cannot find drive. A drive with the name '.' does not exist.
At line:1 char:1
+ dir
+ ~~~
+ CategoryInfo : ObjectNotFound: (.:String) [], DriveNotFoundException
+ FullyQualifiedErrorId : DriveNotFound
---
This had been working fine but now all of a sudden I can't do anything. I've tried removing PowerShell 4 and re-installing... no change. Sorry for the formatting here... It looks organized in my view above but the preview text looks horrid.
I don't remember ever having java installed, but looking at my regular %path% I see that %java_home% is in there, but the value is never used or defined anywhere. Once I removed that from my path, the error above went away.
Strange that it would even be an issue for powershell. You'd think it would just skip past a non-existent directory in my path and move onto the next one when resolving a command.

PowerShell issue - I have to type ./ to run bat file

I've just installed PHP & Yii Framework. It works fine, I played with CMD. But after a while I switched to PowerShell ISE. I navigated to Yii folder:
cd C:\dev\yii-1.1.9.r3527\framework
and I issued command:
yiic.bat
and I get an error:
PS C:\dev\yii-1.1.9.r3527\framework> yiic.bat
The term 'yiic.bat' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:9
+ yiic.bat <<<<
+ CategoryInfo : ObjectNotFound: (yiic.bat:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
However when I type:
./yiic.bat
into PowerShell window, it works fine.
Is there a way to aviod typing ./ every time I run a bat file?
The framework directory you're trying to run the batch file from is evidently not in your path. When you type yiic.bat into the shell, it looks for that file in the list of directories contained in your path environment variable. See this question for information about how to set your path in powershell.
For example, if you want to be able to run batch files in the C:\dev\yii-1.1.9.r3527\framework directory, you can say $env:Path = $env:Path + ";C:\dev\yii-1.1.9.r3527\framework".
Or, as mloskot says, you can just add the current directory to your path, though that can pose a minor security risk. See e.g. this question for a bit of discussion on that.
this is an old question, but I stumbled on it looking for something else.
Powershell requires you to type .\ to run commands in the current by design.
https://blogs.technet.microsoft.com/csps/2010/06/06/introduction-to-windows-powershell-scripting/
I don't have PowerShell to try this out, but if you set the path to include current folder, this should work:
$env:Path = $env:Path + ";."