Startsidan  ▸  Texter  ▸  Teknikblogg

Anders Hesselbom

Programmerare, skeptiker, sekulärhumanist, antirasist.
Författare till bok om C64 och senbliven lantis.
Röstar pirat.

Getting started, part 3 of 3


About providers and cmdlets: If you just start PowerShell and use these cmdlets, they are for file management.

The Add-Content cmdlet can create a file if it doesn’t exist, and append information to that file. If you execute the following line, you will get a new file in your C root called MyFile.txt.

Add-Content “C:\MyFile.txt” “This is new content.”

The file will contain one line of text (the second parameter). If you run the same command again, the file will contain two lines. If the file exists, information is appended.

There is also a set of commands that can be used to manage files. Your new created file can be moved using the Move-Item cmdlet. Just specify the source and the destination:

Move-Item “C:\MyFile.txt” “D:\MyDestination.txt”

The Copy-Item cmdlet works in the same way, but leaves the original file.

If you don’t want to use absolute paths, you can type Get-Location to find the current directory. Set-Location (or CD for short) changes the current directory.

But again, the reason these cmdlets are used for file management, is that the underlying provider is a FileSystem provider. To see the available providers, type Get-PSProvider. If you change provider from FileSystem to Registry, the cmdlets will be used to manipulate the registry instead of the file system. To change provider to Registry, type:

Set-Location HKLM:

Now, try the Get-Location cmdlet again. This time, it will give you a location in the registry instead of a location in the file system. If you wonder what happened here, type Get-PSDrive. Now you can see what providers are mapped to what drives. The Get-Location cmdlet is used to select an available drive. The provider associated with the drive will also be selected. If you want to use the file system again, just type Set-Location C: (since C: is associated with the FileSystem provider).

Categories: PowerShell

Tags: PowerShell

Leave a Reply

Your email address will not be published. Required fields are marked *

En kopp kaffe!

Bjud mig på en kopp kaffe (20:-) som tack för bra innehåll!

Bjud på en kopp kaffe!


Kontaktuppgifter, med mera, finns här.

Följ mig

Twitter Instagram
GitHub RSS

Public Service

Folkbildning om public service.

Hem   |   |   |   |   Filmtips