Get-WmiObject Win32_ServerFeature Access Remote Server Roles and features - wmi

Accessing Roles and Features from the Remote server.
i tries the following PowerShell script to get the roles and features from the remote server.
Get-WmiObject -Computer "serverName" -query 'select * from Win32_ServerFeature'
but the problem is i could not identify additional details like if the given object from the collection is Feature or role. Any help please?

Finally i found another alternative by using Get-WindowsFeature -ComputerName where i can filter featuretype and get separate results for roles and features for remote machines.
For example:
Get-WindowsFeature -ComputerName $ServerName | Where-Object {($_.InstallState -eq “installed”) -and ($_.FeatureType -eq “Role Service”)}

Related

SharePoint 2013 Management Shell; Variable is Not recognized and therefore the account attached to the variable cannot be found

I am developing a SharePoint2013 instance in Hyper-V using Windows2012R2. Currently I am struggling to attach credentials to a variable in SharePoint Management Shell and then attach that variable to a New SharePoint account.
After I run the following script(s) I received this error:
Script(s):
"Variable" = Get-Credential "Domain\Username"
New-SPManagedAccount -Credential "Variable"
Error:
New-SPManagedAccount -Credential "Variable" : Some or all identity references could not be translated.
Essentially the new SharePoint account cannot be created and attached to the variable because the account cannot be found. However the first script worked, so I am lost as to where or how the Variable stored the "Domain\Username".
You could try this.
$cred = Get-Credential
New-SPManagedAccount -Credential $cred
For more information, you could read this article.
https://learn.microsoft.com/en-us/powershell/module/sharepoint-server/new-spmanagedaccount?view=sharepoint-server-ps#examples

How to deploy or delete several virtual machines at once with Azure PowerShell?

How can I do multiple operations on multiple VM's like creating or deleting 10 VM's through Azure PowerShell scripts?
Generally, we deploy a bunch of VMs in order to increase the availability and reliability of Virtual Machine solutions on Azure using Availability Sets or manage a set of identical, auto-scaling virtual machines using virtual machine scale sets.
In this case, if you just want to deploy a volume of VMs once time. You can use a for loop with powershell. For example, you create two VMs as following steps:
Create a resource group
New-AzureRmResourceGroup -ResourceGroupName "ResourceGroupVM" -Location "EastUS"
Create 2 VMs using FOR loop.
for ($i=1; $i -le 2; $i++)
{
$cred = Get-Credential
New-AzureRmVm `
-ResourceGroupName "ResourceGroupVM" `
-Name "myVM$i" `
-Location "East US" `
-VirtualNetworkName "myVnet" `
-SubnetName "mySubnet" `
-SecurityGroupName "myNetworkSecurityGroup" `
-PublicIpAddressName "myPublicIpAddress$i" `
-Credential $cred
}
Remove your resource group to remove VMs.
Remove-AzureRmResourceGroup -Name "ResourceGroupVM" -Force
However, it is recommended to use the template to deploy many independent VMs. You can create a template file that deploys the resources and a parameters file that supplies parameter values to the template. Then deploy the template. Using template is a more flexible method to deploy many personalized VMs that you can specific lots of properties (e.g. virtual network, subnet, load balancer configs, etc.)

Unable to save/modify imported build definition in VSTS

I am attempting to export a build from one project to another. Projects are in different collections. I have collection admin so perms should be good, but just to be sure I granted myself build and project admin.
I exported the build as json using the VSTS UI in the source project then imported in the target project. All the tasks are present, but the parameters are grayed out. I also cannot enable/disable tasks. There are some parameters that need to be filled in such as build agent. I was able to select the appropriate agent. I have no outstanding items at this point that the UI is indicating I would need to address prior to saving. The save, discard, queue options are all grayed out.
I can add a new phase, but I can't add any tasks to that phase. I also tried bringing up the yaml and compared it to the yaml in the source project, no differences.
Why can't I save my imported build definition?
Import succeeded after replacing all instances of the project and collection ids in the json I was attempting to import. At the time of this post those changes must be completed manually.
UPDATE:
I tried just removing the offending properties rather than replacing them and that worked. I created a simple script to clear out those properties:
Param(
[parameter(Mandatory=$true)]
[alias("p")]
$path
)
$removeProperties = #("triggers","metrics","_links","authoredBy","queue","project")
$json = Get-Content -Path $path -Raw | ConvertFrom-Json
foreach ($property in $removeProperties) {
$json.PSObject.Properties.Remove($property)
}
$json | ConvertTo-Json -Depth 100 | Set-Content -Path $path -Force

MS Exchange access by API or Web Services

I am looking for a way to access emails in Exchange. I assume that there would be needed 2007 version with SP1. As I know there is possibility to access Exchange by PowerShell or by web services. What I am interested in is to access messages from various mailboxes to get their from/to/subject/body.
I've found that by web services this is possible by using FindItem and GetItem calls. Are there also other powershell commands to get to emails?
How can I access what I need?
You should use the Exchange API for this (EWS)
Glenn Scales has explained how to use it with powershell on http://gsexdev.blogspot.nl/2012/01/ews-managed-api-and-powershell-how-to.html?m=1
I looked over the native Exchange cmdlets and was only able to find a reference to Get-Message cmdlet, but it appears that cmdlet is used to
view the details of one or more messages in a queue on a computer that has the Hub Transport server role or the Edge Transport server role installed.
But it doesn't look like the message body is returned.
If you can tolerate a paid solution (currently in Beta), my employer (CData Software) makes a set of cmdlets for working with Exchange data.
EDIT: Beta solution isn't helpful for OP.
With the limitations in the native Exchange cmdlets and the restriction for a production solution, I can offer my employer's ADO.NET Provider for Exchange. We have already published a Knowledge Base article (whose contents are copied below):
The CData ADO.NET Provider for Microsoft Exchange implements standard ADO.NET interfaces, enabling you to access the capabilities of the Microsoft Exchange API from .NET applications, such as PowerShell. The provider simplifies authentication and interaction with Microsoft Exchange data. This tutorial shows how to use some of the common ADO.NET objects to execute SQL queries directly from PowerShell.
Execute Queries
Follow the three steps below to execute any create, read, update, and delete (CRUD) command to Microsoft Exchange data in PowerShell:
Load the provider's assembly:
[Reflection.Assembly]::LoadFile("C:\Program Files\CData\CData ADO.NET Provider for Microsoft Exchange\lib\System.Data.CData.Exchange.dll")
Connect to Microsoft Exchange data. Specify the User and Password to connect to Exchange. Additionally, specify the address of the Exchange server you are connecting to and the Platform associated with the server.
$constr = "User='myUser#mydomain.onmicrosoft.com';Password='myPassword';Server='https://outlook.office365.com/EWS/Exchange.asmx';Platform='Exchange_Online';"
$conn= New-Object System.Data.CData.Exchange.ExchangeConnection($constr)
$conn.Open()
Instantiate the ExchangeDataAdapter, execute an SQL query, and output the results:
$sql="SELECT GivenName, Size from Contacts"
$da= New-Object System.Data.CData.Exchange.ExchangeDataAdapter($sql, $conn)
$dt= New-Object System.Data.DataTable
$da.Fill($dt)
$dt.Rows | foreach {
Write-Host $_.givenname $_.size
}
Update Microsoft Exchange Data
$cmd = New-Object System.Data.CData.Exchange.ExchangeCommand("UPDATE Contacts SET BusinnessAddress_City='Raleigh' WHERE Id = #myId", $conn)
$cmd.Parameters.Add(new System.Data.CData.Exchange.ExchangeParameter("myId","10456255-0015501366"))
$cmd.ExecuteNonQuery()
Insert Microsoft Exchange Data
$cmd = New-Object System.Data.CData.Exchange.ExchangeCommand("INSERT INTO Contacts SET BusinnessAddress_City='Raleigh' WHERE Id", $conn)
$cmd.Parameters.Add(new System.Data.CData.Exchange.Microsoft ExchangeParameter("myId","001d000000YBRseAAH"))
$cmd.ExecuteNonQuery()
Delete Microsoft Exchange Data
$cmd = New-Object System.Data.CData.Exchange.ExchangeCommand("DELETE FROM Contacts WHERE Id", $conn)
$cmd.Parameters.Add(new System.Data.CData.Exchange.Microsoft ExchangeParameter("myId","001d000000YBRseAAH"))
$cmd.ExecuteNonQuery()

amazon EC2 command line interface not returning all my snapshots

So I am tasked with creating a Batch script to handle creating and deleting snapshots of one of our servers. Well I have most of it working but the problem I am having is trying to list out more than 11 snapshots. We have well over 200 snapshots on one volume.
I've tried ec2-describe-snapshots -F "volume-id=vol-12345" -F "status=completed"|sort /R /+49 where vol-12345 is my volume id of course. That does do the proper sorting by date that I need but it still only returns 11 snapshots. I also tried to throw a -a at the end in case there were any private snapshots but I was still getting only 11.
I did see this post: how to list all the snapshots created from a single volume ID EC2 instance but that doesnt quite answer my question on how to display more than 11 snapshots. Any help on this would be greatly appreciated! Thanks.
Here's an alternative, using the AWS Tools for PowerShell. This utility should already be installed if your Windows EC2 is based off of an AMI that Amazon provided.
This example describes a collection of snapshots that you created, and is filtered by status "completed" and by your provided volumeId. It is sorted by StartTime.
# Create a filter to limit by status = completed
$filterByStatusCompleted = New-Object Amazon.EC2.Model.Filter -Property #{Name = "status"; Value = "completed"}
# Create a filter to limit by specific volume ID
$filterByVolumeId = New-Object Amazon.EC2.Model.Filter -Property #{Name = "volume-id"; Value = "vol-11111111"}
# Describe the collection of snapshots, sorted by StartTime
Get-EC2Snapshot -OwnerIds self -Filter $filterByStatusCompleted, $filterByVolumeId | Sort -Property StartTime
Documentation:
AWS Tools For PowerShell - Get-EC2 Snapshot