Skip to content

Instantly share code, notes, and snippets.

View mczerniawski's full-sized avatar

mczerniawski mczerniawski

View GitHub Profile
VERBOSE: Processing Computer {HyperV} with default credentials of user {mczerniawski_admin}
VERBOSE: Processing adding new VHDX Disk to VM {VMName1} on Computer {HyperV}
VERBOSE: Getting VM {VMName1} properties from Computer {HyperV} to set Path for new VHDX
VERBOSE: Setting disk type to {Dynamic} for {VMName1} on Computer {HyperV}
VERBOSE: Creating new VHDX in {C:\AdminTools\VMName1\Virtual Hard Disks\VMName1_disk1.vhdx} for {VMName1} on Computer {HyperV}
Number :
PSComputerName : HyperV
RunspaceId : 7acbb7e4-efc4-4222-93c9-f75618873037
#optional
#$Creds = Get-Credential #Credki do VM - moga byc domenowe lub lokalne
$NewVMDiskProps = @{
VMProps = @{
ComputerName = 'HyperV'
VMName = 'VMName1'
}
VHDProps = @(
@{
function Add-AHVMDisk {
<#
.SYNOPSIS
Adds a new vhdx to Hyper-V VM
.DESCRIPTION
Creates a new VHDX in VM's default disk location with given size (VHDSize). Attaches to a VM.
.PARAMETER ComputerName
ComputerName of a HyperV Computer where VM is.
$ComputerPSSession = New-PSSession -ComputerName $ServerList.servers.server.name -Credential $Credential
$params =@(
@{
ComputerName = 'ComputerName1'
Counter = $MetricList
SampleInterval = 3
MaxSamples = 3
},
@{
ComputerName = 'ComptuerName2'
foreach ($server in $ServerList) {
#Generate all variables
$resultCounters = Invoke-Command -ComputerName $server -Credential $Credential -ScriptBlock {
param(
$MetricList
)
Get-Counter -Counter $MetricList -SampleInterval 10 -MaxSamples 10
} -ArgumentList $MetricList
$resultCounters | Export-Counter -Path $path -FileFormat $fileFormat
$disabled_OnlineMembership | ConvertTo-Json -Depth 99| Out-File c:\AdminTools\disabled_onlinemembership.json
#Export For further 'human' processing through excel:
$disabled_OnlineMembership | Select-Object UserName,DisplayName,Enabled,UserDN,AADUserObjectID,
@{n='Groups';e={$_.GroupName -join ','}},
@{n='GroupMail';e={$_.GroupMail -join ','}} |
Export-Csv -Path c:\AdminTools\disabled_onlinemembership.csv -NoTypeInformation
$userOUs = @('OU=Leavers,OU=Site1,OU=Contoso Users,DC=Contoso,DC=com','OU=Leavers,OU=Site2,OU=Contoso Users,DC=Contoso,DC=com')
$disabledUsers = foreach ($ou in $userOUs) {
get-aduser -filter {Enabled -eq $false} -SearchBase $ou
}
$disabledUsers | Export-Csv -Path C:\AdminTools\disabled_users.csv -NoTypeInformation
function Get-EmptyFolder {
<#
.SYNOPSIS
Returns if there are empty folders in given path.
.DESCRIPTION
Will check for empty folders in given path. If ComputerName is provided will connect to remote computer. Credential parameter works in combination with ComputerName only
.PARAMETER Path
Path to check for empty folders
function Set-ClusterVMPossibleOwner {
<#
.SYNOPSIS
Will configure Possible Owners for Virtual Machine running on Failover Cluster
.DESCRIPTION
Uses Invoke-Command to allow for PSCredential.
If PossibleOwner is provided first will verify if it matches cluster Owner Nodes.
If yes - will set PossibleOwner for given VMs.
If no - will abort.
function Set-ClusterVMPreferredOwner {
<#
.SYNOPSIS
Will configure Preferred Owners for Virtual Machine running on Failover Cluster
.DESCRIPTION
Uses Invoke-Command to allow for PSCredential
If Preferred Owner is provided will verify if it matches cluster Owner Nodes.
If yes - will set Preferred Owners for given VMs.
If no - will abort.