# Tag Info

8

Here's how I'd do it. Get-ADUser -Filter * -Properties Enabled, AccountExpirationDate, LastLogonDate | ? {  ($_.Enabled -EQ$False) -OR  ($_.AccountExpirationDate -NE$NULL -AND $_.AccountExpirationDate -LT (Get-Date)) -OR  ($_.LastLogonDate -NE $NULL -AND$_.LastLogonDate -LT (Get-Date).AddDays(-90)) } One call to AD, gets only the properties that we ...

8

It doesn't look like two-factor authentication is supported by PowerShell for O365. http://community.office365.com/en-us/f/148/t/222763.aspx "If an administrator account was enabled Multi-factor Authentication, PowerShell will not work when he connects to PowerShell with this administrator account. Ensure you create a service account with a strong password ...

6

If these systems are members of an Active Directory domain you can use group policy to add a group of admin users to the Local Administrators group. If these systems are members of a domain but the users are local, you can use Restricted Groups to produce the desired effect. If these computers are not members of an AD domain you can use PowerShell to ...

4

I think the problem might be with the way you're generating the credential using ConvertTo-SecureString. By default, that cmdlet uses an encryption key specific to the current host (I think) unless you provide an explicit encryption key with the -Key parameter. On the remote side, it needs to decrypt the string using the same encryption key which it ...

3

I've been asked something vaguely similar, and have Get-MessageTrackingLog -Sender user@example.com -EventID "send" -start '3/1/15' -end '3/5/15' -resultsize unlimited | select-object sender | Group-Object pattern | select count The receive would be: Get-MessageTrackingLog -Recipients user@example.com -EventID "receive" -start '3/1/15' -end '3/5/15' ...

3

Presumably you're trying to format them this way so that they all show up nicely aligned. The only problem is that 020 isn't the same as 20. Not according to this anyway. Windows for Workgroups with TCP/IP-32 and Windows NT utilities can accept Internet Protocol (IP) addresses comprised of decimal, octal, or hexadecimal numbers. This can cause confusion ...

3

No - "Parallel" does not support a throttle limit I think you are confusing two distinct functionalities in PowerShell Workflows: Parallel (which is a Workflow Foundation keyword) -Parallel (a Workflow-specific parameter to the foreach loop) The Parallel keyword means: "Each of the following statements/sequences can be executed in parallel". So a ...

3

You should never configure your VM to Static Ip addresses inside the operating system, use azure portal or powershell instead. Configure a Static Internal IP Address for a VM: https://msdn.microsoft.com/en-us/library/azure/dn630228.aspx Basically you are telling the DHCP server to always give the same ip to your VM. If you don't want to use powershell, ...

3

If your txt file is just a space-separated list of [computername] [ip-address], you can use the Import-Csv cmdlet: $Computers = Import-Csv -Path C:\file.txt -Delimiter " " -Header Name,IP foreach($Computer in $Computers){ # Query$Computer.Name # Assign $Computer.IP as the static address } 2 Mathias' answer is perfectly suited for the question as asked. A much better, more maintainable way to accomplish the goal, however, is to use a DHCP server with reservations. 2 You seem to have two different issues preventing you from doing what you want here - ExecutionPolicy and SysWOW64 File System Redirection. Bypass Execution Policy To bypass the execution policy, do so when launching PowerShell, like so: PowerShell.exe -ExecutionPolicy Bypass -File .\scriptname.ps1 Bypass File System Redirection Since freeSSHd seems ... 2 If the end result is to replace "David" with "Gerald" as the owner, avoid the Add/Replace syntax altogether: Set-DistributionGroup Sales -ManagedBy "Gerald" If you must do these two operations atomically (if you have cases where you might not want to replace existing values), split it into two distinct operations: Set-DistributionGroup Sales -ManagedBy ... 2 From https://support.microsoft.com/en-us/kb/2019527 : The purpose of configuring WinRM for HTTPS is to encrypt the data being sent across the wire. WinRM HTTPS requires a local computer "Server Authentication" certificate with a CN matching the hostname, that is not expired, revoked, or self-signed to be installed. So you need to install a ... 2 That thread Tim linked has good info, here is a native way: (Get-Acl -Path "AD:\CN=John Doe,OU=Users,DC=contoso,DC=com" |  select -ExpandProperty Access) | ` select ActiveDirectoryRights,IdentityReference With that, you should be able to get that into an Object and compare the user you're working as with -contains. Here are a couple blogs from Microsoft ... 2 Easiest, native solution according to me. using powershell: Invoke-WebRequest http://your.url/path Save as test.ps1 and just invoke it. Then schedule it using task scheduler. 2 From Preview Portal: Browse -> Virtual Machines -> Select VM -> All Settings -> Extensions -> Add -> Select Extension -> Create. Using Powershell: https://msdn.microsoft.com/en-us/library/azure/dn606311.aspx Each extension has different pre-requisites so it's not only a matter of installing the extension using powershell commands. Check the above list ... 2 Install the Windows Update PowerShell Module, then run Get-WUList, it will take a while but will show you the required updates with their size. You can then use Get-WUInstall to download and install them. 2 Get-Process won't get you anywhere. Assign the Count to a variable and test if the value of that variable is then 13:$cabFileCount = (Get-ChildItem -Filter "*.cab" "C:\path\to\folder").Count Write-Host $cabFileCount if($cabFileCount -eq 13){ # Success! Write-Host "$cabFileCount files found, perfect!" } else { # Failure! Write-Host ... 2 You can easily copy the contents of a file over-the-wire through a PSRemoting session using Invoke-Command and Set-Content:$Session = New-PSSession -ComputerName "remotehost.domain.tld" -Credential (Get-Credential) -UseSsl $FileContents = Get-Content -Path 'C:\path\to\arbitrary.file' Invoke-Command -Session$Session -ScriptBlock { ...

2

You need to make the drive mapping available to the user you're running Powershell as. You can do the following to give that user the same drive mapping: net use Z: "\\vmware-host\Shared Folders" See the following SO question: Cannot access network drive in PowerShell running as administrator

2

Are you starting this PowerShell console as Administrator or as your current user? If you are running it from a non-elevated command prompt, then it should see all your locally mapped network drives. I'm in the same situation as you right now and have x: mapped to \\vmware-host\[folder], and a Get-PSDrive -PSProvider FileSystem shows me all my locally ...

2

It looks like Get-TSSession cmdlet tries to read some registry (or pipe?) data and fails. Looking at the PSTerminalServices source code I see that it uses Cassia and this could be a permissions issue. This question may be relevant: Calling WTSEnumerateSessions from a Local System Try to set on the remote server 'Full Control' permissions for the ...

1

Looks like you have the issue when you run get-wmiObject, after that call just write -ErrorAction "Resume" Looks like the $OS is actually the null-value so you might want to do something like this that will know if$s is null and make a decision of what to do: if ($OS -ne$null){ $uptime = (get-date) -$os.converttodatetime } else { ...

1

You don't have to be the global admin for an entire SharePoint Online deployment to upload files to a single library, so no, it can certainly be done

1

Find something else to delete first, like IIS logs.

1

To actually return an object of type Microsoft.ActiveDirectory.Management.ADOrganizationalUnit of a User Object, use this: Get-ADOrganizationalUnit -Identity $(($adUser = Get-ADUser -Identity $env:USERNAME).DistinguishedName.SubString($adUser.DistinguishedName.IndexOf("OU="))) The same can be accomplished for a computer: Get-ADOrganizationalUnit ...

1

In Powershell 4.0 you can use requires at the top of your script: #Requires -RunAsAdministrator Outputs: The script 'MyScript.ps1' cannot be run because it contains a "#requires" statement for running as Administrator. The current Windows PowerShell session is not running as Administrator. Start Windows PowerShell by using the Run as ...

1

unfortunately search-mailbox cmdlet is no longer available. not sure why they removed it. There is no option to recover ONLY recoverable items..

1

I know this is an old post but I'd like to point out that the ForEach-Object cmdlet doesn't suffer the same issue as using the ForEach key word. So you can pipe the results of DIR to ForEach and just reference the file using $_, like:$backups | ForEach{ Remove-Item \$_ } You can actually forward the Dir command itself through the pipe and avoid even ...

1

I know this is an old thread, but I had the same issue and took me close to a full day to figure this out. According to this reddit article, you have to update your firewall rules corresponding to "Windows Remote Management" to allow the connection (even if it is NOT SECURE)! As far as I can tell, that's the only way to make WinRM work in Server Manager ...

Only top voted, non community-wiki answers of a minimum length are eligible