Tag Info

New answers tagged

2

If you don't need to use $allusers as a collection of user objects multiple times (or if all you need is the names of users,) you can cut down on what you're storing in the shell's memory by doing this: $usernames = (get-aduser -Filter {Enabled -eq $true}).samAccountName $usernames.Contains("check_value") Or say you had an entire array of check values you ...


1

Counting through the array with ($i=0; $i ..., could be so much neater - PowerShell iterates through things quite nicely with foreach, but often you don't need that either. Your final code: $allusers= get-aduser -Filter {Enabled -eq $true} $usernames = @() for ($i=0; $i -le $allusers.length; $i++) { $usernames += $allusers[$i].SamAccountName } ...


3

You can use "select -expand xxx" to produced a flattened(?) array where you don't need to use the property name for parsing the array. $allusers = get-aduser -Filter {Enabled -eq $true} | select -expand samAccountName PS C:\> $allusers.contains("GeoSword") True


7

The problem comes with your Format-Table :) $allusers= get-aduser -Filter {Enabled -eq $true} | FT samAccountName $allusers | gm TypeName : Microsoft.PowerShell.Commands.Internal.Format.FormatStartData Name MemberType Definition ---- ---------- ---------- Equals ...


2

I know the answer comes late it would have already been figured out, If not it might be useful for future visitors. STDIN has to be re-directed in powershell execution inorder to be able to come from hang (Here it waits in STDIN). to be able to do this use -inputformat none powershell -inputformat none -File powershell_script.ps1 will work. Check - ...


2

According to New in Windows Server Update Services 3.0, Microsoft extended the API to allow for 'creating approvals for “optional installation”' These API extensions for "advanced options" aren't exposed through the GUI so that is why you only see this optional option through PowerShell: "New APIs have been created for use by advanced management tools ...


3

There is currently no built-in way to do this in DSC. I wrote a custom resource for my organization that installs a certificate from a PFX. I can't post that code at this time unfortunately, but I used the Cert: PSDrive, Import-PfxCertificate cmdlet and secured credentials in DSC (for the PFX password).


0

I was having a similar issue using Windows XP and Windows 8 from within a VMware Fusion virtual machine: PS C:> $profile \\vmware-host\Shared Folders\<user>\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1 Once I stopped 'Desktop' mirroring (I kept the shared folders), the problem was resolved: PS C:> $profile C:\Documents and ...


1

We figured out that it was a replication issue across our two Domain Controllers and that our firewall was blocking DFSRS (Distributed File System Replication Service). That caused all sorts of subtle things to break in our environment.


1

How about using group policy to deploy the certificate to the domain? http://technet.microsoft.com/en-us/library/cc770315%28v=ws.10%29.aspx To deploy a certificate by using Group Policy Open Group Policy Management Console. Find an existing or create a new GPO to contain the certificate settings. Ensure that the GPO is associated with the domain, site, or ...


0

Yes, you have 2 options: You can install SSHd server on windows and in configuration set up path to the PowerShell. For this you can use tutorial for installation of SSHd and configuration PowerShell path. In short: Install freeSSHd Add new user account and allow SSH access Enable SSH port in Windows Firewall Configure path to PowerShell.exe ...


5

Some options: Install an SSH server on a Windows machine, SSH in, run Powershell on the Windows box Run an RDP client on Linux, RDP in, run Powershell on the Windows box Use Powershell Web Access, hit the POSH WA gateway server with a browser, run Powershell via the browser http://technet.microsoft.com/en-us/library/hh831611.aspx I'm not aware of any ...


1

How about loading up a blank VM, start Process Monitor, and then installing the role or feature. Once the feature is installed you can review the process monitor log to see what changed.


1

$outfile = 'Groups.csv' $groups = Get-ADGroup -Filter * -SearchBase "OU=customOU,DC=panic,DC=org" foreach ($group in $groups) { Get-ADGroupMember -Identity $group | Select name, objectClass, @{Expression={$group.Name}; Label='Group'} | Export-CSV -Path $outfile -NoTypeInformation ` -Encoding ...


0

I got where I could live migrate a VM from one hyper-v 2012R2 server to another, but could not migrate it back. (I'm trying to use SAMBA 4.2 as my domain controller and wanted to see if I could live migrate with CredSSP as I couldn't use constrained delegation with Samba4). Ultimately I went to the working hyper-v and copied the registry entries at ...


0

There's nothing I'm aware of, out of the box, that will do this. You could write a script to dump all of the things you care about, and then paste those into your new window. get-childitem -path env: will show all your environment variables. Get-Variable will show your powershell variables. Get-ChildItem -path function: will show all functions. If ...


1

I have taken jscott's answer an expanded it to output the files that are present in one but not the other for those who are insterest in that type of functionality. Please note it also shows progress made since it was hard for me to see that given the huge folders with not very many differences. It looked like the script was hung to me. Here is the ...


3

Are you using Powershell or Exchange console? Even if you import the exchange tools into Powershell, the add mailbox feature won't work (I never got it to work). For 'add mailbox' you must use the exchange console only.


0

This is almost certainly a two-hop issue. If I use Enter-PSSession to connect to ServerA, and then run Get-Service spooler -ComputerName ServerB, I get the exact same "cannot find any service with service name" error. However, if I run Enter-PSSession ServerA -Authentication CredSSP -Credential (Get-Credential), then the Get-Service command runs fine. The ...


4

There is absolutely no relationship between these objects "out of the box". Windows 8 / Windows Server 2012 introduced a concept of a "primary computer" Active Directory schema attribute but I highly doubt you're going to find that being used. Getting the logged-on user on a remote machine is one of those things that sounds like it should be really easy ...


0

Do you get the same result with get-adobject (instead of get-aduser)? Or try using the .NET Directory Searcher object $rootDSE = [adsi]"LDAP://RootDSE" $dnDomain = $rootDSE.defaultNamingContext $search = New-Object DirectoryServices.DirectorySearcher([ADSI]"") $search.searchroot = [adsi]"LDAP://$dnDomain" $search.Filter = ...


3

Existing profiles on a Windows computer are listed in the following registry key: HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList It contains a subkey per user profile, and the name of each subkey identifies the corresponding user by a Security Identifier. You could "discover" user profiles by enumerating the subkeys and ...


0

I seem to have gotten it to work. I think some variable properties were sticking in memory and it was causing the query to supply the wrong timeframes. here's the finished product for anyone interested, query has been tightened up to only pull 2 sec worth of logs to parse, and only looking back the last 10 min. There's also an segment for writing the ...


1

-command is not a valid parameter for Invoke-Command. Use -FilePath instead to trigger your second script. Also, ensure you have the proper credentials to execute these scripts.


0

The script looks very simple, so i feel like your problem lays elsewhere. maybe try invoke-command -computername $srv {Add-PSSnapin Microsoft.Exchange.Management.PowerShell.E2010; Get-MessageTrackingLog} If that fails maybe walk towards another solution, with psExec fx. This is just a quick copy/paste from my personal scripts. $ps = new-object ...


1

Get-Mailbox will return whatever mailbox instance that the target identity is currently linked to. Once you submit a move request, two instances of the mailbox exist, but the account that owns the mailbox will still be linked to the original. Once the move has been completed, Exchange will re-link the user identity to the new instance of the mailbox, and ...


0

For me only works doing this: extract to another folder; unblock all files; copy the dnsshell folder to modules folder; import the module;


0

First, run the powershell command "Get-ExecutionPolicy -List" (as mentioned in the error message). This will give you a list of the different execution policy scopes and which setting is defined in which scope. This list of scopes has an order of precedence (MachinePolicy, UserPolicy, Process, CurrentUser, LocalMachine). Each of these scopes can have a ...


1

This isn't too tough, it's Powershell 101 really. If you're going to be doing a bunch of Exchange work, you'll definitely need to learn PS front to back. $conns = Get-ReceiveConnector foreach ($conn in $conns) {$conn.name } If you need to limit it to only a specific server, do this $conns = Get-ReceiveConnector -server MyServerName foreach ($conn in ...


4

As indicated in the comments, you'll need to query the transport servers for the so-called "Message Tracking logs" The example below will retrieve any "RECEIVE" event performed by the STOREDRIVER, that is, every time a message was actually delivered to the mailbox (Get-TransportServer | Get-MessageTrackingLog -Recipients "london.sales-inbound@company.com" ...


0

You should use Powershell profile. In the profile you can have all of those functions, variables etc. Basically every time you open a powershell window, you can load your custom powershell profile which in turn will also load your settings as defined. Please see this link: Powershell profile.


1

When you say you can't use AD, do you mean that you don't want to manage printers through Group Policy Preferences, or that you can't use Group Policy at all for this task? I ask because the easiest and probably most maintainable way to run a script when users log off is to add the script as a Logoff Script using Group Policy. This TechNet article describes ...


4

You can either set up a scheduled task that is triggered by Event 4634 ("logon session destroyed") in the Security Event Log, or you can assign a logoff script through the Local Group Policy Editor: Logoff script details are saved in a key in the users registry hive: ...


0

If you have a Csv file with a "Hostname" column, like below, you can use Import-Csv. Example servers.csv file: Id,Hostname,"ServerRole" 123,Server1,"Web Server" 124,Server2,"Web Server" 131,Server3,"App Server" 132,Server4,"App Server" Script using foreach and Import-Csv to accomplish what you are trying to do: # Clear the screen Clear-Host # Import ...


1

Was looking for the same. This works on the PowerShell version that comes with Windows 10 TP register-packagesource -Name chocolatey -Provider PSModule -Trusted -Location http://chocolatey.org/api/v2/ -Verbose


0

Although not recommended by some, if you would like to disable pagefiles completely, be sure to disable Automatic page management as well: # Disable automatic pagefile management $cs = gwmi Win32_ComputerSystem if ($cs.AutomaticManagedPagefile) { $cs.AutomaticManagedPagefile = $False $cs.Put() } # Disable a *single* pagefile if any $pg = gwmi ...


1

This is a serialization problem. New-WebSite and top-level WebSite information from the IIS:\Sites\{sitename} protocol both return objects of type Microsoft.IIs.PowerShell.Framework.Configuration. That object contains a property ftpServer; and ftpServer isn't serializable. New-WebApplication and Sub-WebApplication information from the ...


0

You may try: schtasks /query /FO CSV | ConvertFrom-CSV | Where { $_.TaskName -eq "myTask" } The trick is in converting output to CSV first, and then back to a powershell object.


0

My temporary "solution" is to use a short timeout on the initial calls and immediately retry if they fail. The timeout is short enough that on this server it fails and then retries again fast enough to start communicating successfully (just like when I ran it manually, cancelled it, then ran again). So far it looks like having one timeout and retry is good ...


1

The * actually works as a wildcard with IP-Addesses. E.g> winrm set winrm/config/client @{TrustedHosts="10.1.0.*"}


0

This does not seem to be a general pipeline bug, but rather a quirk with the AD Cmdlets and the way the Properties loaded from Active Directory is populated. If you pipe the entire Computer object as Objects (cast using [Object[]] in your param block) instead, and inspect the Properties of the object with $_.psobject.Properties, you should see that ...


1

I'm going to assume that when you say you want "easier to read" output, you mean want easier to read output on the console, and not in that CSV file. Because CSV files are not meant to be pretty or easy for humans to read - CSV files are meant to be easy for computers to process. So to that end, I've just ignored the Export-CSV cmdlet at the end. In my ...


7

Extend your Get-ADUser line: $getmembership = Get-ADUser $User -Properties MemberOf | Select -ExpandProperty memberof | Get-ADGroup -Properties name | Where { $_.GroupCategory -eq 'Security' } | Select -ExpandProperty Name This will feed the DN of the Group to Get-ADGroup to retrieve additional properties, then filter on group category and select the name ...


1

Working on Windows Server 2012 R2 Core, this worked for me: Set-NetFirewallRule -DisplayGroup "File And Printer Sharing" -Enabled True Here is how to check if it was succesful Get-NetFirewallRule -DisplayGroup "File And Printer Sharing" And find the value in "Enabled", it should be set to TRUE. More info and arguments can be found here: ...


0

I see you already have an answer to this. But you might look at the question a little differently if you wanted to use the DefragAnalysis. $driveLetter = Get-WmiObject -Class Win32_Volume -Filter "DriveLetter = 'C:'" $driveDefrag = $driveLetter.DefragAnalysis() $driveDefrag.DefragAnalysis $report.DefragRecommended will display if the OS thinks it needs a ...


3

Run a query for Event ID 258 in the Application event log PS F:\ps1> get-winevent -filterHashTable @{Logname = 'Application'; ID = '258';} | select-object -first 1 -prop machinename,timecreated,message | fl MachineName : coyote.acme.com TimeCreated : 9/24/2014 2:28:07 AM Message : The disk defragmenter successfully completed defragmentation on (C:) ...


0

We don't have an authenticating proxy but I had a similar problem with update-help. It seems our gateway may be set up not to allow requests from powershell, but does allow requests from IE. In our case running fiddler allowed the request from powershell to get through the gateway\proxy. Not sure how, maybe fiddler changes the user-agent string or something, ...


1

This is a known issue with objects returned from the AD cmdlets. If you request a property from them that they do not have, they will automatically create it as $null. It's annoying, non-standard behavior that confused me too when first piping objects into my own PowerShell functions. So PowerShell tries to bind the ComputerName property first, and gets ...


0

Thank you so much for the code. It has been a great help. I added the following to send an email with the deletion results: $style = "<style>BODY{font-family: Arial; font-size: 10pt;}" $style = $style + "TABLE{border: 1px solid black; border-collapse: collapse;}" $style = $style + "TH{border: 1px solid black; background: #dddddd; padding: 5px; }" ...



Top 50 recent answers are included