Posts Tagged ‘powershell’
Recently trying to install a Module in Powershell gallery on a PC , but came back with an error
PS C:\Windows\system32> Install-Module -Name AsBuiltReport
PackageManagement\Install-Package : No match was found for the specified search criteria and module name
'AsBuiltReport'. Try Get-PSRepository to see all available registered module repositories.
At C:\Program Files\WindowsPowerShell\Modules\PowerShellGet\1.0.0.1\PSModule.psm1:1772 char:21
+ ... $null = PackageManagement\Install-Package @PSBoundParameters
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (Microsoft.Power....InstallPackage:InstallPackage) [Install-Package], Ex
ception
+ FullyQualifiedErrorId : NoMatchFoundForCriteria,Microsoft.PowerShell.PackageManagement.Cmdlets.InstallPackage
Had a check and No Repos were listed
PS C:\Windows\system32> Get-PSRepository | fl *
WARNING: Unable to find module repositories.
Installed the Default Repos again
PS C:\Windows\system32> Register-PSRepository -Default
PS C:\Windows\system32> Get-PSRepository | fl *
Name : PSGallery
SourceLocation : https://www.powershellgallery.com/api/v2
Trusted : False
Registered : True
InstallationPolicy : Untrusted
PackageManagementProvider : NuGet
PublishLocation : https://www.powershellgallery.com/api/v2/package/
ScriptSourceLocation : https://www.powershellgallery.com/api/v2/items/psscript
ScriptPublishLocation : https://www.powershellgallery.com/api/v2/package/
ProviderOptions : {}Y
GD Star Rating
loading...
GD Star Rating
loading...
This is useful for when you have a hyper v host only nope with CLI and no GUI
DRConfigurator.exe /r /friendlyname MyServerName /credentials “C:\Software\vaultname_asr_DayMonthDateYear.VaultCredentials”
GD Star Rating
loading...
GD Star Rating
loading...
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;
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...
Get-ChildItem C:\Temp\*.zip | ren -NewName { "$($_.BaseName)$(get-date -format "_yyyyMMddhhmmss")$($_.extension) "}
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...
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...