简体   繁体   English

Powershell在AzureVM上创建文件夹

[英]Powershell create folder on AzureVM

I've been trying to create a folder on a list of vm's in Azure using powershell. 我一直在尝试使用powershell在Azure中的VM列表上创建一个文件夹。

Within the VM's I can use the below which works 在VM内,我可以使用以下有效的方法

$c = Get-Credential -Credential domain\AdminUser
$Comp = Get-Content C:\temp\list.txt
$s = $ExecutionContext.InvokeCommand.NewScriptBlock("mkdir c:\Whatyousaying")
Invoke-Command -ComputerName $Comp -ScriptBlock $s -Credential $c

However I have tried a few things but it doesn't recognise the AzureVm path. 但是,我尝试了一些操作,但无法识别AzureVm路径。

I have tried something like 我已经尝试过类似的东西

$ComputerName = Get-AzureRmVM | select Name
$DriveLetter = "C"
$Path = "NewDirectory"

foreach ($ComputerNames in $ComputerName)
{
    New-Item -Path \\

$ComputerName\$DriveLetter$\$Path -type directory -Force 
}

I m missing something obvious, I'm thinking DNS not finding the servers, so Ive tried using the public ip name and address, but they failed with winRM error, but this works in Azure. 我缺少明显的东西,我想DNS无法找到服务器,所以我尝试使用公共IP名称和地址,但是它们失败并出现winRM错误,但这在Azure中有效。 I have checked using Enable-PSRemoting, which is already enabled. 我已经使用Enable-PSRemoting(已启用)进行了检查。

Thanks in advance 提前致谢

You are right, create a folder for Azure VM you can use Winrm . 没错,为Azure VM创建一个可以使用Winrm的文件夹。

About enable Azure VM winrm, you should add port 5985 to Azure NSG inbound rules and add port 5985 to windows firewall inbound rules. 关于启用Azure VM winrm,应将端口5985添加到Azure NSG入站规则,并将端口5985添加到Windows防火墙入站规则。

You can use this script to create a session: 您可以使用此脚本创建会话:

$username = 'user'
$pass = ConvertTo-SecureString -string 'password' -AsPlainText -Force
$cred = New-Object -typename System.Management.Automation.PSCredential -argumentlist $username, $pass
$s = New-PSSession -ConnectionUri 'http://xx.xx.xx.xx:5985' -Credential $cred -SessionOption (New-PSSessionOption -SkipCACheck -SkipCNCheck -SkipRevocationCheck)

About create new folder, you can use invoke-command to create it: 关于创建新文件夹,您可以使用invoke-command来创建它:

Invoke-Command -Session $s -ScriptBlock {new-item c:\newdirectory}

Also you need to filter Azure VMs' public IP addresses with Azure PowerShell. 另外,您还需要使用Azure PowerShell筛选Azure VM的公共IP地址。

Here a similar case about you, via Winrm to run powershell command, please refer to it. 这里有一个关于您的类似案例 ,通过Winrm运行powershell命令,请参考它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM