How to create a new file in Powershell?
new-item keyword creates a new file in the filesystem. The type of item new item creates depends on where the item is being created. Per eżempju, punt ġdid jista 'joħloq ukoll ċwievet reġistru u l-entrati jekk jintużaw fir-reġistru.
Type the following command in to create a new file in the current path:
ni {filename.extension}
Hawn fuq huwa l-isem fittizju għall-kmand li ġej…
ġodda partita {filename.extension}
eżempju
ni fun.txt
Parametri jista 'jintuża wkoll ma' partita ġdida.
Dan li ġej toħloq fajl fil-passaġġ attwali ma 'xi kontenut:
ni -N fun.txt -p . -it f -v 'this is some silly text'
In the above example we have added the -name, -path and -itemtype parameters with their default values. Omitting these will generate the same result.
ni fun.txt -v 'this is some silly text'
Jekk inti tixtieq li jissostitwixxu fajl eżistenti tuża l--force jew parametru -f:
ni fun.txt -v 'this is some silly text' -f
Oħloq fajls multipli fid-direttorju kurrenti:
ni -it f -p 'file.txt', 'fun.txt'
Oħloq fajls multipli fil-c:/ għeruq u affarijiet direttorju
ni -it f -p 'c:\file.txt', 'c:\things\fun.txt'
ħolqien Direttorji
Tista 'toħloq direttorju ġdid minflok mkdir jew md billi tuża l-oġġett ġdida ta' kmand u l-istabbiliment tat-tip oġġett bħala direttorju.
gost ni -it d
Oħloq direttorju ġdid fil-għerq c:
ni -N -it gost d -p ċ:\
Oħloq direttorji multipli fil-passaġġ attwali:
ni -it d -p 'fun', 'silly'
Oħloq direttorji multipli fil-c:/ għeruq u affarijiet direttorju
ni -it d -p 'c:\folder', 'c:\things\fun'
It-tabella li ġejja turi l-parametri u huwa psewdonomu
| parametru | alias | eżempju | Deskrizzjoni |
-isem |
-n jew l-ebda parametru |
ni fun.txt |
Speċifika l-isem oġġett ġdid |
-itemtype |
-dan |
-it d jew -it dir jew -it directory-it f jew -it file |
Specify the type of item to create. Creates file by default. |
-force
|
-f
|
-f
|
Overwrite existing file. |
-value
|
-v
|
-v 'Some file content...'
|
Write content of file |
-path
|
-p
|
-p c:\
|
Path of where the new item should be created |
Some commands that is useful with the ni command:
ls – Get-ChildItem, lists files and directories of the current working directory. eg ls
gc – Get-Content, view the contents of a file eg. gc fun.txt
md – mkdir, make directory eg. md mynewdirectory
rm– Remove-Item, remove directory or file

Conteúdo top de mais, parabéns!