Azure Remote directory navigation - powershell

When I startup PowerShell from within my Azure Portal I can readily navigate to my Storage Accounts and files.
When running Powershell from my laptop, and logging into Azure using "Login-AzureRmAccount", I cannot do the same thing. My prompt is always "PS C:>" so any dir command is executed on my laptop rather than actually "inside" Azure.
What am I doing wrong and how can I navigate the Azure file system?

You'll need to create a PS drive from a provider. SHiPs was created to do e exactly this, take a look:
https://blogs.msdn.microsoft.com/powershell/2017/10/19/navigate-azure-resources-just-like-a-file-system/

Related

Run a powershell script on machine connected to deployment group in azure

I am trying to build a CI/CD pipeline with azure. The deployment is working until the final stage where i need to run a powershell/cmd script on the machine that is running the deployment group agent. Can someone please assist on how to run a cmd/powershell script on the machine that is running the deployment group agent?
I have tried using remote powershell but that requires a username and password which i can not use for security reasons.
For context
I have a local server. I have a repo on azure. I have created a pipeline that builds the repo and the artifacts of the build are then copied to my local server. Now I want to run a powershell/cmd on the local server through the pipeline.
Refer to the documentation here:
https://learn.microsoft.com/en-us/azure/devops/pipelines/scripts/powershell?view=azure-devops&tabs=yaml#add-a-powershell-script
The syntax for including PowerShell Core is slightly different from the syntax for Windows PowerShell.
Push your PowerShell script to your repo.
Add a pwsh or powershell step. The pwsh keyword is a shortcut for the PowerShell task for PowerShell Core. The powershell keyword is another shortcut for the PowerShell task but Windows PowerShell and will only work on a Windows agent.
# for PowerShell Core
steps:
- pwsh: ./my-script.ps1
# for Windows PowerShell
steps:
- powershell: .\my-script.ps1
However as you would notice, this would only run on the agent.
You can also use the classic alternative, also described in the same documentation using the UI provided by Azure
Another alternative which may be suited for your case is to create a VM extension by navigating to the virtual machine in the Azure Portal, clicking on "Extensions" in the left sidebar, and then clicking the "+Add" button.
Otherwise, your only option may be the "Azure Remote Run", however you mention you cannot get the credentials for that.

Unable to map azure file shares using azure pipelines to deployment group vm's

Im using azure devops release pipeline. Im planning to map the azure Fileshare to all VMS in deployment groups. I have the script from the portal to map fileshare in local. Replacing the passkey value in that script I'm passing as variable.
Tried to check and the value is getting. But in results it shows mapped with the drive letter. When I opened the file explorer it shows disconnected and unable to eject the sharepath shows "This network connection does not exist" Also it is not even mapped. If any issue in getting keys from variable means it should throw error without showing drive create status.
Looking for help is any step or mistake happened in the pipeline? Or in script?
Note: in local i can able to run the script successful and drive mapped successful as well.
Script:
cmd.exe /C "cmdkey /add:"storageaccount.file.core.windows.net" /user:"localhost\storageaccount" /pass:"accesskeyforstorageaccount"
New-PSDrive -Name Z -PSProvider Filesystem -Root "\storageaccount.file.core.windows.net\fileshare-name" -Persist
Make sure the drive name Z is not taken on Deployment group VM.
When you say in local i can able to run the script successful, do you mean you run on the deployment group VM? If not, try to run the script to check if it's successfully, check network, port.
You can check the code sample which is successful, double check if password is correctly set if you are using secret variable in the pipeline.
If the issue persists, please share more info like screenshot, log.

Azure File share mounted drive showing Disconnected Network Drive

I am using Microsoft Azure Fluent API with RunPowerShellScript method to execute powershell script.
My file share drive mounted properly but it's showing disconnected .But same powershell command when i run from virtual machine it's working properly.Please see below image :

Unix permissions needed when running Powershell script

As a final step in our AD account creation process that is being moved to a powershell script a few folders need to be created on the filer for users and I am coming unstuck with permissions.
I am just using the basic new-item command to create folder but the locations need unix permissions (775) set before anything can be created. I can't go there and right click in Windows explorer and click new.. and the powershell script is being bounced also due to permissions.
The reasoning from one of the tech guys here is that I am trying to create a sub folder via smb mount from Windows using ntfs permissions. There is no correlation to unix permissions and any of our Linux users won't be able to access / use the location created for them.
Sorry if that is a clumsy way of explaining it, I am not a systems engineer, just the guy trying to translate a whole heap if pearl scripts into a new powershell process.
Thank you
S.

How to run a script on a new Hyper-V Windows VMM virtual machine

I use a powershell script, triggered by teamcity, to spin up new Windows Server VMs. Currently, when the machine is up and running, I need to log in via the VMM console to make a couple of configuration changes (enable file sharing, network discovery, msdeploy and remoting over winrm) in order to allow other teamcity jobs to be able to deploy enterprise apps to the VM.
I haven't found any way to run my config setup scripts on the new VM other than by using the GUI console in VMM. For VMHosts, there is Invoke-SCScriptCommand, but this doesn't work for virtual machines themselves. Am I missing something or do I have to alter the template that my VM's are built from, in order to get the required config on the VMs?
One way you could achieve what you require is by putting all your config changes in a powershell script sitting inside VM template and adding it to VM's startup scripts.
The script's first step is checks whether the config changes have been applied in the past by checking some kind of a flag(ie. a file c:\deployed.flag) and last step is to create the flag.
if(Test-Path c:\deployed.flag){
## deployment script run already, do nothing
}
else{
## your config changing code block
New-Item c:\deployed.flag -Type f
}
In VMWare/PowerCLI you can run Invoke-VMScript which executes command directly on a VM via VMWare tools but alas Hyper-V Integration Services don't have such functionality.