I'm using PowerShell for auto-deploying website, and recently found AppPool setting which cannot be set with PS. or at least I did not manage to find out how to do it.
$appPool = $serverManager.ApplicationPools.Add($sitename)...
I need to set "Private Memory Limit" to some value, but it looks like there is no such property at ApplicationPool or ApplicationPoolRecycling object.
Does anybode know workaround for this issue?
This script uses Get-Webconfiguration and Set-WebConfiguration to get the value for private memory for all app pools. You can set each individually or set the application pool defaults for them to inherit. I have commented out the line which actually does the set.
import-module webadministration
$applicationPoolsPath = "/system.applicationHost/applicationPools"
$applicationPools = Get-WebConfiguration $applicationPoolsPath
foreach ($appPool in $applicationPools.Collection)
{
$appPoolPath = "$applicationPoolsPath/add[#name='$($appPool.Name)']"
Get-WebConfiguration "$appPoolPath/recycling/periodicRestart/#privateMemory"
# Set-WebConfiguration "$appPoolPath/recycling/periodicRestart/#privateMemory" -Value 1000
}
I am adding an answer because I was having trouble using the existing.
import-module webadministration
$applicationPools = Get-ChildItem IIS:\AppPools
foreach ($appPool in $applicationPools){
Set-ItemProperty IIS:\AppPools\$appPool.name `
-Name recycling.periodicrestart.privateMemory -Value 7000000
}
Your responses helped me come up with a solution to a problem that I was having with my WSUS servers. I knew that it was the application pool size for the WsusPool that was giving me problems so I made the following PS script and applied it to the root OU for my WSUS servers (I have 3) I was getting a connection error and my option to Reset Server Node didn't help. The event viewer had Event IDs 12002, 12012, 12032, 12022, 12042, 12052, and 12072.
Set-WebConfiguration "/system.applicationHost/applicationPools/add[#name='WsusPool']/recycling/periodicRestart/#privateMemory" -Value 0
Related
My PowerShell is VERY rusty, so please bear with me. I've been tasked to bulk tag Azure Resources based on CSV data, specifically Azure VM's. In this CSV are 3 headers (VMName, TagName, TagValue). I've tried to automate this task with PowerShell and no matter how I format the code, I keep falling short. Can someone help me clear this up or perhaps point me in the direction of a known working PS script that will help me accomplish this?
`
Connect-AzAccount -TenantId ''
Set-AzContext -Subscription ''
$Import = Import-Csv -Path '...\Tags.csv' |
ForEach-Object {
$_.psobject.properties |
ForEach-Object {Set-Variable -Name $_.Name -Value $_.Tags}
foreach ($Name in $Import) {
$Tag = $_.Name.Tags
$Tag.Add($_.Tags)
Set-AzResource -ResourceId $Name.ResourceId -Tag -Force
}
}
`
I've tried a hash table and a fully customized script. It either only applies the Tag Name and not the Tag Value, and it needs both, or it shoots off error after error. Microsoft seems to want bulk tagging at the subscription and resource group level, so it's a bit difficult to get this right specific to resources. In the end, I want the script to read the server name in Row 1 Column 1, find that resource in Azure, and create the Tag using the Tag Name (Row 1 Column 2) and Tag Value (Row 1 Column 3).
After reproducing from my end, I could able to get this work using New-AzTag. Below is the complete script that worked for me.
$Import = Import-Csv -Path 'Tags.csv'
foreach($I in $Import) {
$Resource = Get-AzResource -Name $I.VMName
$TagName=$I.TagName
$TagValue=$I.TagValue
New-AzTag -ResourceId $Resource.ResourceId -Tag #{"$TagName"="$TagValue"}
}
RESULTS:
Tags.csv
In portal
Is there a way to fetch all details of routing from each subscription with Route-Table Name, subscriptions, next hop type address prefix.
I have tried 'Get-AzRouteTable -ResourceGroupName "" -Name "prod" | Get-AzRouteConfig | Export-Csv azureroutetable2.csv' but getting only from specific environment, is there a better way to do the same?
Regards
Devbrat
According to the help for Get-AzRouteTable it doesn't require any value to be specified for ResourceGroupName so we should just be able to loop through your available contexts. If you did have a large Azure Network infrastructure and they were logically organised by Resource Group, you may want to consider looping through Resource Groups too.
That being said, you can do something like this. It will create a csv for each subscription in your current session. Change the . at the beginning of the path value to set a full path if you would like.
$Contexts = Get-AzContext -ListAvailable
foreach ($Context in $Contexts) {
[void](Set-AzContext -SubscriptionId $Context.Subscription.Id)
$RouteConfig = Get-AzRouteTable -Name "prod" | Get-AzRouteConfig
# If you are using PowerShell 5.1, add '-NoTypeInformation' to the end of this command.
$RouteConfig | Export-Csv -Path ".\$($Context.Subscription.Name)_Routes.csv" -Encoding utf8 -NoClobber
}
I want to pass a value in Octopus from one step to another of a project via output variable, the value is "VM running" or "VM deallocated".
There are two server, one of the server is down, another one is running so values should be passed accordingly. Now when I use the exact syntax of Output variable, it is passing Null value to next step.
Octopus deploy Project Step 1:
$RG = $RGName
$VM = "#{StepTemplate_VMName}"
$WarningPreference = 'SilentlyContinue'
$VMStats = (Get-AzureRmVM -Name $VM -ResourceGroupName $RG -Status).Statuses
$stats = ($VMStats | Where Code -Like 'PowerState/*')[0].DisplayStatus
Set-OctopusVariable -name "RunStatus" -value $stats
write-host $stats #value can either be "VM running" or "VM deallocated"
Octopus deploy Project Step 2:
$VM = "#{StepTemplate_VMName}"
$Runstatus = $OctopusParameters["Octopus.Action[Step1].Output[$VM].RunStatus"]
write-host $Runstatus
If I do not use [$VM] in the code of step 2, it give only 1 value to both the machine as "VM running"
As per the syntax given in Octopus website, we should use the VM name to pass machine specific different values.
so I used [$VM] but it gives null values to both of the machine
Edit: Event If I hardcode the value of $VM to any one VMName, it still gives me null.
Based on what I do in Octopus it should be:
$Runstatus = $OctopusParameters["Octopus.Action[Step1].Output.RunStatus"]
Even states that format on the help documentation. https://octopus.com/docs/projects/variables/output-variables
Is the step that's creating the output variable actually being run on the server that's down? When the output variable is created in a step that's run on multiple machines, multiple machine-scoped values for that variable will be created. When the subsequent step is run on the same machines, Octopus will pick the correct value based on that scope. So maybe a little off topic, but if both steps are run on both targets, specifying the $VM scope is redundant, and is only needed if you want a different machine's value.
Since hardcoding the target name here returns null it seems like the output variable creation step wasn't run on that target. I'd suggest debugging this by creating a variable called OctopusPrintEvaluatedVariables with value True in your project. That'll increase the task log verbosity and log how all variables are evaluated through each step of the deployment.
I have "billing reader" access to several hundred subscriptions in an EA.
I'm trying to get a list of virtual machines and their sizes across all subscriptions.
So currently when I run a "Get-AzureRMSubscription" it shows me all the subscriptions (hundreds of them), but i'm not sure how to actually run a script against all the subscriptions?
Would be great to get a "Get-AzureRMVM" across them all
Any suggestions?
Thanks in advance!
You can possibly do something like this:
$azureSubs = Get-AzureRMSubscription
$azureSubs | ForEach-Object {Select-AzureRMSubscription $_ | Out-Null; Get-AzureRMVM -WarningAction SilentlyContinue}
You are essentially setting an array variable to hold all your Azure Subscription and piping it to the ForEach-Object cmdlet to iterate all of the objects in the array. Then you pipe it to the Get-AzureRMVM cmdlet to list all VMs in each subscription.
This is definitely not optimized for performance and there might be better solutions out there, but at least you can run it and forget it.
The reason for the Out-Null and -WarningAction is to suppress the outputs you do not need.
You didn't ask but for classic resources we have the following script run on a regular basis and its output stored in a SQL Database.
$subscriptions = Get-AzureSubscription
foreach ($sub in $subscriptions)
{
$sub | Select-AzureSubscription
Get-AzureService | % {
Get-AzureDeployment -ServiceName $_.ServiceName
} | % {
New-Object -TypeName 'PSObject' -Property #{ 'ServiceName' = $_.ServiceName; 'Addresses' = $_.VirtualIPs.Address; }
} | sort Addresses | ft
}
% is ForEach-Object, ft is Format-Table although some kind souls may come along and try to edit this and make it harder to reuse. You can add/remove properties in the select statement to tailor your output as needed. Try it in one subscription to refined your needs, then create a script to make it easy to reuse.
We recently released Azure Resource Graph to support these types of searches across multiple subscriptions. See documentation here https://learn.microsoft.com/en-us/azure/governance/resource-graph/overview
I am trying to multithread something and ran across this:
http://learn-powershell.net/2015/03/31/introducing-poshrsjob-as-an-alternative-to-powershell-jobs/
Attempting to use but getting errors and not able to access the data I need. Let me explain. I have an extremely simple example here:
#('12.34.56.78')|Start-RSJob -Name {"TEST_$($_)"} -ScriptBlock {
Param($Computername)
Test-Connection -ComputerName $Computername -Quiet
}
get-RSJob|Receive-RSJob
This actually errors saying computername is null. Any type of command I place in here same error comes up saying computername is null. How to get rid of this and how to access the Boolean value that should be returned.
This returns a true or false on the command line but I cannot access this value when run in this script.
Eventually this will need to take an array of IP's and I will need to access all values returned for each machine. I don't have to use this posh module but need threads and thought this a good choice. Any advice here is appreciated.
It looks like you found a bug in my module with using Param() to host the incoming data in the pipeline. Fortunately, you can work around this by just using $_ in the scriptblock.
#('12.34.56.78')|Start-RSJob -Name {"TEST_$($_)"} -ScriptBlock {
Test-Connection -ComputerName $_ -Quiet
}
get-RSJob|Receive-RSJob
That being said, I definitely need to stomp that bug.
Edit: The issue with returning a $False is a bug ($True returns fine) in Receive-RSJob. I'll fix that as well.