Delen via


Get-Location

Hiermee haalt u informatie op over de huidige werklocatie of een locatiestack.

Syntax

Get-Location
   [-PSProvider <String[]>]
   [-PSDrive <String[]>]
   [-UseTransaction]
   [<CommonParameters>]
Get-Location
   [-Stack]
   [-StackName <String[]>]
   [-UseTransaction]
   [<CommonParameters>]

Description

Met de cmdlet Get-Location wordt een object opgehaald dat de huidige map vertegenwoordigt, net als de opdracht afdrukwerkmap (pwd).

Wanneer u tussen Windows PowerShell stations navigeert, behoudt Windows PowerShell uw locatie in elk station. U kunt deze cmdlet gebruiken om uw locatie op elk station te vinden.

U kunt deze cmdlet gebruiken om de huidige map tijdens runtime op te halen en te gebruiken in functies en scripts, zoals in een functie waarin de huidige map wordt weergegeven in de Windows PowerShell prompt.

U kunt deze cmdlet ook gebruiken om de locaties in een locatiestack weer te geven. Zie de Notities en beschrijvingen van de parameters Stack en StackName voor meer informatie.

Voorbeelden

Voorbeeld 1: de huidige locatie van het station weergeven

PS C:\> Get-Location
Path
----
C:\WINDOWS

Met deze opdracht wordt uw locatie in het huidige Windows PowerShell station weergegeven.

Als u zich bijvoorbeeld in de Windows-map van station C: bevindt, wordt het pad naar die map weergegeven.

Voorbeeld 2: uw huidige locatie voor verschillende stations weergeven

The first command uses the **Set-Location** cmdlet to set the current location to the Windows subdirectory of the C: drive.
PS C:\> Set-Location C:\Windows

The second command uses the **Set-Location** cmdlet to change the location to the HKLM:\Software\Microsoft registry key. When you change to a location in the HKLM: drive, Windows PowerShell retains your location in the C: drive.
PS C:\>
PS C:\WINDOWS> Set-Location HKLM:\Software\Microsoft
PS HKLM:\Software\Microsoft>

The third command uses the **Set-Location** cmdlet to change the location to the HKCU:\Control Panel\Input Method registry key.
PS C:\>
PS HKLM:\Software\Microsoft> Set-Location "HKCU:\Control Panel\Input Method"
PS HKCU:\Control Panel\Input Method>

The fourth command uses the **Get-Location** cmdlet to find the current location on the C: drive. It uses the *PSDrive* parameter to specify the drive.
PS C:\>
PS HKCU:\Control Panel\Input Method> Get-Location -PSDrive C



Path
----
C:\WINDOWS

The fifth command uses the **Set-Location** cmdlet to return to the C: drive. Even though the command does not specify a subdirectory, Windows PowerShell returns you to the saved location.
PS C:\>
PS HKCU:\Control Panel\Input Method> Set-Location C:
PS C:\WINDOWS>

The sixth command uses the **Get-Location** cmdlet to find the current location in the drives supported by the Windows PowerShell registry provider. **Get-Location** returns the location of the most recently accessed registry drive, HKCU.
PS C:\>
PS C:\WINDOWS> Get-Location -PSProvider registry




Path
----
HKCU:\Control Panel\Input Method

To see the current location in the HKLM: drive, you need to use the *PSDrive* parameter to specify the drive. The seventh command does just this:
PS C:\>
PS C:\WINDOWS> Get-Location -PSDrive HKLM



Path
----
HKLM:\Software\Microsoft

In dit voorbeeld ziet u het gebruik van Get-Location om uw huidige locatie op verschillende Windows PowerShell stations weer te geven.

Voorbeeld 3: de locaties in de huidige locatiestack en alternatieve locatiestacks weergeven

The first command sets the current location to the Windows directory on the C: drive.
PS C:\> Set-Location C:\Windows

The second command uses the **Push-Location** cmdlet to push the current location (C:\Windows) onto the current location stack and change to the System32 subdirectory. Because no stack is specified, the current location is pushed onto the current location stack. By default, the current location stack is the unnamed default location stack.
C:\WINDOWS> Push-Location System32

The third command uses the *StackName* parameter of the **Push-Location** cmdlet to push the current location (C:\Windows\System32) onto the Stack2 stack and to change the current location to the WindowsPowerShell subirectory. If the Stack2 stack does not exist, **Push-Location** creates it.
C:\Windows\System32> Push-Location WindowsPowerShell -StackName Stack2

The fourth command uses the *Stack* parameter of the **Get-Location** cmdlet to get the locations in the current location stack. By default, the current stack is the unnamed default location stack.
C:\WINDOWS\system32\WindowsPowerShell> Get-Location -Stack
Path
----
C:\WINDOWS

The fifth command uses the *StackName* parameter of the **Get-Location** cmdlet to get the locations in the Stack2 stack.
PS C:\>
C:\WINDOWS\system32\WindowsPowerShell>get-location -stackname Stack2



Path
----
C:\WINDOWS\system32

Met deze opdracht ziet u hoe u de parameters Stack en StackName van Get-Location gebruikt om de locaties in de huidige locatiestack en alternatieve locatiestacks weer te geven. Zie de Notities voor meer informatie over locatiestacks.

Voorbeeld 4: De Windows PowerShell prompt aanpassen

PS C:\>
function prompt { 'PowerShell: ' + (get-location) + '> '}
PowerShell: C:\WINDOWS>

In dit voorbeeld ziet u hoe u de Windows PowerShell prompt aanpast. De functie waarmee de prompt wordt gedefinieerd, bevat de opdracht Get-Location , die wordt uitgevoerd wanneer de prompt in de console wordt weergegeven.

De indeling van de standaardprompt Windows PowerShell wordt gedefinieerd door een speciale functie met de naam prompt. U kunt de prompt in uw console wijzigen door een nieuwe functie te maken met de naam prompt.

Als u de huidige promptfunctie wilt zien, typt u de volgende opdracht: Get-Content Function:prompt

De opdracht begint met het trefwoord van de functie, gevolgd door de functienaam, prompt. De hoofdtekst van de functie wordt weergegeven tussen accolades ( ). {}

Met deze opdracht definieert u een nieuwe prompt die begint met de tekenreeks PowerShell: . Als u de huidige locatie wilt toevoegen, wordt de opdracht Get-Location gebruikt, die wordt uitgevoerd wanneer de promptfunctie wordt aangeroepen. De prompt eindigt met de tekenreeks " "> .

Parameters

-PSDrive

Hiermee geeft u de huidige locatie in het opgegeven Windows PowerShell station dat deze cmdlet in de bewerking ophaalt.

Als u zich bijvoorbeeld in het station Certificate: bevindt, kunt u deze parameter gebruiken om uw huidige locatie in station C: te vinden.

Type:String[]
Position:Named
Default value:None
Required:False
Accept pipeline input:True
Accept wildcard characters:False

-PSProvider

Hiermee geeft u de huidige locatie op het station dat wordt ondersteund door de Windows PowerShell provider die deze cmdlet in de bewerking ophaalt.

Als de opgegeven provider meer dan één station ondersteunt, retourneert deze cmdlet de locatie op het laatst geopende station.

Als u zich bijvoorbeeld in station C: bevindt, kunt u deze parameter gebruiken om uw huidige locatie te vinden in de stations van de Windows PowerShellRegistry-provider.

Type:String[]
Position:Named
Default value:None
Required:False
Accept pipeline input:True
Accept wildcard characters:False

-Stack

Geeft aan dat deze cmdlet de locaties in de huidige locatiestack weergeeft.

Als u de locaties in een andere locatiestack wilt weergeven, gebruikt u de parameter StackName . Zie de Notities voor informatie over locatiestacks.

Type:SwitchParameter
Position:Named
Default value:None
Required:False
Accept pipeline input:False
Accept wildcard characters:False

-StackName

Hiermee geeft u, als een tekenreeksmatrix, de benoemde locatiestacks op. Voer een of meer locatiestacknamen in.

Gebruik de parameter Stack om de locaties in de huidige locatiestack weer te geven. Als u van een locatiestack de huidige locatiestack wilt maken, gebruikt u de parameter Set-Location. Zie de Notities voor informatie over locatiestacks.

Met deze cmdlet kunnen de locaties in de naamloze standaardstack niet worden weergegeven, tenzij het de huidige stack is.

Type:String[]
Position:Named
Default value:None
Required:False
Accept pipeline input:True
Accept wildcard characters:False

-UseTransaction

Hiermee wordt de opdracht opgenomen in de actieve transactie. Deze parameter is alleen geldig wanneer een transactie wordt uitgevoerd. Zie about_Transactions voor meer informatie.

Type:SwitchParameter
Aliases:usetx
Position:Named
Default value:False
Required:False
Accept pipeline input:False
Accept wildcard characters:False

Invoerwaarden

None

U kunt geen invoer doorspezen naar deze cmdlet.

Uitvoerwaarden

System.Management.Automation.PathInfo or System.Management.Automation.PathInfoStack

Als u de parameters Stack of StackName gebruikt, retourneert deze cmdlet een StackInfo-object . Anders wordt een PathInfo-object geretourneerd.

Notities

  • Deze cmdlet is ontworpen om te werken met de gegevens die door elke provider worden weergegeven. Als u de providers in uw sessie wilt weergeven, typt u Get-PSProvider. Zie about_Providers voor meer informatie.

    De manier waarop de parameters PSProvider, PSDrive, Stack en StackName samenwerken, is afhankelijk van de provider. Sommige combinaties leiden tot fouten, zoals het opgeven van zowel een station als een provider die dat station niet beschikbaar maakt. Als er geen parameters zijn opgegeven, retourneert deze cmdlet het PathInfo-object voor de provider die de huidige werklocatie bevat.

    Een stack is een lijst met de laatste in, first-out waarin alleen het laatst toegevoegde item toegankelijk is. U voegt items toe aan een stapel in de volgorde waarin u ze gebruikt en haalt ze vervolgens op voor gebruik in omgekeerde volgorde. met Windows PowerShell kunt u providerlocaties opslaan in locatiestacks. Windows PowerShell maakt een naamloze standaardlocatiestack en kunt u meerdere benoemde locatiestacks maken. Als u geen stacknaam opgeeft, gebruikt Windows PowerShell de huidige locatiestack. Standaard is de naamloze standaardlocatie de huidige locatiestack, maar u kunt de cmdlet Set-Location gebruiken om de huidige locatiestack te wijzigen.

    Als u locatiestacks wilt beheren, gebruikt u de Windows PowerShellLocation-cmdlets als volgt.

    • Als u een locatie wilt toevoegen aan een locatiestack, gebruikt u de cmdlet Push-Location.

    • Gebruik de cmdlet Pop-Location om een locatie op te halen uit een locatiestack.

    • Als u de locaties in de huidige locatiestack wilt weergeven, gebruikt u de parameter Stack van de cmdlet Get-Location . Als u de locaties in een benoemde locatiestack wilt weergeven, gebruikt u de parameter StackName van de cmdlet Get-Location .

    • Als u een nieuwe locatiestack wilt maken, gebruikt u de parameter StackName van de cmdlet Push-Location . Als u een stack opgeeft die niet bestaat, maakt Push-Location de stack.

    • Als u van een locatiestack de huidige locatiestack wilt maken, gebruikt u de parameter StackName van de cmdlet Set-Location .

    De naamloze standaardlocatiestack is alleen volledig toegankelijk wanneer het de huidige locatiestack is. Als u een benoemde locatiestack de huidige locatiestack maakt, kunt u de pushlocatie - of poplocatie toevoegen niet meer gebruiken of items ophalen uit de standaardstack of deze cmdlet-opdracht gebruiken om de locaties in de naamloze stack weer te geven. Als u van de naamloze stack de huidige stack wilt maken, gebruikt u de parameter StackName van de cmdlet Set-Location met de waarde $null of een lege tekenreeks ("").