Question

I have a one line PowerShell script, when it executes it gives me a total site list of IIS server, but when I save to an Excel spreadsheet I get an Access denied error.

Code:

cmd /c  %windir%\system32\inetsrv\appcmd list site > c:\sites.xls

Log 1:

Access to the path 'C:\sites.xls' is denied.
At line:1 char:53
+ cmd /c  %windir%\system32\inetsrv\appcmd list site > <<<<  c:\sites.xls
    + CategoryInfo          : OpenError: (:) [], UnauthorizedAccessException
    + FullyQualifiedErrorId : FileOpenFailure

Log 2:

+  cmd /c  %windir%\system32\inetsrv\appcmd list site > <<<<  %temp%\sites.xls 
    + CategoryInfo          : OpenError: (:) [], DirectoryNotFoundException
    + FullyQualifiedErrorId : FileOpenFailure

How I can solve this problem ?

No correct solution

OTHER TIPS

The output of the command is being output to a file in a location where the current user does not have access to write a file. Try outputting the file to a location where the user has access. For example:

cmd /c  %windir%\system32\inetsrv\appcmd list site > %temp%\sites.xls

Alternatively, if the file MUST be output to c:\, then try running the Powershell process as a user with permissions to that folder (e.g. start -> type 'powershell' -> right-click 'Windows Powershell', and choose 'Run as Administrator'. Then try with the original command line:

cmd /c  %windir%\system32\inetsrv\appcmd list site > c:\sites.xls
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top