Yubikey smartcard insert/remove notifications - yubikey

The Powershell code is to find out which USB is communicating with the computer which is working fine.
while ($true) {
If( gwmi win32_diskdrive | where{$_.Interfacetype -eq "USB" } ) {
Start-Sleep -Seconds 1
Write-Host "$computer Connected" -ForegroundColor Green
}
else {
Start-Sleep -Seconds 1
Write-Host "$computer Not Connected" -ForegroundColor Red
}
}
I usually use Yubikey, but Windows recognizes it as a smartcard.
Class gwmi win32_diskdrive works fine with USB flash memory.
Class gwmi Win32_PnPEntity can show Yubikey but not trigger notifications as USB in the code.
Any suggestions?

Related

Azure Logic App - How can I re-started my operations failed?

I have many operations failed in my Azure Logic App.
I see that if you click on a single operation on the Azure portal you can re-started the operation:
Is it possible to select ALL of these failed operations, and re-run all together?
Thanks a lot guys
If you want to resubmit one or more logic app runs that failed, succeeded, or are still running, you could bulk resubmit Logic Apps from the Runs Dashboard.
About how to use this function, you could refer to this article:Monitor logic apps with Azure Monitor logs. Under the tile View logic app run information, you could find the Resubmit description.
Alternative to bulk resubmit Logic Apps from the Runs Dashboard, you can utilize the PowerShell commands. Take a look at the script below, which can automate listing Failed logic app runs, identify triggers, actions responsible and restart the apps by input ResourceGroupName. You can change some of those bits as per your needs. (skip the interactions and just restart apps again) I have just show it for understanding.
Using: Get-AzLogicApp, Get-AzLogicAppRunHistory ,
Get-AzLogicAppRunAction, Get-AzLogicAppTrigger and Start-AzLogicApp
cmdlets.
Script using Az PowerShell 6.2 Module: Az.LogicApp [Copy below to file, say restart.ps1 and run] Make sure you assign $rg with your actual AzResourceGroup name
$rg = "MyResourceGrp"
#get logic apps
$logicapps = Get-AzLogicApp -ResourceGroupName $rg
Write-Host "logicapps:" -ForegroundColor "Yellow"
write-output $logicapps.Name
#list all logicapp runs failed
$failedruns = #(foreach($name in $logicapps.Name){
Get-AzLogicAppRunHistory -ResourceGroupName $rg -Name $name | Where {$_.Status -eq 'Failed'}
})
Write-Host "failedruns:" -ForegroundColor "Yellow"
Write-Output $failedruns.Name | select -Unique
Write-Host "failedruns: LogicAppNames" -ForegroundColor "Yellow"
Write-Output $failedruns.Workflow.Name | select -Unique
#list all logicappRunsActions failed
foreach($i in $logicapps){
foreach($y in $failedruns){
if ($i.Version -eq $y.Workflow.Name) {
$resultsB = Get-AzLogicAppRunAction -ResourceGroupName $rg -Name $i.Name -RunName $y.Name -FollowNextPageLink | Where {$_.Status -eq 'Failed'}
}
}
}
foreach($item in $resultsB){
Write-Host "Action:" $item.Name " " -NoNewline "Time:" $item.EndTime
Write-Output " "
}
#get logicapp triggers
foreach($ii in $logicapps){
foreach($yy in $failedruns){
if ($ii.Version -eq $yy.Workflow.Name) {
$triggers = Get-AzLogicAppTrigger -ResourceGroupName $rg -Name $ii.Name
}
}
}
Write-Host "triggers:" -ForegroundColor "Yellow"
Write-Output $triggers.Name
#start logic apps with triggers
Write-Host "Starting logic apps....." -ForegroundColor "green"
foreach($p in $logicapps){
foreach($tri in $triggers){
if ($p.Version -eq $triggers.Workflow.Name) {
Start-AzLogicApp -ResourceGroupName $rg -Name $p.Name -TriggerName $tri.Name
}
}
}
$verify = Read-Host "Verify ruuning app? y or n"
if ($verify -eq 'y') {
$running = #(foreach($name2 in $logicapps.Name){
Get-AzLogicAppRunHistory -ResourceGroupName $rg -Name $name2 | Where {$_.Status -eq 'Running' -or $_.Status -eq 'Waiting'}
})
Write-Host $running
}
else {
Write-Host "Bye!"
}
Although my LogicApp has failed again, but you can see it was triggered in time by script
Note: If your logic app trigger expects inputs or actions (unlike recurrence or scheduled) please edit or make changes accordingly for Start-AzLogicApp command to execute successfully.
Here I am considering all logic apps are enabled (use -State Enabled) parameter for Get-AzLogicApp command if you want to run this on only currently enabled apps.
Example: Get-AzLogicApp -ResourceGroupName "rg" | where {$_.State -eq 'Enabled'}
2. You can also try advanced settings for triggers in workflow. Such as retry policy.
You can specify it to retry at custom intervals in case of failures due to an intermittent issues.
You can submit a feedback or Upvote a similar Feedback : ability-to-continue-from-a-particular-point-as-in
Refer: help topics for the Logic Apps cmdlets

How to do a full site collecion level re-index in sharepoint online?

After adding a new managed property I need to do a full site collection level or tenant level re-indexing to get the search crawler run. But I could not find a way to do this in SharePoint online.Is there a way to do this?
There is a script to re-index a SharePoint online site collection via CSOM. I think this will help you to re-index your 100+ subsites.
#Grab the tenant information
$username = Read-Host "Enter the tenant admin account login"
$password = Read-host -AsSecureString "Enter the admin account password"
$siteUrl = Read-Host "Please enter the site collection URL to re-index"
Write-Host "Would you like to populate the managed properties on all lists post re-crawl (ex. Cross Site Publishing)?" -ForegroundColor Green
Write-Host "1. Yes - enable managed properties on all lists in this site!" -ForegroundColor Cyan
Write-Host "2. No - Turn off managed properties in all lists in the site!" -ForegroundColor Blue
Write-Host "3. No - Just re-index the site!" -ForegroundColor Red
$enableAllManagedProperties = Read-Host "Choice [1-3]?"
$date = (Get-Date).ToString("yyyyMMdd")
#Load the assemblies
$load1 = [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Client")
$load2 = [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Client.Runtime")
$load3 = [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Client.UserProfiles")
if (!$load1) {
$script_folder = (Split-Path -Parent $MyInvocation.MyCommand.Path)
$load1 = [System.Reflection.Assembly]::LoadFile($script_folder + "\Microsoft.SharePoint.Client.dll")
if (!$load1) {
Write-Host "Failed to load Microsoft.SharePoint.Client.dll - please ensure it is in the same location as the PS1." -ForegroundColor Red
write-host "Alternatively, install the SPO Client Components SDK from http://www.microsoft.com/en-us/download/details.aspx?id=42038" -ForegroundColor Red
exit;
}
}
if (!$load2) {
$script_folder = (Split-Path -Parent $MyInvocation.MyCommand.Path)
$load2 = [System.Reflection.Assembly]::LoadFile($script_folder + "\Microsoft.SharePoint.Client.Runtime.dll")
if (!$load2) {
Write-Host "Failed to load Microsoft.SharePoint.Client.Runtime.dll - please ensure it is in the same location as the PS1." -ForegroundColor Red
write-host "Alternatively, install the SPO Client Components SDK from http://www.microsoft.com/en-us/download/details.aspx?id=42038" -ForegroundColor Red
exit;
}
}
if (!$load3) {
$script_folder = (Split-Path -Parent $MyInvocation.MyCommand.Path)
$load3 = [System.Reflection.Assembly]::LoadFile($script_folder + "\Microsoft.SharePoint.Client.UserProfiles.dll")
if (!$load3) {
Write-Host "Failed to load Microsoft.SharePoint.Client.UserProfiles.dll - please ensure it is in the same location as the PS1." -ForegroundColor Red
write-host "Alternatively, install the SPO Client Components SDK from http://www.microsoft.com/en-us/download/details.aspx?id=42038" -ForegroundColor Red
exit;
}
}
function Connect-SPO($siteUrl) {
$clientContext = New-Object Microsoft.SharePoint.Client.ClientContext($siteUrl)
$clientContext.Credentials = $credentials
if (!$clientContext.ServerObjectIsNull.Value) {
Write-Host "Connected to SharePoint Online site: '$siteUrl'" -ForegroundColor Green
}
$rootWeb = $clientContext.Web
processWeb($rootweb)
}
function processWeb($web) {
$subWebs = $web.Webs
$clientContext.Load($web)
$clientContext.Load($web.AllProperties)
$clientContext.Load($subWebs)
try
{
$clientContext.ExecuteQuery()
}
catch
{
write-host "Error on $($clientContext) - $($_)" -ForegroundColor Red
Write-Host "It's possible you are not an administrator on the site collection - Exiting the script" -ForegroundColor Red
Sleep 10
Exit
}
Write-Host "Web URL:" $web.Url -ForegroundColor White
if ( $enableAllManagedProperties -ne "3" ) {
Set-AllManagedProperties -web $web -clientContext $clientContext -enableAllManagedProps $enableAllManagedProperties
}
[int]$version = 0
$allProperties = $web.AllProperties
if ( $allProperties.FieldValues.ContainsKey("vti_searchversion") -eq $true ) {
$version = $allProperties["vti_searchversion"]
}
$version++
$allProperties["vti_searchversion"] = $version
Write-Host "-- Updated search version: " $version -ForegroundColor Green
$web.Update()
$clientContext.ExecuteQuery()
# No need to process subwebs if we only mark site collection for indexing
if ($enableAllManagedProperties -ne "3") {
foreach ($subWeb in $subWebs) {
processWeb($subWeb)
}
}
}
function Set-AllManagedProperties( $web, $clientContext, $enableAllManagedProps ) {
$lists = $web.Lists
$clientContext.Load($lists)
$clientContext.ExecuteQuery()
foreach ($list in $lists) {
Write-Host "--" $list.Title
if ( $list.NoCrawl ) {
Write-Host "-- Skipping list due to not being crawled" -ForegroundColor Yellow
continue
}
$skip = $false;
$eventReceivers = $list.EventReceivers
$clientContext.Load($eventReceivers)
$clientContext.ExecuteQuery()
foreach ( $eventReceiver in $eventReceivers ) {
if ( $eventReceiver.ReceiverClass -eq "Microsoft.SharePoint.Publishing.CatalogEventReceiver" ) {
$skip = $true
Write-Host "-- Skipping list as it's published as a catalog" -ForegroundColor Yellow
break
}
}
if ( $skip ) {continue}
$folder = $list.RootFolder
$props = $folder.Properties
$clientContext.Load($folder)
$clientContext.Load($props)
$clientContext.ExecuteQuery()
if ( $enableAllManagedProps -eq "1" ) {
Write-Host "-- Enabling all managed properties" -ForegroundColor Green
$props["vti_indexedpropertykeys"] = "UAB1AGIAbABpAHMAaABpAG4AZwBDAGEAdABhAGwAbwBnAFMAZQB0AHQAaQBuAGcAcwA=|SQBzAFAAdQBiAGwAaQBzAGgAaQBuAGcAQwBhAHQAYQBsAG8AZwA=|"
$props["IsPublishingCatalog"] = "True"
}
if ( $enableAllManagedProps -eq "2" ) {
Write-Host "-- Disabling all managed properties" -ForegroundColor Green
$props["vti_indexedpropertykeys"] = $null
$props["IsPublishingCatalog"] = $null
}
$folder.Update()
$clientContext.ExecuteQuery()
}
}
#SPO Credentials
$credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($username, $Password)
Connect-SPO -siteUrl $siteurl
if ($version -ne "$null" ) {
Write-Host "Re-index has should now have been succesfully triggered for $siteurl - Please remember that this can take some time before the crawl picks up the index." -ForegroundColor Cyan
}
https://gallery.technet.microsoft.com/office/Re-index-a-Sharepoint-e70d285b
Note: This will not improve crawl time, merely ensure items are re-indexed.
You need to go to the Site Settings > Search and Offline Availability link and then press the reindex option as in below image.
You need to be site collection admin or owner to view these settings:
Updated as per comments:
To trigger a full site collections reindex, you need to make use of PS script as in this link.

Thread does not create multiple VMs (session issue)

Data is taken from *.CSV file. Script should create in my test case 2 VM on the same vcenter but in different thread. Need guidance how to solve this.
cls
Add-PSSnapin VMware.VimAutomation.Core | Out-Null
#import VM settings
$VMs = Import-CSV '...\Data.csv' -UseCulture
#array for connections
$server = #()
#threads
$Throttle = 2
# Create session state
$sessionState = [System.Management.Automation.Runspaces.InitialSessionState]::CreateDefault()
# Create runspace pool consisting of runspaces
$RunspacePool = [RunspaceFactory]::CreateRunspacePool(1, $Throttle, $sessionState, $Host)
$RunspacePool.Open()
#array for jobs
$Jobs = #()
$global:DefaultVIServer
$ScriptBlocky = {
Param ($VM, $ses)
Add-PSSnapin VMware.VimAutomation.Core | Out-Null
Write-Host $VM.vm_name "Father session: " $ses.SessionSecret
$sessionf = Connect-VIServer $VM.vs_xstream__vc_host -Session $ses.SessionSecret -wa 0
Write-Host $VM.vm_name "Child session: " $sessionf.SessionId
$domain_name = $VM.FQDN.split('.')
Write-Host $domain_name
#Random for testing purposes
$OSspec = ("BasicLinuxSpec_rand{0}" -f (Get-Random))
# Create new OS Customization Specification template for further usage
New-OSCustomizationSpec –Name $OSspec –Domain ("{0}.{1}" -f $domain_name[1],$domain_name[2]) –DnsServer $VM.DNS,$VM.DNS2 –NamingScheme VM –OSType Linux
Get-OSCustomizationSpec $OSspec -Server $VM.vs_xstream__vc_host | Get-OSCustomizationNicMapping | Set-OSCustomizationNicMapping -IpMode UseStaticIp -IpAddress $VM.Ipaddress -SubnetMask $VM.NetMask -DefaultGateway $VM.Gateway
Write-Host $VM.vm_name "OSspec: "$OSspec
Write-Host $VM.vm_name "Cluster: "$VM.Cluster
Write-Host $VM.vm_name "Host: "$VM.vs_xstream__vc_host
# Selecting random Cluster for VMs deployment
$ClusterHost = Get-Cluster $VM.Cluster -server $VM.vs_xstream__vc_host | Get-VMHost | Get-Random
Write-Host "================="
Write-Host $VM.vm_name "ClusterHost " $ClusterHost
Write-Host "================="
New-Vm -VMhost $ClusterHost -Name $VM.vm_name -Server $VM.vs_xstream__vc_host -Datastore $VM.Datastore -Template $VM.Template -Description $VM.Description -DiskStorageFormat "Thin" -OScustomizationSpec $OSspec
Remove-OSCustomizationSpec $OSspec -Server $VM.vs_xstream__vc_host -confirm:$false
}
Write-Host ("Starting script: {0}" -f (Get-Date))
$startTime = Get-Date
$count = 0
ForEach($VM in $VMs)
{
$count = $count + 1
Write-Host $VM.vs_xstream__vc_host
Write-Host "Current connections:"
$Global:DefaultVIServers.count
$ses = Connect-VIServer $VM.vs_xstream__vc_host -User $VM.vs_xstream__vc_admin -Password $VM.vs_xstream__vc_password -wa 0
$Job = [powershell]::create()
$Job.RunspacePool = $RunspacePool
$Job.AddScript($ScriptBlocky).AddParameter("VM", $VM).AddParameter("ses", $ses)
Write-Host "Adding job to jobs list"
$Jobs += New-Object PSObject -Property #{
RunNum = $count
Job = $Job
Result = $Job.BeginInvoke()
}
#Disconnect-VIServer $VM.vs_xstream__vc_host -Confirm:$false -Force
}
Write-Host "Waiting.." -NoNewline
Do {
Write-Host "." -NoNewline
Start-Sleep -Seconds 1
} While ( $Jobs.Result.IsCompleted -contains $false)
$endTime = Get-Date
$totalSeconds = "{0:N4}" -f ($endTime-$startTime).TotalSeconds
Write-Host "All jobs finished in $totalSeconds seconds"
Results:
Name Port User
---- ---- ----
10.xxx.xx.10 443 VSPHERE.LOCAL\do1xstream
Starting script: 2/29/2016 2:48:20 PM
10.xxx.xx.10
Current connections:
1
Adding job to jobs list
10.xxx.xx.10
Current connections:
1
The specified mount name 'vmstores' is already in use.
The specified mount name 'vis' is already in use.
virtual38 Father session: f8bafd42e6b7c85aa313e2896eba11c0f9f876cf
Adding job to jobs list
virtual38 Child session: f8bafd42e6b7c85aa313e2896eba11c0f9f876cf
virtual38 domain com
Waiting...virtual39 Father session: f8bafd42e6b7c85aa313e2896eba11c0f9f876cf
virtual39 Child session:
virtual39 domain com
virtual39 OSspec: BasicLinuxSpec_rand618798101
virtual39 Cluster: do1mgmt
virtual39 Host: 10.xxx.xx.10
=================
virtual39 ClusterHost
=================
virtual38 OSspec: BasicLinuxSpec_rand581276505
virtual38 Cluster: do1mgmt
virtual38 Host: 10.xxx.xx.10
.=================
virtual38 ClusterHost 10.xxx.xx.2
=================
..............
As result shows because virtual38 was first in line it has session information and can perform actions.
maybe i am wrong about this I think session isssue is preventing to create second VM (virtual39 )
Update/notice: I realized that when threads $Throttle = 1 then both VM is created, when I set $Throttle = 2 or more then only one of them (first one) is created.
Any suggestions?
Believe me or not but I found what was wrong. Script is working, but when connecting to new session or existing one (or even different vCenter, when is need to create VM in more then one vCenter environment) DefaultVIServers variable is modified and session drops.
Solution:
* Create all connection to vCenter's before all other actions so connection would be stable. for example:
# Iterate and connect to all vCenters so connections to them will be stable and read only
ForEach($VM in $VMs)
{
If ($VM.Use -eq 1)
{
If($server.Contains($VM.vs_xstream__vc_host) -eq $FALSE)
{
$server += $VM.vs_xstream__vc_host
$AllSessions += Connect-VIServer $VM.vs_xstream__vc_host -User $VM.vs_xstream__vc_admin -Password $VM.vs_xstream__vc_password -NotDefault
Write-Host "Connected to: " $VM.vs_xstream__vc_host
}
}
}
After all work is done i simply disconnect from all sessions
# Disconnect all created sessions
ForEach($item in $server)
{
Write-Host ("Disconnecting from {0}...." -f ($item))
Disconnect-VIServer $item -Confirm:$false
}
Now script works perfectly and creates VM in different or the same vCenter. if anyone will experience any problems with it let me know.

Get programmatically User Roles and Permissions in SSRS 2008

I use SSRS 2008 on Windows 2008 R2.
How can I get the user list of roles and permissions (Reports Manager Roles such as Browser, Content Manager, etc) using Powershell or C# (programmatically)?
Any suggestions ?
Notes:
"Folder Settings" area where you can specify roles for a user - "Content Manager," "Publisher," "Browser," "Report Builder," and "My Reports"
SSRS has 2 security/role sections available in the web GUI: Folder Settings and Site Settings.
I try with my script powershell.
References: http://www.bi-rootdata.com/2015/03/list-ssrs-items-permissions-using.html by Anup Agrawal comment
Usage:
$ScriptDirectory = Split-Path $MyInvocation.MyCommand.Path
Clear-Host
Write-Host $ScriptDirectory
Write-Host $env:COMPUTERNAME -ForegroundColor Yellow
Write-Host $env:USERNAME -ForegroundColor Yellow
$ReportServerUri = 'http://localhost/ReportServer/ReportService2005.asmx'
$InheritParent = $true
$SourceFolderPath = '/'
$outSSRSSecurity=#()
$Proxy = New-WebServiceProxy -Uri $ReportServerUri -Namespace SSRS.ReportingService2005 -UseDefaultCredential
$items = $Proxy.ListChildren($sourceFolderPath, $true)|Select-Object Type, Path, Name|Where-Object {$_.type -eq "Folder"};
foreach($item in $items)
{
#Write-Host $item
if ($item.Name -ne "TestsCustomCDR")
{
#continue;
}
Write-Host $item.Path -ForegroundColor Yellow
Write-Host $item.Name -ForegroundColor Green
Add-Member -InputObject $item -MemberType NoteProperty -Name PolicyGroupUserName -Value '';
foreach($policy in $Proxy.GetPolicies($item.path, [ref]$InheritParent))
{
Write-Host $policy.GroupUserName
$objtemp=$item.PsObject.Copy();
$objtemp.PolicyGroupUserName=$policy.GroupUserName;
$outSSRSSecurity += $objtemp;
$objtemp.reset;
}
}
$outSSRSSecurity|Export-csv SSRSSecurityOutput.csv -NoTypeInformation;

Enabling Sharepoint Features With Powershell

I am new to PowerShell and have been asked to modify a script that is used to activate features on a site. The script has some latency issues between the two feature activations, so I decided to make a new function that will enable the feature and sleep or delay until the feature is finished enabling. Will this work? And if so, how can I tell that the feature is finished activating?
# This is a function that enable's a Sharepoint Feature and Sleeps Until Its Finished Enabling
function Feature-Enable
{param ([string]$ID, [string]$URL)
#Enable Feature
Enable-SPFeature -Identity $ID -url $URL -Confirm:$false
#Sleep Until Feature is Done Enabling
}
#Set parameters/variables for script
$serverName = "someServerName"
$rootwebUrl = "someRootUrl"
$currentpath=Split-Path -Path $MyInvocation.MyCommand.Path -Parent
$siteURL = "http://" + $servername + $rootwebURL
$start = Get-Date -DisplayHint Time
# check to ensure Microsoft.SharePoint.PowerShell is loaded
$snapin = Get-PSSnapin | Where-Object {$_.Name -eq 'Microsoft.SharePoint.Powershell'}
if ($snapin -eq $null) {
Write-Host "Loading SharePoint Powershell Snapin"
Add-PSSnapin "Microsoft.SharePoint.Powershell"
}
# Active Site Collection Features (in order)
write-host ""
write-host "----------------------------------------"
write-host "Begin activation of site collection features"
write-host "----------------------------------------"
write-host ""
Feature-Enable –identity "3cbf5d1e-ff2e-48d2-82a4-99b060381268" -URL $siteUrl
#NOTE: POTENTIAL LATENCY ISSUES. MAY NEED TO INSERT DELAY TIMER!
Feature-Enable –identity "bbde524e-9293-468e-84f7-fdb763ffa309" -URL $siteUrl
write-host ""
write-host "----------------------------------------"
write-host "Activation of site collection features - DONE!"
write-host "----------------------------------------"
write-host ""
$end= Get-Date -DisplayHint Time
Write-Host "Started at: " $start " Ended at: " $end;
function WaitForJobToFinish([string]$SolutionFileName)
{
$JobName = "*solution-deployment*$SolutionFileName*"
$job = Get-SPTimerJob | ?{ $_.Name -like $JobName }
if ($job -eq $null)
{
Write-Host 'Timer job not found'
}
else
{
$JobFullName = $job.Name
Write-Host -NoNewLine "Waiting to finish job $JobFullName"
while ((Get-SPTimerJob $JobFullName) -ne $null)
{
Write-Host -NoNewLine .
Start-Sleep -Seconds 2
}
Write-Host "Finished waiting for job.."
}
}

Resources