Il percorso della cartella documenti (MyDocuments) dell'utente corrente in Powershell è dato dal metodo GetFolderPath dell'oggetto Environment:

PowerShell

[Environment]::GetFolderPath("MyDocuments")
che ritorna un percorso tipo:

Text

C:\Users\nomeUtente\Documents
per spostarsi nella directory documents:

PowerShell

cd $([Environment]::GetFolderPath("MyDocuments"))
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:

PowerShell

[Environment]::GetFolderPath("sbagliato")
che ritorna questo errore:
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
Tags:
Errori120 PowerShell200
Potrebbe interessarti anche: