Posts Tagged ‘powershell’

Open Powershell As Administrator

Import-Module NTFSSecurity

#Check Existing Access

dir2 “\\?\e:\folde\path\name” -Recurse | Get-NTFSAccess

#Take Ownership

dir2 “\\?\e:\folde\path\name” -Recurse | Set-NTFSOwner -Account “Administrators”

#Add Permissiosn

dir2 “\\?\e:\folde\path\name” -Recurse | Add-NTFSAccess -Account Administrators -AccessRights FullControl

#recheck Access

dir2 “\\?\e:\folde\path\name” -Recurse | Get-NTFSAccess

Prove access for a user

Get-ChildItem -Path c:\docs -Recurse -Directory | Get-NTFSEffectiveAccess -Account ‘corp\confroom’ | select Account, AccessControlType, AccessRights, FullName

GD Star Rating
loading...
GD Star Rating
loading...

You can send emails via Mimecast instead of 365 , so you don’t need a licensed 365 user.

Login and enable SMTP Email submissions for that user

Use the users Cloud password and email address for Auth

$creds = get-credential

Send-MailMessage -From [email protected] -To [email protected] -Subject "Test Email" -Body "Test SMTP Service from Powershell on Port 587" -SmtpServer au-smtp-outbound-1.mimecast.com -Credential $creds -UseSsl -Port 587

 

If you see

Send-MailMessage : Unable to read data from the transport connection: net_io_connectionclosed

You need to create an Authentication profile with 2fa disabled , and apply it to that user via Application Settings

 

“Send-MailMessage : A call to SSPI failed, see inner exception”

Trying to send email comes back with this error , you need to change TLS1.2

‘ServicePointManager.SecurityProtocol’ is not recognized as the name

Trying to use

ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
to Force TLS 1.2 doesn’t work 
 
 
Use 
 
# Enable TLS 1.2 as Security Protocol
[Net.ServicePointManager]::SecurityProtocol = `
    [Net.SecurityProtocolType]::Tls12 ;
 
 
 
 
 
 
GD Star Rating
loading...
GD Star Rating
loading...

You can target the following powershell below to update items in desktop-config.json such as 

disableGpu\openAtLogin\registerAsIMProvider\runningOnClose

(Get-Content $ENV:APPDATA\Microsoft\Teams\desktop-config.json).replace(‘”disableGpu”:false’, ‘”disableGpu”:true’) | Set-Content $ENV:APPDATA\Microsoft\Teams\desktop-config.json
(Get-Content $ENV:APPDATA\Microsoft\Teams\desktop-config.json).replace(‘”openAtLogin”:true’, ‘”openAtLogin”:false’) | Set-Content $ENV:APPDATA\Microsoft\Teams\desktop-config.json

 

GD Star Rating
loading...
GD Star Rating
loading...

 Report % Rate of change from the last Backup Job Run

Add-PSSnapin -Name VeeamPSSnapIn -ErrorAction SilentlyContinue

Disconnect-VBRServer | out-null

connect-vbrserver -server localhost

$JobsOutput = @()

Foreach ($JobObject in Get-VBRJob | ?{$_.JobType -eq "Backup"})

{

$LastSession = $JobObject.FindLastSession()

$ChangeRate = ($LastSession.Info.Progress.TransferedSize/$LastSession.Info.Progress.TotalUsedSize)*100

$JobOutput = New-Object -TypeName PSObject

$JobOutput | Add-Member -Name "Jobname" -MemberType Noteproperty -Value $JobObject.Name

$JobOutput | Add-Member -Name "Endtime" -MemberType Noteproperty -Value $LastSession.endtime

$JobOutput | Add-Member -Name "TotalUsedSize" -MemberType Noteproperty -Value $LastSession.Info.Progress.TotalUsedSize

$JobOutput | Add-Member -Name "ReadSize" -MemberType Noteproperty -Value $LastSession.Info.Progress.ReadSize

$JobOutput | Add-Member -Name "TransferedSize" -MemberType Noteproperty -Value $LastSession.Info.Progress.TransferedSize

$JobOutput | Add-Member -Name "ChangeRate" -MemberType Noteproperty -Value $ChangeRate

$JobsOutput += $JobOutput

}

$JobsOutput | Out-GridView

Disconnect-VBRServer | out-null

However one result is not a fair estimate of rate of change , and I don’t have a Veeam One license so I decided to Average Stuff

You can run on One VM or all the VM’s in a Backup Job

Add-PSSnapin -Name VeeamPSSnapIn -ErrorAction SilentlyContinue

connect-vbrserver -server localhost

#Query to get all jobs in the time period in hours that have processed data (Data ne 0 ) and have completed

$vbrtasksessions = (Get-VBRBackupSession |

Where-Object {($_.EndTime -ge (Get-Date).addhours(-168) -or $_.CreationTime -ge (Get-Date).AddHours(-168) -or $_.State -eq "Working")}) | Get-VBRTaskSession | Where-Object {$_.Status -notmatch "Idle|InProgress|Pending|Fail"-and $_.Info.Progress.TotalSize -ne "0"}

#Get Backup Job and VM

#$getOne = $vbrtasksessions | ? {$_.JobName -eq "%Veeam Backup or Backup Copy Name%" -and $_.Name -eq "%Name of Server%"}

#Or Get Whole Backup Job and average between all the machines

#$getOne = $vbrtasksessions | ? {$_.JobName -eq "%Veeam Backup or Backup Copy Name%"}

#Cannot Get Total usedSize in Backup

Echo ListofAllFullSizesInBytes $getOne.Info.Progress.TotalSize

#Echo AverageTotalFullBackupSizeInGB $([Math]::Round([Decimal]($getOne.Info.Progress.TotalSize | Measure-Object -Average).Average/1GB, 2))

Echo ListofIntcrementalSizeinBytess $getOne.Info.Progress.TransferedSize

#Echo AverageIntSizeinGB $([Math]::Round([Decimal]($getOne.Info.Progress.TransferedSize | Measure-Object -Average).Average/1GB, 2))

Echo RateofChangein% ((($getOne.Info.Progress.TransferedSize | Measure-Object -Average).Average/($getOne.Info.Progress.TotalSize | Measure-Object -Average).Average)*100)

Disconnect-VBRServer | out-null
GD Star Rating
loading...
GD Star Rating
loading...

Login to Azure Active Directory. Locate Usage & insights , under Monitoring

Select “Users registerd for Multi-Factor Authentication”

 

 

Can also be done in powershell : https://dirteam.com/sander/2020/05/14/todo-optimize-the-azure-multi-factor-authentication-methods-used-throughout-your-organization/

Monitoring with PowerShell: Monitoring the used MFA type for O365/Azure.

GD Star Rating
loading...
GD Star Rating
loading...

I have been using this plugin to https://wordpress.org/plugins/pastacode/

highlight some of my programming. I write a bit in Powershell however this is not a supported markup. This is what to add to your functions file of your theme to add another library

/** pastcode plugin */
add_filter( 'pastacode_langs', '_pastacode_langs' );
function _pastacode_langs( $langs ) {
	$langs['powershell'] = 'Powershell';
	return $langs;
}

add_filter( 'pastacode_tinymcevars', '_pastacode_tinymcevars' );
function _pastacode_tinymcevars( $pvars ) {
	$pvars['scripts']['powershell']=get_template_directory_uri().'/js/powershell.js';
	$array=array(
			'libs'      => array('powershell'),
			'mode'      => 'application/x-powershell',
			);

	$pvars['language_mode']['powershell']=$array;
	return $pvars;
}

add_action('wp_enqueue_scripts', 'mytheme_scripts');

function mytheme_scripts() {
  wp_dequeue_script( 'prismjs' );
  wp_deregister_script( 'prismjs' );
  wp_enqueue_script( 'prismjs',  get_template_directory_uri().'/js/prism.js', false,PASTACODE_VERSION, true );
} 

 

You will also need to create a js folder and upload the new .js library from https://codemirror.net/mode/ and prism.js

GD Star Rating
loading...
GD Star Rating
loading...

For auditing purposes you will need to report on the updates install on a server and the install status. 

Below is a  powershell script that does just that

 

[email protected]('Unk','Installation','Uninstallation','Other')
[email protected]('Unk','In Progress','Succeeded','Succeeded With Errors','Failed','Aborted')

$updateSession=New-Object -ComObject Microsoft.Update.Session
$updateSearcher=$updateSession.CreateUpdateSearcher() 
$historyCount=$updateSearcher.GetTotalHistoryCount() 
$updateSearcher.QueryHistory(0, $historyCount) | 
    Select-Object Date,
                @{N='Operation';E={$operation[$_.operation]}},
                @{N='Status';E={$resultCode[$_.resultcode]}},
                Title |
    Format-Table -AutoSize
GD Star Rating
loading...
GD Star Rating
loading...
$Days = $%id%Days%id%

$Days = (get-date).adddays(-($Days))

$SnapshotList = $null

$SnapshotList = Get-VM | Get-VMSnapshot | where-object { $_.CreationTime -lt $Days }

	if ($SnapshotList -eq $null)
	{
		$OverdueSnapshot = "NO Overdue Snapshot"
	}
	else
	{
		foreach ($EachSS in $SnapshotList)
		{
			$OverdueSnapshot += "$EachSS.VMName : $EachSS.Name : $EachSS.CreationTime : "
		}
	}

$%id%OverdueSnapshot%id% = $OverdueSnapshot
GD Star Rating
loading...
GD Star Rating
loading...

You will need to update the CompanyName to yours

#Change AutoSaveLocation to OneDrive



$onedrivelocation = %userprofile%\OneDrive - **CompanyName**\



mkdir "$onedrivelocation\Autorecover\Word\"

New-ItemProperty -path "HKCU:\Software\Microsoft\Office\16.0\Word\Options" -Name AUTOSAVE-PATH -PropertyType "ExpandString" -Value "$onedrivelocation\Autorecover\Word\"

mkdir "$onedrivelocation\Autorecover\Excel\"

New-ItemProperty -path "HKCU:\Software\Microsoft\Office\16.0\excel\Options" -Name AutoRecoverPath -PropertyType "ExpandString" -Value "$onedrivelocation\Autorecover\Excel\"

mkdir "$onedrivelocation\Autorecover\Powerpoint\"

New-ItemProperty -path "HKCU:\Software\Microsoft\Office\16.0\PowerPoint\Options" -Name PathToAutoRecoveryInfo -PropertyType "ExpandString" -Value "$onedrivelocation\Autorecover\Powerpoint\"
GD Star Rating
loading...
GD Star Rating
loading...