cadeia de seleção do powershell não retornando resultados

0

Estou tentando encontrar uma palavra específica (Gate) em um documento com a cadeia de seleção do powershell, e não está retornando nenhum resultado.

Get-ChildItem -path '.\somedocument.docx' | Select-String -pattern 'Gate'

O que estou fazendo de errado? Eu estou na fase inicial do aprendizado do PowerShell.

    
por kkd1988 11.03.2018 / 23:52

1 resposta

0

Desde que você é novo no mundo PoSH. É muito importante que você receba alguma orientação / treinamento primeiro, para evitar que você se perca / fique frustrado. Veja esta discussão.

Help with teaching PowerShell Learning PowerShell https://www.reddit.com/r/PowerShell/comments/7oir35/help_with_teaching_others_powershell

CConard96 está correto em Get-Children, você lê arquivos usando o Get-Content ou as bibliotecas de arquivos .Net.

O PowerShell tem acesso total a qualquer biblioteca .Net, interface COM e DOM fornecida pelo Windows.

Então, você precisa conhecer e usar o conjunto de ferramentas certo. Para o que você está procurando, eu não procuraria o Select-String para este caso de uso.

Você pode usar o PoSH para fazer isso, mas também precisa usar o DOM do Word. Por exemplo:

# Instantiate Word object
$wd = New-Object -com word.application

# Oepn a Word doc
$doc = $wd.Documents.Open('D:\Documents\Microsoft Graph API.docx')

# Read all the doc contents
$doc.Range().text


Microsoft Graph APIList windowsInformationProtectionAppLearningSummariesImportant: APIs under the /beta version in Microsoft Graph are in preview and are subject to change. Use of these APIs in production applicatio
ns is not supported.Note: Using the Microsoft Graph APIs to configure Intune controls and policies still requires that the Intune service is correctly licensed by the customer.https://developer.microsoft.com/en-us/g
raph/docs/api-reference/beta/api/intune_wip_windowsinformationprotectionapplearningsummary_list https://social.technet.microsoft.com/wiki/contents/articles/33525.an-introduction-to-microsoft-graph-api.aspx Using the
 Microsoft Graph API to access data in Microsoft Intunehttps://blogs.technet.microsoft.com/intunesupport/2016/10/04/using-the-microsoft-graph-api-to-access-data-in-microsoft-intune How to use Microsoft Graph and Off
ice 365 API in a Service or in a Windows App/UWP without a graphical interfacehttps://blogs.msdn.microsoft.com/laurelle/2016/02/12/how-to-use-microsoft-graph-and-office-365-api-in-a-service-or-in-a-windows-appuwp-wi
thout-a-graphical-interface 


# Get formatted text
$doc.Range().paragraphs | foreach {$_.range.text}

List windowsInformationProtectionAppLearningSummaries
Important: APIs under the /beta version in Microsoft Graph are in preview and are subject to change. Use of these APIs in production applications is not supported.

Note: Using the Microsoft Graph APIs to configure Intune controls and policies still requires that the Intune service is correctly licensed by the customer.
https://developer.microsoft.com/en-us/graph/docs/api-reference/beta/api/intune_wip_windowsinformationprotectionapplearningsummary_list 
https://social.technet.microsoft.com/wiki/contents/articles/33525.an-introduction-to-microsoft-graph-api.aspx 

Using the Microsoft Graph API to access data in Microsoft Intune
https://blogs.technet.microsoft.com/intunesupport/2016/10/04/using-the-microsoft-graph-api-to-access-data-in-microsoft-intune 

How to use Microsoft Graph and Office 365 API in a Service or in a Windows App/UWP without a graphical interface
https://blogs.msdn.microsoft.com/laurelle/2016/02/12/how-to-use-microsoft-graph-and-office-365-api-in-a-service-or-in-a-windows-appuwp-without-a-graphical-interface 


# Find a specific word(s) in the Doc file, for example Graph or under or licensed using the .Net Regualr Expression namespace
[regex]::Matches(($doc.Range().text),'Graph|under|licensed').value

Graph
under
Graph
Graph
licensed
Graph
Graph

$wd.quit()

Você não precisará de todos os itens acima para resolver o caso de uso, pois ele pode ser simplificado. No entanto, você vê, isso pode ser feito.

Existem outros exemplos diretamente neste fórum.

Getting specific data out of a word document https://www.reddit.com/r/PowerShell/comments/38dcm7/getting_specific_data_out_of_a_word_document

Você pode até converter o documento para outro tipo de arquivo e depois lê-lo com os cmdlets, mas isso é apenas um trabalho extra. Por que isso se você não precisa.

    
por 13.03.2018 / 08:24

Tags