我创建了一个小脚本来将名为 pssfulllocation 的 Active Directory pc 属性值从一台 pc 传输到另一台 pc。
为了实现这一点,我必须使用类型转换+拆分..
这是有效的脚本
$oldpc=read-host "Enter old pc name"
$newpc=read-host "Enter new pc name"
$my=Get-ADComputer -Identity $oldpc -Properties * | select pssfulllocation
$itemcast=[string]$my
$b = $itemcast.Split("=")[1]
$c=$b.Split("}")[0]
Set-ADComputer -identity $newpc -Replace @{pSSFullLocation="$c"}
Run Code Online (Sandbox Code Playgroud)
并且输出将很好地完成预期的工作..以这种方式..这是期望的结果..
但是,如果我不按照以下脚本使用类型转换 + 拆分--
$oldpc=read-host "Enter old pc name"
$newpc=read-host "Enter new pc name"
$my=Get-ADComputer -Identity $oldpc -Properties * | select pssfulllocation
Set-ADComputer -identity $newpc -Replace @{pSSFullLocation="$my"}
Run Code Online (Sandbox Code Playgroud)
输出在下面..这不是我想要的..
简而言之,如果我不使用类型转换 + 拆分输出将添加为 @{pSSFullLocation=C/BRU/B/0/ADM/1 但它只能添加为 C/BRU/B/0/ADM/1按照这个: …
我们有一个交换混合环境。(有些用户在本地交换中,有些用户在 office 365。)
当我们想从本地导出电子邮件时,我们使用下面的命令来导出邮箱和存档。
New-MailboxExportRequest -Mailbox "user" -FilePath \\mysrv\l$\PST\Mailbox-user.pst; New-MailboxExportRequest -Mailbox "user" -IsArchive -FilePath \\mysrv\l$\PST\Mailbox-user-archive.pst -confirm:$false
Run Code Online (Sandbox Code Playgroud)
New-MailboxExportRequest 适用于本地用户而不适用于 Office 365。有没有办法使用 powershell 将 Office 365 用户邮箱导出到 pst?
到目前为止我尝试过的:
我登录到 Office 365
$UserCredential = Get-Credential
Import-Module MSOnline
Connect-MsolService -Credential $UserCredential
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $UserCredential -Authentication Basic -AllowRedirection
Import-PSSession $Session
Run Code Online (Sandbox Code Playgroud)
并尝试 New-MailboxExportRequest
但它会产生错误。显然,Office 365 不知道该命令
PS C:\Users\pp> New-MailboxExportRequest
New-MailboxExportRequest : The term 'New-MailboxExportRequest' is not recognized as the name of a cmdlet, function,
script …Run Code Online (Sandbox Code Playgroud) powershell export microsoft-office-365 exchange-2013 exchange-hybrid
我正在尝试编写一个powershell脚本来更改comment使用csv和的电脑列表中名为“ ”的 属性import-Csv。
这是我的脚本
$computers=Import-Csv -Path "C:\sds.csv"
foreach ($item in $computers){
Set-ADComputer -identity $computers.DistinguishedName -add @{comment="bara"}
}
Run Code Online (Sandbox Code Playgroud)
并听到我的csv文件位于"C:\sds.csv"
但它跳到这个..
尝试谷歌搜索并在这里和那里更改,但不起作用!我对power-shell脚本了解甚少,但希望学习。有人可以指导我请什么我搞砸了?