I'm trying to automate the process of right clicking a folder or file and then clicking the "Always available offline" in windows 7+.
I've not been able to find any command or batch way to do that. So far, I found this powershell script that simulate a right click operation on a context menu item (Always available offline in my case).
$o = New-Object -ComObject Shell.Application
$o.Namespace("Z:\").Self.verbs() | `
Where-Object { $_.Name -eq 'Always &available offline' } | `
ForEach-Object { $_.DoIt() }
It doesn't work.
If I try to pass a folder or UNC path instead of a drive (let's say Z:\foldertomakeavailableoffline), all I get is "You cannot call a method on a null-valued expression." as if the folder I specify doesn't exist.
Any help is appreciated.
Thanks.
It would be rather helpful if you would post your $o.Namespace("Z:\").Self.verbs() result like this:
Mine are:
Name
----
&Open
Git &Add all files now
Git &Commit Tool
Git &History
Git &Gui
Git Ba&sh
Scan for Viruses...
Hg &Workbench
Restore previous &versions
Combine files in Acrobat...
Select &Left Folder for Compare
&Disconnect
&Copy
Create &shortcut
Rena&me
P&roperties
In my eyes the issue here is that you don't see it and that is why id does not work. (It is also atypical menu item as the value are true/false).
I would try to do it the following "pinning" way:
If you need to pin a folder/file for a user try this:
$path = “\\path_to\shared\folder”
$objWMI = [wmiclass]”\\.\root\cimv2:win32_offlinefilescache”
$objWMI.Pin($path, 0x00001221, $true)
Which uses these bits:
0x00001221
OfflineFilesPinControlFlagFill (0x00000001)
Fills the item in addition to pinning it. This results in the item being fully cached as part of the pin operation. If this flag is not
set, the item is only pinned and must wait to be filled by some other
means of synchronization. Note that the Offline Files service
periodically fills files in the background. If immediate offline
availability is not necessary, it may be better (performance-wise) to
not set this flag and let the service fill the file in the background.
OfflineFilesPinControlFlagForUser (0x00000020)
Pins the items for the calling user. This is the flag typically set for a caller of this function. It is important to note that
Offline Files does not support a true per-user notion of pinning. When
an item is pinned for a user, it is pinned for all users of that
machine. An item that is pinned with this flag can be unpinned by any
user who has access to that file. The ability to access that pinned
file depends on the user's access rights to that file computed while
online.
OfflineFilesPinControlFlagLowPriority (0x00000200)
Reserved for future use.
(I like to use this one for it is LowPriority not to clog the system)
OfflineFilesPinControlFlagConsole (0x00001000)
This flag is ignored if the OfflineFilesPinControlFlagInteractive flag is not set. If the OfflineFilesPinControlFlagInteractive flag is
set, this flag indicates that any UI produced should be directed to
the console window associated with the process invoking the operation.
Related
Edited for clarification: The goal is outlined in what I would like to accomplish. Now I don't know if I am headed in the right direction with this. So in a nut shell,
Am I going about this correctly? (example Is this single script possible or do I need multiple scripts? Is there a better process to doing this in powershell?)
How do I achieve my goal with what I have here? It only does part of what I am looking for. The part to list the computers an update should go out to and the status of the update on said computer I am struggling with.
I am not expecting people to write this but help me figure it out. I can't imagine I am the first one to fit these needs, but just haven't found a similar script for assistance.
Backstory:
For the last few weeks I have been teaching myself Powershell to accomplish a wsus reporting goal. I have searched everywhere trying to find a script that I could modify to fit my needs but I feel my limited skills is making that difficult.
Goal: Pre-approval
I am trying to generate a list of updates that are needing to be approved. (This works) But for each update I want to list out the servers who should be getting this update along with the update status. Example: Update KB12345 is needed by server1/server2/server3 and install status equals X. I am just confused as to the best way to handle this. I am ok with exporting to different file formats. TXT for the first part that lists "How many updates need to be approved" and excel for the computer status part. I started playing with computerscope but I was not able to filter it so I can get workstations vs servers. It lists everything all together.
Goal: Verify Installed status
I would like to run a second check against this during/after our maint window so we can confirm everything installed correctly and that report is logged in our change request for audit needs.
Things I have tried:
Checking each computer to see if the update was installed using a different script took way to long and was dependent on the workstation being available. Servers not so much a big deal as they are always up. Servers we can compare against locally if wsus doesn't get updated in time, but I would need to be able to run this so that I can report on the workstations for this month. (I only care about the updates being applied per month. Not outstanding or previous updates.)
I thought about splitting up this into two scripts. One that did the approval list and one that is run after comparing against a list of KB#s in a text file.
I feel this is a bit overkill but in how our SOX auditing this year has been any hiccup or concern was crazy scrutinized.
#Note the "Cleanup" in my script is a local function to ISEprofile that clears everything on each run. This is removed when it is put into production.
Cleanup
[void][reflection.assembly]::LoadWithPartialName(“Microsoft.UpdateServices.Administration”)
#Connect to the WSUS Server and create the wsus object
$wsus = [Microsoft.UpdateServices.Administration.AdminProxy]::getUpdateServer(‘wsus’,$False,"8530")
#Variables
#Wsus Variables
$Arrivaldate = ”01/12/2021"
#ApprovedStatus could be the following:Any, declined, hasstaleupdateapprovals, latestrevisionapproved, notapproved
$ApprovedStatus = "notapproved"
$InstallationStatus = "NotInstalled"
#Logging Variables
$Logpath = "D:\scripts\ps1\Testing\Logs\Monthlyupdatelist.txt"
#Create a computer scope object
$computerscope = New-Object Microsoft.UpdateServices.Administration.ComputerTargetScope
#Create UpdateScope
$updatescope = New-Object Microsoft.UpdateServices.Administration.UpdateScope
#Find all clients using the computer target scope
#$wsus.GetComputerTargets($computerscope)
#$Wsus.GetComputerStatus($computerscope,[ Microsoft.UpdateServices.Administration.UpdateSources]::All)
#Find updates based on scope below. Run $updatescope alone to see all the items you can filter by.
$updatescope.ApprovedStates = [Microsoft.UpdateServices.Administration.ApprovedStates]::$ApprovedStatus
$updatescope.IncludedInstallationStates = [Microsoft.UpdateServices.Administration.UpdateInstallationStates]::$InstallationStatus
$updatescope.FromArrivalDate = [datetime]$Arrivaldate
Start-Transcript -Path $Logpath
#This lists how many updates are set in "all updates"
Write-Host "Number of Updates this month to approve:"$wsus.GetUpdateCount($updatescope)
$wsus.GetUpdateStatus($updatescope,$False)
#List out the updates for the month
$Updatelist = $wsus.GetUpdates($updatescope)
$Updatelist | Select Title, UpdateClassificationTitle, KnowledgebaseArticles, ProductTitles, ArrivalDate, IsApproved, IsDeclined
Stop-Transcript
In the context of a project, I have to succeed, with a code in PowerShell, to activate the "Print background colors and images" parameter for all users.
For the moment, I can activate it for the current user with the following command:
Set-ItemProperty -Path 'HCKU:\Software\Microsoft\Internet Explorer\PageSetup\' _Name 'Print_Background' -Value YES _Force
Unfortunately, and logically, this only affects the current user and not all other users as desired.
I'm still not very comfortable with registry keys. I understand that I have to use a HKEY_LOCAL_MACHINE. But I haven't figured out how to access this parameter using such a key. I tried to replace 'HKCU' by 'HKLM', as recommended by some people, but it returns me an error.
If you want to enable the option Print background colors and images in the page setup of the IE browser for all users then you need to create registry on location below.
HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Internet
Explorer\Main
Name: Print_Background
Value: yes
You can try to modify your script and try to check whether it works for you or not.
I use Powershell to pull in data about user accounts, some of which includes details about an user's home folder.
I have been using get-item on folders to get the ACL to make sure an user has proper access to their home folder.
An example of my code is:
((get-item C:\exampleFolder).GetAccessControl('access')).Access
This provided me the list I needed and works great. However, if an user's username changes, it can take some time (like 5- 10 minutes) before Powershell can see the change even though viewing the folder's properties reflects the changes nearly instantaneously.
I am just seeing if there is a better way to pull the ACL data so that what I see in folder property page is what Powershell gets.
first world issue for me really, just trying to make my code a little bit more efficient.
Edit: This is a change in a username on a domain though Active Directory, not a username on a local machine.
There is the Get-ACL Cmdlet. This will output an object with an Access property listing all users with Access and their Access Level.
If you want to, you could use this to make a function to get more explicit data like this:
function Get-Permissions ($folder) {
(get-acl $folder).access | select `
#{Label="Identity";Expression={$_.IdentityReference}}, `
#{Label="Right";Expression={$_.FileSystemRights}}, `
#{Label="Access";Expression={$_.AccessControlType}}, `
#{Label="Inherited";Expression={$_.IsInherited}}, `
#{Label="Inheritance Flags";Expression={$_.InheritanceFlags}}, `
#{Label="Propagation Flags";Expression={$_.PropagationFlags}}
}
This you could easily pipe on to a | Format-Table -Auto or however you wish to visually consume your output.
I am in the process of writing a PowerShell script for backing up a Windows computer using rsync. To this end, I am attempting to use WMI from said script to create a non-persistent Shadow copy with writer participation (as is apparently recommended for backups).
I found out from another question (Accessing Volume Shadow Copy (VSS) Snapshots from powershell) a way to create a shadow copy in general, but the example given there uses "ClientAccessible" as the context parameter, which results in the creation of a persistent Shadow Copy, without writer participation.
While searching for a solution, I have found that I could use the following command to obtain a list of contexts, which I assume are understood by WMI:
Get-WmiObject win32_shadowcontext | Out-GridView
It does the list have a context named "Backup", which is conveniently what I want. I proceeded to attempt creating a non-persistent shadow copy using that context:
$shadow = (Get-WmiObject -list win32_shadowcopy).Create("C:\", "Backup")
However, this seems to fail and the content of the $shadow variable is set to
ReturnValue : 5
ShadowID : {00000000-0000-0000-0000-000000000000}
According to the relevant documentation (Create method of the Win32_ShadowCopy class), the return value means "Unsupported shadow copy context."
I couldn't find any relevant documentation as to why this context is unsupported or whether it is possible to use it at all. I have also tried the "FileShareBackup" and "AppRollback" contexts without success.
I assume I am either missing something obvious, or that for some reason, WMI really doesn't support anything else than "clientAccessible" when creating shadow copies, or that this is OS-dependent (I am testing this on Windows 7, 64-bit)
How can I get this to work?
Okay, Technoob1984 here with the scoop. See my attached screen shot.
This one is tricky, because you have to use x64 version of Powershell (located under system32 not wow64)
The Shadow Copy Context are the .properties of the object.
Also I used the static method in my screenshots below.
https://learn.microsoft.com/en-us/previous-versions/windows/desktop/vsswmi/create-method-in-class-win32-shadowcopy
# get existing shadow copies
$shadow = get-wmiobject win32_shadowcopy
"There are {0} shadow copies on this sytem" -f $shadow.count
""
# get static method
$class=[WMICLASS]"root\cimv2:win32_shadowcopy"
# create a new shadow copy
"Creating a new shadow copy"
$class.create("C:\", "ClientAccessible")
# Count again
$shadow = get-wmiobject win32_shadowcopy
so in the example there, you would want to use $class.Properties to see what you can use as a Shadow Context.
See my screen shot:
So Shadow Context is 'Caption, Count, Description' and anything else under the 'Name:' value of .Properties. I do not see 'Backup' as one of the options.
Enjoy
Your $shadow has a 5 on return value looking at the error message, your shadow id has all zeros , you would need to add a 1 or a 2 to the end of the volume shadow copy in the registry using binary or dword.
find the folder in the registry named volsnap in your regedit search .volsnap.sys is found in the C:\Windows\System32\drivers directory. The file size is 52,352 bytes.The volsnap file contains Microsoft's digital signature make sure its the correct bytes.
This confirms its authenticity. volsnap.sys appears to be a file that was compressed by an EXE-Packer. This technique is often used by trojans to keep the file size small and also hamper debugging efforts.
However, this in itself is not sufficient reason to presume malicious intent, since even well-intentioned, professional software producers take advantage of compressed files. For this reason, 2% of all experts consider this file to be a possible threat. The probability that it can cause harm is high. Please consider the additional Comments from other users.
shadow id default
00000000-0000-0000-0000-000000000000
00000000-0000-0000-0000-000000000005
if it already has a 5 which it probably doesn't change it to 1
or create new code
Shadow id $shadow 00000000-0000-0000-0000-0000000000001
not exactly as shown.you may have to try different wording I'm not sure if $will work, if not, try the js standalone version.
I'd like to create a dynamic view that only shows the files a user created/modified for a particular label.
Right now, I am listing all of the files in the label and comparing that with the previous label.
If I have to use cleartool to find the files, that is fine with me. I'd like the process to be more automated than it currently is.
Another option too is, can I simply see the diffs for a particular user? That way, I am more likely to understand the file's history. If a developer had attempted something one way and found that didn't work, it might be helpful to see that trial and error.
config spec:
#element * REL_2010.2.2.006
element * .../pgh_rel_4.0.0_dot_rel/{created_by(pp50773)&&lbtype(REL_2010.2.2.006)}
# first stop rule
element -directory * .../pgh_rel_4.0.0_dot_rel/{lbtype(REL_2010.2.2.006)}
# second stop rule
element -directory * main/LATEST
This config spec doesn't fetch my changes - It fetches empty directories. It is also important to note that while I made the changes to the actual file, another guy is responsible for applying the label weekly. So, if it goes by whose name is on the label, that won't work.
If I remove the created_by constraint, it works fine listing all of the changes for the label, but I want only files in that label for a given user.
Walter
According to the version selector rules, you can do that, but I would recommend:
2 dynamic views (easy to setup and refresh, since their content is not downloaded on your hard drive, but accessed through the network)
one one for one label
one for the other
to not forget to add stop rules for directories (if directories are not created by your user, they won't be selected, meaning your view won't be able to select any version within it.
The config spec for one of those view would be something like:
element * .../MyBranch/{created_by(myuser)&&lbtype(MY_LABEL)}
# first stop rule
element -directory * .../MyBranch/LATEST
# second stop rule
element -directory * main/LATEST
When you have two views correctly configured, you can compare their content with a tool like WinMerge.