我想弄清楚如何编写一个脚本,该脚本通过一个文件夹并抓取文件夹中的所有 Word 文档以搜索超链接并将链接更改为另一个链接。然后保存该 Word 文档并创建另一个版本,将其转换为 pdf。
如何调整下面的脚本以获取文件夹中的所有 Word 文档,然后搜索“ https://www.yahoo.com ”到“ https://www.google.com ”的所有超链接。一些如何遍历整个文档搜索所有超链接。保存该文档,然后转换并提供新的 pdf。
这可能吗?
到目前为止我所拥有的
$word = New-Object -ComObject word.application
$document = $word.documents.open("path to folder")
$hyperlinks = @($document.Hyperlinks)
$hyperlinks | ForEach {
$newURI = ([uri]$_.address).AbsoluteUri
Write-Verbose ("Updating {0} to {1}" -f $_.Address,$newURI) -Verbose
$_.address = $newURI
}
If (_$.address -eq "https://www.yahoo.com/") {
$_.Address = "https://www.google.com/"
} ElseIf ($_.Address -eq "http://def.com/motorists") {
$_.Address = "http://hij.com/"
}
$document.save()
$word.quit()
Get-ChildItem -Path $document -Include *.doc, *.docx -Recurse |
ForEach-Object {
$doc = …Run Code Online (Sandbox Code Playgroud) 使用 PowerShell,我希望收集已安装的应用程序。这似乎是通过在此处解析注册表的“卸载”部分来最彻底地完成的:
HKLM\Software\Microsoft\Windows\CurrentVersion\Uninstall\
Run Code Online (Sandbox Code Playgroud)
和
HKLM\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\
Run Code Online (Sandbox Code Playgroud)
一个简单的 PowerShell 来解析数据并将其以表格格式抛出,其中之一可能是:
Get-ItemProperty HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\*
| Select-Object DisplayName, DisplayVersion
| Sort-Object DisplayName | Format-Table -AutoSize
Run Code Online (Sandbox Code Playgroud)
我想要做的不是运行上面的行来获取 x86 和 x64 安装的应用程序,而是将它们组合成相同的输出。是否有简单的解决方案可以允许同一行解析两个注册表项并将数据合并到一个表中?
我有一个接受一个或多个子域的脚本,我想验证它们但[ValidatePattern()]似乎只检查数组中的第一项。
编码:
param(
[ValidatePattern('\w*\.domain\.com')][string]$subdomain
)
Run Code Online (Sandbox Code Playgroud)
此输入被接受:
.\script.ps1 -subdomain "test.domain.com", "randomstring"
Run Code Online (Sandbox Code Playgroud)
有没有办法验证数组中的每个条目?
我是 powershell 的新手,并试图从脚本中解码以下行
Get-WmiObject -class MSFC_FCAdapterHBAAttributes -namespace “root\WMI” | ForEach-Object {(($ .NodeWWN) | ForEach-Object {“{0:x}” -f $ })}
该脚本位于:https : //gallery.technet.microsoft.com/scriptcenter/Find-HBA-and-WWPN-53121140
我对“ForEach-Object {“{0:x}” -f $_} 更感兴趣
“{0:x}”是什么意思?
-f 对当前对象 $_ 有什么作用?
当我在 Windows Server 上运行脚本时,我看到 NodeWWN 条目之一: NodeWWN : {32, 0, 0, 16...} 现在转换为: 20:00:00:10:9B:17: 9E:28
如果这里的专家能帮助我指出正在发生的事情,我将不胜感激。
在 PowerShell 中,您可以将多个参数传递给函数或 cmdlet,方法是将它们包装在一个哈希表变量中,然后传递前缀为@而不是 的变量$。
是否可以使用哈希表作为另一个对象的属性(即作为一个衬垫)?例如,下面我首先必须将属性 ( testInt, testString)分配给另一个变量,然后才能将其分配给Demo. 我想要一些方法来避免这个额外的步骤,但一直无法找到一个巧妙的解决方案......
function Demo {
[CmdletBinding()]
Param (
[Parameter()]
[string]$One
,
[Parameter()]
[string]$Two
)
"1 = $One"
"2 = $Two"
}
$test = @{
testInt = @{
One = '1'
Two = '2'
}
testString = @{
One = 'One'
Two = 'Two'
}
}
$t = $test.testInt
Demo @t
$t = $test.testString
Demo @t
Demo @test.testInt #this doesn't work / I've also tried …Run Code Online (Sandbox Code Playgroud) 我正在尝试通过 powershell 生成 AWS API 网关访问密钥。但是,每次我尝试使用任何 cmdlet 时都会引发错误:
例如:
Get-AWSCredential -ListProfileDetail
Run Code Online (Sandbox Code Playgroud)
会导致这样的错误:
Get-AWSCredential :术语“Get-AWSCredential”不被识别为 cmdlet、函数、脚本文件或可运行程序的名称。检查名称的拼写,或者如果包含路径,请验证路径是否正确,然后重试。在行:1 char:1 + Get-AWSCredential -ListProfileDetail + ~~~~~~~~~~~~~~~~~~ + CategoryInfo : ObjectNotFound: (Get-AWSCredential:String) [], CommandNotFoundException +fullyQualifiedErrorId :命令未找到异常
当我通过 Get-Command 显示命令列表时,AWS cmdlet 不会弹出。知道可能是什么问题吗?
qfarm /load命令显示我的服务器的负载。输出:
PS> qfarm /load
Server Name Server Load Load Throttling Load Logon Mode
-------------------- ----------- -------------------- ------------------
SERVER-01 400 0 AllowLogons
SERVER-02 1364 OFF AllowLogons
SERVER-03 1364 OFF AllowLogons
SERVER-04 1000 0 AllowLogons
SERVER-05 700 0 AllowLogons
SERVER-06 1200 0 AllowLogons
Run Code Online (Sandbox Code Playgroud)
我只需要显示第一列(服务器名称)和第二列(服务器负载)并循环遍历它们,以便稍后进行一些逻辑,但 powershell 似乎没有将其视为具有属性的对象:
PS> qfarm /load | Select -ExpandProperty "Server Name"
Select-Object : Property "Server Name" cannot be found.
Run Code Online (Sandbox Code Playgroud)
有没有其他可能,比如一张桌子什么的?
我有一个对象数组:
$people= @()
foreach ($person in $databaseOfGuests)
{
$people += @{ "FirstName"=$person.FirstName; "LastName"=$person.LastName }
}
Run Code Online (Sandbox Code Playgroud)
现在我想从 中删除重复项$people,是否可以在 PowerShell 中执行此操作?就像是:
$people = $people | Select -Uniq
Run Code Online (Sandbox Code Playgroud)
我有两个数组$people1and $people2,我需要获取所有在$people1但不在 the 中的人的数组,$people2反之亦然。就像是:
$peopleInPeople1ButNotInPeople2 = $people1.Substruct($people2)
$peopleInPeople2ButNotInPeople1 = $people2.Substruct($people1)
Run Code Online (Sandbox Code Playgroud)
可以在PS中一行完成吗?
我有一个非常大的审计项目,我希望能够自动化。
我需要获取属于某个组的每个用户的姓名、SamAccountName、Title 和 Department。问题是,该组中有组,而这些组中有组。另一个问题是,大约 99% 的组的显示名称(不是 SamAccountName)中有一个星号。
这是我目前拥有的代码,它工作正常,直到它收到一个名称中带有星号的组..(因此是 .Replace("*","") 部分......任何人都知道如何修复这个?
function Get-NestedGroupMember {
[CmdletBinding()]
param(
[Parameter(Mandatory)]
[string]$Group
)
$broke = @();
## Find all members in the group specified
$members = Get-ADGroupMember -Identity $Group
foreach ($member in $members){
## If any member in that group is another group just call this function again
if ($member.objectClass -eq 'group'){
$memberGroup = $($member.Name).Replace("*", "")
try{
Get-NestedGroupMember -Group "$($memberGroup)"
}catch{
$broke += "$($memberGroup)`n"
}
}else{
## otherwise, just output the non-group object (probably a …Run Code Online (Sandbox Code Playgroud) 我有一个 Azure 对象(虚拟机、数据仓库或分析服务)的集合,我想遍历该集合,但也过滤掉具有特定标签的对象。
例如,获取所有没有名为“Environment”且值为“Production”的标签的Analysis Services 。
如何指定Where-Object过滤器(尝试了几种方法都没有成功)
cls
# Login to Azure
#Login-AzureRmAccount | Out-Null
# Selecting the right subscription
#Select-AzureRmSubscription -SubscriptionName "MySubscription" | Out-Null
# Get all my Analysis Services, but leave out those with the tag Environment=Production
$AnalysisServicesServers = Get-AzureRmAnalysisServicesServer | Where-Object {$_.Tag -notcontains @{Environment="Production";}}
# Loop Through the collection and to something
foreach ($AnalysisServicesServer in $AnalysisServicesServers)
{
$AnalysisServicesServer # Show all properties
Write-Host "1 Name $($AnalysisServicesServer.Name)" # Show Name
Write-Host "2 Tags count [$($AnalysisServicesServer.Tag.Keys.Count)]" # …Run Code Online (Sandbox Code Playgroud)