Tuesday, June 28, 2016

PowerShell–Get-VM command is not recognize or missing

Currently I’m supporting one of the customer, found out that the PowerShell is in version 1.0 in the SCVMM.  Therefore, I tried to execute a script using the get-vm but it says as not recognize.

The message was :

PS C:\Users\Administrator\Desktop> Get-VM
The term 'Get-VM' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
As a workaround, I’ve execute the command as below :

Import-Module virtualmachinemanager

Then the get-vm command works.

keywords : SCVMM, get-vm missing, get-vm command not recognize, powershell command not recognize.

PowerShell–Listing of Folder Permission, export to CSV

Today would like to share with you about a way to list down all the Folder and subfolder permission into a CSV format.  This is good especially for internal or external audits.

There are two options that you can run.

  • Run in the File Server (provided you have PowerShell installed)
  • Run from your Computer (Map the File Server Drive, and also provided you have PowerShell installed in your computer)

The coding is as below :

# This is the file specified for the Output of CSV. Make the necessary change
$OutFile = "C:\Download\Permission.csv"

$Header = "Folder Path,IdentityReference,AccessControlType,IsInherited,InheritanceFlags,PropagationFlags"
Del $OutFile
Add-Content -Value $Header -Path $OutFile


# This is the top path of where want to scan the permission from.  This will include the sub folders
$RootPath = "C:\Download\Driver"

$Folders = dir $RootPath -recurse | where {$_.psiscontainer -eq $true}

foreach ($Folder in $Folders){
    $ACLs = get-acl $Folder.fullname | ForEach-Object { $_.Access  }
    Foreach ($ACL in $ACLs){
    $OutInfo = $Folder.Fullname + "," + $ACL.IdentityReference  + "," + $ACL.AccessControlType + "," + $ACL.IsInherited + "," + $ACL.InheritanceFlags + "," + $ACL.PropagationFlags
    Add-Content -Value $OutInfo -Path $OutFile
    }}

Note : Make changes to the Pink in colour according to your CSV file and which path you want to scan your File Server and export out the permission listing.

The output will be something like below when open with Excel :

image

I’m executing on my PC, that’s the reason I have the output as above.

Thank you and hope this helps.

keywords : ACL, folder permission, powershell, File Server, fileserver, Access list, access control list, permission to CSV

Thursday, June 9, 2016

Azure – Removing / Deleting Resource Group with PowerShell

Since Azure introduced the new portal, the recommendation to create is as below :

  1. Create Resource Group
  2. Create Azure Storage Account
  3. Create Azure VNET

That is the 3 basic items that MUST be created first before creating any VMs.

So now I face the “horror of cleaning up” after conducting some demos. The cleaning up is quite a challenge through the GUI Management Portal.  Therefore I need to clear the entire Resource Group.  Before I can delete that, I need to delete all the contents in the resource group. It’s very tedious.

Now I’ve found a way that I would like to share.

Step 1

Update your local PowerShell with the Azure SDK.   If not download it from here.

[image12.png]

Step 2

Once it’s installed, then you should have the Azure commands added into your PowerShell.

Launch the Run ISE as Administrator

Minimize the PowerShell Window.

Step 3

SNAGHTML5584fe7

  • Expand the left panel
  • Browse to the Resource Group

SNAGHTML5603fb3

  • Take note of the PowerShell command (which is going to help later).

Step 4

  • Maximize the PowerShell that was launch earlier (ISE) in Step 2
  • Login using the command of Login-AzureRMAccount

SNAGHTML562ddbf

  • Take note of the SubscriptionId
  • The command to remove the entire Resource Group is as follow :

Remove-AzureRMResource –ResourceId /subscriptions/SubscriptionId/resourceGroups/resourcegroupname/ –ApiVersion 2014-04-01 –Force

Note : Only make changes to the pink colour syntax.  The first is your subscription ID information that you get from the top when you login to Azure and the second one is the resource group name. 

  • If you’re not so sure of the command, then refer to the command that you noted earlier in Step 3 from the Azure Resource Explorer.
  • As example I would like to delete off the entire Resource Group of RG-CANADA-CENTRAL-01 in my subscription then I type the following :

image

  • Once it’s completed removing the Resource Group, a True word is indicated.

image

So hopefully the above helps you as it has helped me in cleaning up the Resource Group.

keywords : azure, resource explorer, manage azure, azure portal , resource group, housekeeping resource group, new azure portal, manage azure portal

How to Remove Azure Account (Cached) using PowerShell

Recently I’ve done quite a lot of testing using various accounts to Azure.  All the commands are executed in the PowerShell ISE (Run ISE are Administrator).

The PowerShell should have the Azure Commands in it already.  If not, can download from here.

Select the Install from the Command-line tools

image

When I tried to Get-AzureAccount, it displayed more than one account and subscriptions

image

I need to remove the other subscriptions.  Therefore I perform as follow :

image

Execute the command as below :

  • Get-AzureAccount | format-table id

Once displayed, I execute to remove the account using

  • Remove-AzureAccount account-name

Note : Just replace the account-name with the account that needs to be deleted.

Another way is to remove all the accounts then re-add it back. 

To do this execute it as below to remove all the accounts :

  • Get-AzureAccount | ForEach-Object {Remove-AzureAccount $_.ID -Force}

To add the account that I’m working on, use :

  • Add-AzureAccount

 

keys : add azure account, remove azure account in cache, Azure powershell command line, command-line, azure subscription, AzureSubscription, get-azureaccount, remove-azureaccount, Azure SDK