Azure Cloud Shell'de PowerShell için hızlı başlangıç
Bu belgede, powershell'in Cloud Shell'de nasıl Azure portal.
Not
Hızlı Başlangıç Azure Cloud Shell bash de kullanılabilir.
Cloud Shell'i Başlatma
Gezinti Cloud Shell üst gezinti çubuğundan Yenile düğmesine Azure portal

Açılan listeden PowerShell ortamını seçin; azure sürücüsünde olur
(Azure:)
PowerShell komutlarını çalıştırma
Normal PowerShell komutlarını Cloud Shell, örneğin:
PS Azure:\> Get-Date
# Expected Output
Friday, July 27, 2018 7:08:48 AM
PS Azure:\> Get-AzVM -Status
# Expected Output
ResourceGroupName Name Location VmSize OsType ProvisioningState PowerState
----------------- ---- -------- ------ ------ ----------------- ----------
MyResourceGroup2 Demo westus Standard_DS1_v2 Windows Succeeded running
MyResourceGroup MyVM1 eastus Standard_DS1 Windows Succeeded running
MyResourceGroup MyVM2 eastus Standard_DS2_v2_Promo Windows Succeeded deallocated
Sanal makinelerle etkileşim kurma
Dizin aracılığıyla geçerli abonelik altındaki tüm sanal makinelerinizi VirtualMachines bulabilirsiniz.
PS Azure:\MySubscriptionName\VirtualMachines> dir
Directory: Azure:\MySubscriptionName\VirtualMachines
Name ResourceGroupName Location VmSize OsType NIC ProvisioningState PowerState
---- ----------------- -------- ------ ------ --- ----------------- ----------
TestVm1 MyResourceGroup1 westus Standard_DS2_v2 Windows my2008r213 Succeeded stopped
TestVm2 MyResourceGroup1 westus Standard_DS1_v2 Windows jpstest Succeeded deallocated
TestVm10 MyResourceGroup2 eastus Standard_DS1_v2 Windows mytest Succeeded running
Uzak VM'ler arasında PowerShell betiği çağırma
MyVM1 sanal makineniz olduğunu varsayarak, uzak makinede Invoke-AzVMCommand bir PowerShell betik bloğu çağırmak için kullanacağız.
Enable-AzVMPSRemoting -Name MyVM1 -ResourceGroupname MyResourceGroup
Invoke-AzVMCommand -Name MyVM1 -ResourceGroupName MyResourceGroup -Scriptblock {Get-ComputerInfo} -Credential (Get-Credential)
Ayrıca, önce VirtualMachines dizinine de gidin ve aşağıdaki Invoke-AzVMCommand gibi çalıştırın.
PS Azure:\> cd MySubscriptionName\ResourceGroups\MyResourceGroup\Microsoft.Compute\virtualMachines
PS Azure:\MySubscriptionName\ResourceGroups\MyResourceGroup\Microsoft.Compute\virtualMachines> Get-Item MyVM1 | Invoke-AzVMCommand -Scriptblock {Get-ComputerInfo} -Credential (Get-Credential)
# You will see output similar to the following:
PSComputerName : 65.52.28.207
RunspaceId : 2c2b60da-f9b9-4f42-a282-93316cb06fe1
WindowsBuildLabEx : 14393.1066.amd64fre.rs1_release_sec.170327-1835
WindowsCurrentVersion : 6.3
WindowsEditionId : ServerDatacenter
WindowsInstallationType : Server
WindowsInstallDateFromRegistry : 5/18/2017 11:26:08 PM
WindowsProductId : 00376-40000-00000-AA947
WindowsProductName : Windows Server 2016 Datacenter
WindowsRegisteredOrganization :
...
Uzak bir VM'de etkileşimli olarak oturum açma
Azure'da Enter-AzVM çalışan bir VM'de etkileşimli olarak oturum açmak için kullanabilirsiniz.
PS Azure:\> Enter-AzVM -Name MyVM1 -ResourceGroupName MyResourceGroup -Credential (Get-Credential)
Ayrıca önce dizinine VirtualMachines de gidin ve aşağıdaki gibi Enter-AzVM çalıştırın:
PS Azure:\MySubscriptionName\ResourceGroups\MyResourceGroup\Microsoft.Compute\virtualMachines> Get-Item MyVM1 | Enter-AzVM -Credential (Get-Credential)
WebApps'i keşfetme
dizinine girerek WebApps web uygulaması kaynaklarınıza kolayca ulaşabilirsiniz
PS Azure:\MySubscriptionName> dir .\WebApps\
Directory: Azure:\MySubscriptionName\WebApps
Name State ResourceGroup EnabledHostNames Location
---- ----- ------------- ---------------- --------
mywebapp1 Stopped MyResourceGroup1 {mywebapp1.azurewebsites.net... West US
mywebapp2 Running MyResourceGroup2 {mywebapp2.azurewebsites.net... West Europe
mywebapp3 Running MyResourceGroup3 {mywebapp3.azurewebsites.net... South Central US
# You can use Azure cmdlets to Start/Stop your web apps
PS Azure:\MySubscriptionName\WebApps> Start-AzWebApp -Name mywebapp1 -ResourceGroupName MyResourceGroup1
Name State ResourceGroup EnabledHostNames Location
---- ----- ------------- ---------------- --------
mywebapp1 Running MyResourceGroup1 {mywebapp1.azurewebsites.net ... West US
# Refresh the current state with -Force
PS Azure:\MySubscriptionName\WebApps> dir -Force
Directory: Azure:\MySubscriptionName\WebApps
Name State ResourceGroup EnabledHostNames Location
---- ----- ------------- ---------------- --------
mywebapp1 Running MyResourceGroup1 {mywebapp1.azurewebsites.net... West US
mywebapp2 Running MyResourceGroup2 {mywebapp2.azurewebsites.net... West Europe
mywebapp3 Running MyResourceGroup3 {mywebapp3.azurewebsites.net... South Central US
SSH
SSH kullanarak sunucularda veya VM'lerde kimlik doğrulaması yapmak için, Cloud Shell ortak-özel anahtar çiftini üretin ve ortak anahtarı gibi uzak makinede authorized_keys 'de /home/user/.ssh/authorized_keys yayımlayın.
Not
SSH özel-ortak anahtarlarını kullanarak oluşturabilir ve bu ssh-keygen anahtarları $env:USERPROFILE\.ssh Cloud Shell.
SSH Kullanma
Cmdlet'leri kullanarak yeni bir VM yapılandırması oluşturmak Azure PowerShell yönergeleri izleyin.
Dağıtımı başlatmaya New-AzVM çağırmadan önce VM yapılandırmasına SSH ortak anahtarını ekleyin.
Yeni oluşturulan VM, konumdaki ortak anahtarı içerir ve bu sayede VM'de kimlik bilgisi ~\.ssh\authorized_keys olmayan SSH oturumunu etkinleştirebilirsiniz.
# Create VM config object - $vmConfig using instructions on linked page above
# Generate SSH keys in Cloud Shell
ssh-keygen -t rsa -b 2048 -f $HOME\.ssh\id_rsa
# Ensure VM config is updated with SSH keys
$sshPublicKey = Get-Content "$HOME\.ssh\id_rsa.pub"
Add-AzVMSshPublicKey -VM $vmConfig -KeyData $sshPublicKey -Path "/home/azureuser/.ssh/authorized_keys"
# Create a virtual machine
New-AzVM -ResourceGroupName <yourResourceGroup> -Location <vmLocation> -VM $vmConfig
# SSH to the VM
ssh azureuser@MyVM.Domain.Com
Kullanılabilir komutları listele
Sürücü Azure altında, bağlama Get-AzCommand özgü Azure komutlarını almak için yazın.
Alternatif olarak, kullanılabilir Get-Command *az* -Module Az.* Azure komutlarını bulmak için her zaman kullanabilirsiniz.
Özel modülleri yükleme
modüllerini yüklemek Install-Module için PowerShell Galerisi.
Get-Help
PowerShell Get-Help hakkında bilgi almak için yazın Azure Cloud Shell.
Get-Help
Belirli bir komut için yine de bir Get-Help cmdlet'i kullanabilirsiniz.
Get-Help Get-AzVM
Verilerinizi Azure Dosyalar için Azure Dosyalar'i kullanma
Gibi bir betik oluşturabilir ve helloworld.ps1 kabuk oturumlarında kullanmak clouddrive için bunu kendi betiğinize kaydedebilirsiniz.
cd $HOME\clouddrive
# Create a new file in clouddrive directory
New-Item helloworld.ps1
# Open the new file for editing
code .\helloworld.ps1
# Add the content, such as 'Hello World!'
.\helloworld.ps1
Hello World!
PowerShell'i bir sonraki Cloud Shell dosya, dosya paylaşımınızı helloworld.ps1 $HOME\clouddrive bağlama dizininde Azure Dosyalar olacaktır.
Özel profil kullanma
PowerShell profillerini ( veya ) oluşturarak PowerShell ortamınızı profile.ps1 Microsoft.PowerShell_profile.ps1 özelleştirebilirsiniz.
Oturumdaki $profile.CurrentUserAllHosts her $profile.CurrentUserAllHosts PowerShell'e yüklen için altına (veya ) Cloud Shell kaydedin.
Profil oluşturma hakkında bilgi için bkz. Profiller Hakkında.
Git kullanma
Git depolarını depoya Cloud Shell için kişisel erişim belirteci oluşturmanız ve bunu kullanıcı adı olarak kullanmanız gerekir. Belirtecini olduktan sonra depoyu aşağıdaki gibi klonlamanız gerekir:
git clone https://<your-access-token>@github.com/username/repo.git
Kabuktan çıkış yapma
Oturumu exit sonlandırmak için yazın.