Come ottenere il percorso della cartella documents in PowerShell
Il percorso della cartella documenti (MyDocuments) dell'utente corrente in Powershell è dato dal metodo GetFolderPath dell'oggetto Environment:
che ritorna un percorso tipo:
per spostarsi nella directory documents:
Gli altri possibili valori del metodo GetFolderPath sono:
Desktop, Programs, MyDocuments, Personal, Favorites, Startup, Recent, SendTo, StartMenu, MyMusic, MyVideos, DesktopDirectory, MyComputer, NetworkShortcuts, Fonts, Templates, CommonStartMenu, CommonPrograms, CommonStartup, CommonDesktopDirectory, ApplicationData, PrinterShortcuts, LocalApplicationData, InternetCache, Cookies, History, CommonApplicationData, Windows, System, ProgramFiles, MyPictures, UserProfile, SystemX86, ProgramFilesX86, CommonProgramFiles, CommonProgramFilesX86, CommonTemplates, CommonDocuments, CommonAdminTools, AdminTools, CommonMusic, CommonPictures, CommonVideos, Resources, LocalizedResources, CommonOemLinks, CDBurning.
Che vengono visualizzati sbagliando il parametro:
che ritorna questo errore:
PowerShell
[Environment]::GetFolderPath("MyDocuments")
Text
C:\Users\nomeUtente\Documents
PowerShell
cd $([Environment]::GetFolderPath("MyDocuments"))
Desktop, Programs, MyDocuments, Personal, Favorites, Startup, Recent, SendTo, StartMenu, MyMusic, MyVideos, DesktopDirectory, MyComputer, NetworkShortcuts, Fonts, Templates, CommonStartMenu, CommonPrograms, CommonStartup, CommonDesktopDirectory, ApplicationData, PrinterShortcuts, LocalApplicationData, InternetCache, Cookies, History, CommonApplicationData, Windows, System, ProgramFiles, MyPictures, UserProfile, SystemX86, ProgramFilesX86, CommonProgramFiles, CommonProgramFilesX86, CommonTemplates, CommonDocuments, CommonAdminTools, AdminTools, CommonMusic, CommonPictures, CommonVideos, Resources, LocalizedResources, CommonOemLinks, CDBurning.
Che vengono visualizzati sbagliando il parametro:
PowerShell
[Environment]::GetFolderPath("sbagliato")
Cannot convert argument "folder", with value: "MyDocus", for "GetFolderPath"
to type "System.Environment+SpecialFolder": "Cannot convert value "MyDocus" to
type "System.Environment+SpecialFolder". Error: "Unable to match the
identifier name MyDocus to a valid enumerator name. Specify one of the
following enumerator names and try again: Desktop, Programs, MyDocuments,
Personal, Favorites, Startup, Recent, SendTo, StartMenu, MyMusic, MyVideos,
DesktopDirectory, MyComputer, NetworkShortcuts, Fonts, Templates,
CommonStartMenu, CommonPrograms, CommonStartup, CommonDesktopDirectory,
ApplicationData, PrinterShortcuts, LocalApplicationData, InternetCache,
Cookies, History, CommonApplicationData, Windows, System, ProgramFiles,
MyPictures, UserProfile, SystemX86, ProgramFilesX86, CommonProgramFiles,
CommonProgramFilesX86, CommonTemplates, CommonDocuments, CommonAdminTools,
AdminTools, CommonMusic, CommonPictures, CommonVideos, Resources,
LocalizedResources, CommonOemLinks, CDBurning""
At line:1 char:1
+ [Environment]::GetFolderPath("MyDocus")
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodException
+ FullyQualifiedErrorId : MethodArgumentConversionInvalidCastArgument
to type "System.Environment+SpecialFolder": "Cannot convert value "MyDocus" to
type "System.Environment+SpecialFolder". Error: "Unable to match the
identifier name MyDocus to a valid enumerator name. Specify one of the
following enumerator names and try again: Desktop, Programs, MyDocuments,
Personal, Favorites, Startup, Recent, SendTo, StartMenu, MyMusic, MyVideos,
DesktopDirectory, MyComputer, NetworkShortcuts, Fonts, Templates,
CommonStartMenu, CommonPrograms, CommonStartup, CommonDesktopDirectory,
ApplicationData, PrinterShortcuts, LocalApplicationData, InternetCache,
Cookies, History, CommonApplicationData, Windows, System, ProgramFiles,
MyPictures, UserProfile, SystemX86, ProgramFilesX86, CommonProgramFiles,
CommonProgramFilesX86, CommonTemplates, CommonDocuments, CommonAdminTools,
AdminTools, CommonMusic, CommonPictures, CommonVideos, Resources,
LocalizedResources, CommonOemLinks, CDBurning""
At line:1 char:1
+ [Environment]::GetFolderPath("MyDocus")
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodException
+ FullyQualifiedErrorId : MethodArgumentConversionInvalidCastArgument