Skip to content

Instantly share code, notes, and snippets.

mczerniawski mczerniawski

  • Arcon
Block or report user

Report or block mczerniawski

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View Get-VMInventory.ps1
function Get-VMInventory {
<#
.SYNOPSIS
Retrieves detailed information about VMs from Hyper-V host or cluster
.DESCRIPTION
Retrieves information about a VM, it's disk, path, current resources and network properties.
Will query Hyper-V host or all nodes in a cluster if [$Cluster] is provided. Accepts [$Credential] parameter.
.PARAMETER ComputerName
View Transcript.ps1
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
View NewDiskFormatted.ps1
#optional
#$Creds = Get-Credential #Credki do VM - moga byc domenowe lub lokalne
$NewVMDiskProps = @{
VMProps = @{
ComputerName = 'HyperV'
VMName = 'VMName1'
}
VHDProps = @(
@{
View Add-AHVMDisk.ps1
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.
View GetCounter1.ps1
$ComputerPSSession = New-PSSession -ComputerName $ServerList.servers.server.name -Credential $Credential
$params =@(
@{
ComputerName = 'ComputerName1'
Counter = $MetricList
SampleInterval = 3
MaxSamples = 3
},
@{
ComputerName = 'ComptuerName2'
View GetCounter.ps1
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
View CleanAzureAD_4.ps1
$UsersToClean = Get-Content -Path 'c:\AdminTools\disabled_onlinemembership.json ' -RAW | ConvertFrom-Json
#Remove from groups
foreach ($onlineUser in $UsersToClean) {
Write-Host "Processing user {$($onlineUser.DisplayName)}"
foreach ($group in $onlineUser.AADGroupID) {
Write-Host " Processing group {$($group)}"
Remove-AzureADGroupMember -ObjectId $group -MemberId $onlineUser.AADUserObjectID
}
}
View CleanAzureAD_3.ps1
$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
View CleanAzureAD_2.ps1
#Get Credentials to O365 tenant
$credential = Get-Credential
Connect-AzureAD -Credential $credential
$disabled_OnlineMembership = foreach ($user in $disabledUsers) {
if ($user.UserPrincipalName) {
$userObjectId = Get-Msoluser -UserPrincipalName $user.UserPrincipalName | Select-Object -ExpandProperty ObjectId
$group = Get-AzureADUserMembership -ObjectId $userObjectId | Select-Object * | Where-Object {-not ($_.DirSyncEnabled)}
if ($group) {
[pscustomobject]@{
UserName = $user.SamAccountName
View CleanAzureAD_1.ps1
$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
You can’t perform that action at this time.